Академический Документы
Профессиональный Документы
Культура Документы
0 1 5
2 4 3
2 4
0 1 3
3
4
2
2 4
3
2
2 4
0 1 3
3
4
3 2
2 4
4 3
2 4 6
0 2
1 3
3
4
3 2
4 2 4
3
4 5
2 2
0 1 3
3
4
3 2
4 2 4
3
4 5
2 2
0 1 3
3
4
3 2
4 2 4
3
4 5
2 2
0 1 3
3
4
3 2
4 2 4
3
x1 x2 x3 x4
y1 y2 y3 y4
x1 x2 x3 x4
y1 y2 y3 y4
M-augmenting path P: x4y3x3y2x2y1x1y4,
1y4, x2y1, x3y2, x4y3}
[10 marks + 5 marks +5 marks]
(ii) In the perfect matching algorithm, we normally used the convention of
“always choose vertex with the smallest index first” instead of “choose any
vertex. If we were to instead use “choose any vertex”, would we be getting
a different matching for the above bipartite graph? Why?
If we use “choose’ any vertex” strategy the results will be still the same
result since in the firststpe we have no choice but still to choose x4y3 and
the rest will still be the same for the above grapph. [5+5 marks]
4. (a)
(i) In Boyer-Moore algorithm, if there is a mismatch, then we have to consider
two cases depending on the character of text T at index position m-1 that
is compared against the last character of pattern P. What are the two
cases and how does the above procedure handle the cases?
Case 1: If x does not occur in the first m - 1 positions of P, then
clearly we can shift P by its entire length m.
Case 2: if x does occur in the first m – 1 positions of P, then we shift
P so that the rightmost occurrence of x in P[0:m– 1].
Line 2-4 handles Case 1, by initialising everything to case 1.
Lines 5-7 handles Case 2, if that is the case and overwrite the
previous initialisation. [10+10 marks]
(ii) Based on the above procedure, the Boyer-Moore algorithm needs to
create a shift table. Given that P[0:5] = “serasa”, then complete the
following shift table.
A e r s The rest (Yang lain)
2 4 3 1 6
[10 marks]
(iii) The above procedure certainly contributes to the complexity of the overall
Boyer-Moore algorithm. What is the worst-case complexity of the above
procedure? Show how this complexity contributes to the overall complexity
of Boyer-Moore algorithm and state the overall complexity of the algorithm.
The first loop is a constant (size of the alphabet). The second loop is
O(m) (size of P) so the the complexity = O(m).
The overall complexity is id O(n) x O(m) = O(nm) where n is size of T.
[10 + 10 marks]
(b) Without going into mathematical detail or writing any code, explain how the Fast
Fourier Transform can be used to FFT can be used to design O(n log n)
algorithm for polynomial multiplication and explain also how this strategy yields
O(n log n) complexity.
(c) (i) How is a digraph used in ranking of web pages in the page rank
algorithm? Also, explain how the web pages are organised as a digraph.
The algorithm assigns a measure of “prestige” or ranking to each Web
page, independent of any query, using digraph based on the hyperlink
structure of Web (Web digraph)
Web digraph, W is the digraph whose set V(W) consists of all Web pages (or
large collection of Web pages), and whose edge set E(W) corresponds to
the hyperlinks; i.e. an edge is included from page p to page q whenever
there is a hyperlink reference (href) in page p to page q. [5+10 marks]
(ii) Explain the significance of the in-degree of p (the number of Web pages
that belong to the in-neighbourhood Nin(p) of p) in the page rank
algorithm?
More weight should be given to Web pages in Nin(p) that have a high
rank, and thus the rank of p is the sum of the ranks of all q in the in-
neighbourhood of p. [5 marks]
(iii) In the same algorithm, the number of hyperlinks that q contains or
equivalently by the out-degree dout(q) of q is also used. Explain its
significance in the algorithm.
To avoid so much influence of pages with many hyperlinks, we
divide by by the outdegree dout(q) of q i.e. the no. of hyperlinks that q
contains. [5 marks]