4. [10marks total Suppose you are given a directed graph G with nodes, stored in an xnadjacency matrix W (Le. WL is 1 if ther

4. [10marks total Suppose you are given a directed graph G with nodes, stored in an xnadjacency matrix W (Le. WL is 1 if there is an are that goes from vertex i to vertex , and is 0 otherwise). Note that it is possible to have an are from node i to nodef, and from node jto node i A “start node” in G is a node v such thaat there is an are from v to i to all the other nodes i in G, and no ares directed into v. We wish to know if G has a start node or not, and to find that start node if it exists. Example: The directed graph below has a start node, mamely node 5. 000 W 10000 o0100 IIIID Here is another directed graph below, which has no start node a) [7 marks Design a divide and conquer algorithm for this problem. You must first describe the idea behind your algorithm clearly in English, and then write the pscudocode for your algorithm. You will be marked on the clarity and the eficiency (in terms of complexity class) of your algorithm (Hint Try to design your algorithm such that, at each stage of the recursion, you get to eliminate one node from consideration) b) [3 marks Do a worst case analysis of your algorithm using the input size n, and counting the number of “looks” your algorithm makes to elements in W. In your analysis, find a recurrence relation for your worst case W(n), and solve this recurrence relation using back-substitution. You do NOT need to verify your back substitution guess using inductiona in this case.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *