Вы находитесь на странице: 1из 5

Course During Long Vacation Examination 2016/2017 Academic Session

CCS592 – Advanced Algorithms and Complexity

3. (a) Based on the graph below, justify the following statements.

0 1 5

2 4 3

(i) This is a connected graph.


There is only one connected component /every node is reachable from all
other nodes.
(ii) This is a bipartite graph.
It consists of 2 set of edges i.e. {0,5} and {1,2,3,4} and all edges have one
endpoint in one set and the other endpoint in the other set.
(iii) This is a planar graph.
It can be drawn in a plane without intersecting edges.
(iv) This is not a complete graph.
In this graph, all nodes do not have edges to all the other nodes, only to
some nodes
(v) This graph has one connected component.
every node is reachable from all other nodes.
(5 marks x 5)
(b)
(i) Is this algorithm considered to be a greedy method? Explain by referring
the above psedudo-code.
It is greedy because in line 9, the algorithm greedily select the vertex that
with minimum distance and then hoping that at the end the created is the
shortest. [5 marks]
(ii) What is the role of line 10 in the above pseudocode?
Once node u is selected, it is included in the current tree (shortest path so
far). [5 marks]
(iii) Based on the pseudo-code above, state the complexity of this algorithm
and indicate which part of the pseudocode actually contributes to this
complexity.
2
Worst case complexity =O(n ). Line 8- for loop is executed n time which is
the no. of nodes, and line 11-for loop which is nested in Line8-for loop has
2
to at most process every vertex (n nodes). So, the complexity is nxn = n .
[5+10 marks]
(iv) Trace step by step how the algorithm works on the following graph from
node 0. You are not required to show the content of the arrays involved.

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

[20 marks = 5x4]


(c) (i) Given below is a simple bipartite graph and its initial matching. Give the
next augmented path, its corresponding augmented matching and the final
perfect matching. There is no need to show the alternating tree.

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.

[15 marks + explanation of the complexity, 10 marks]

(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]

Вам также может понравиться