Graphs-and-Tree
Question 1 |
S1:The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
S2:The sequence of procedure returns corresponds to a postorder traversal of the activation tree.
Which one of the following options is correct?
S1is false and S2is false
| |
S1is true and S2is true | |
S1is true and S2is false | |
S1is false and S2is true |
The given statements are true, they are well known facts.
- The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
- The sequence of returns corresponds to a postorder traversal of the activation tree.
Question 2 |
Let G = (V,E) be a directed, weighted graph with weight function w:E → R. For some function f:V → R, for each edge (u,v) ∈ E, define w'(u,v) as w(u,v) + f(u) - f(v).
Which one of the options completes the following sentence so that it is TRUE?
“The shortest paths in G under w are shortest paths under w’ too, _______”.
if and only if f(u) is the distance from s to u in the graph obtained by adding a new vertex s to G and edges of zero weight from s to every vertex of G | |
if and only if ∀u ∈ V, f(u) is positive
| |
if and only if ∀u ∈ V, f(u) is negative | |
for every f: V→R |
Question 3 |
Which of the following is/are correct about the graph?
For each pair of vertices u and v, there is a directed path from u to v. | |
The graph does not have a strongly connected component. | |
The graph does not have a topological order. | |
A depth-first traversal staring at vertex S classifies three directed edges as back edges. |
Option-1: FALSE: There is no path from top right corner vertex to any other vertex
Option-2: FALSE: A directed graph is called strongly connected if there is a path in each direction between each pair of vertices of the graph. As there is no path from the above vertex then this statement is wrong.
Option-3: TRUE: This graph does have directed cycles, thus topological order can not be possible for according to topological definition.
Question 4 |
Breadth first search; acyclic | |
Topological sort; acyclic | |
Breadth first search; cyclic | |
Topological sort; cyclic |
Question 5 |
All successor of a visited node before any successors of any of those successors | |
A single path of the graph as far it can go | |
Graph using shortest path | |
None of these |
Question 6 |
v2v4 | |
v1v4 | |
v4v5 | |
v3v4 |
Question 7 |
A flow graph F with entry node (1) and exit node (11) is shown below:
What is the cyclomatic complexity of flowgraph F
2 | |
3 | |
4 | |
5 |
1. The number of regions(R) corresponds to the cyclomatic complexity. Total number of regions(R) are 4.
2. V(G),Flow graph is defined as V(G)=E-N+2 where E is the number of flow graph edges, and N is the number of flow graph nodes.
Predicates are 3+1=4
3. V(G),Flow graph is defined as V(G)=P+1 where p is the number of predicate nodes contained in the flow graph G.
Edges(E)-Nodes(N)+2
= 11-9+2
= 2+2
= 4