Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assignment #2 (Assignment due: Nov. 06, 2018) v1 v2 v3 v4 v5

Similar presentations


Presentation on theme: "Assignment #2 (Assignment due: Nov. 06, 2018) v1 v2 v3 v4 v5"— Presentation transcript:

1 Assignment #2 (Assignment due: Nov. 06, 2018) v1 v2 v3 v4 v5
1.(30) See the graph G shown in Fig. 1(a), which can be stored in a file on disk as a set of pairs as shown in Fig. 1(b). Design an algorithm to load the file in main memory and store it as a set of linked lists. (The algorithm should be able to be used for any graph.) (v1, v2) (v1, v3) (v1, v4) (v1, v5) (v2, v3) (v2, v4) (v2, v5) (v3, v4) (v3, v5) (v4, v5) v1 v2 v3 v4 v5 (a) (b) Fig. 1 Each pair represents an edge.

2 Assignment #2 v1 v1 v2 v2 v3 v4 v3 v5 v4 v5
2.(30) Another way to perform topological sorting on a directed acyclic graph G = (V, E) is to repeatedly find a node of in-degree 0, output it, and remove it and all of its outgoing edges from the graph. Explain how to implement this idea so that it runs in time O(|V| + |E|). 3.(40) Consider the graph G shown in Fig. 1(a) once again. Its DFS tree T is shown in Fig. 2(a), in which each node v is associated with (d[v], f[v]). Remember that a node is a descendant of another node v in T if d[v] < d[u]) < f[u] < f[v]). v1 (1, 10) v1 (1, 10) v2 (2, 9) (2, 9) v2 v3 v4 v3 (a) (3, 6)(7, 8) v5 (b) (7, 8) (3, 6) v4 v5 (4, 5) (3, 6) (4, 5) Fig. 2 Describe an algorithm that associates each node v in G with a sequence s of pairs (as shown in Fig. 2(b)) such that u is a descendant of v in G if and only if d[v] < d[u]) < f[u] < f[v]), or there exists a pair p = (a, b) in s with a  d[u]) < f[u]  b.


Download ppt "Assignment #2 (Assignment due: Nov. 06, 2018) v1 v2 v3 v4 v5"

Similar presentations


Ads by Google