Question: Exercise 3 . Finding Paths in Search Trees Suppose that after the call to the parent - finding D F S ( G , s
Exercise Finding Paths in Search Trees
Suppose that after the call to the parentfinding or from exercise the parent labels are stored with the nodes of the graph, and are available to you. Meaning that for any node parentv will return its parent in the search tree rooted at s or NULL if there is none.
a Show the algorithm findPath which returns the path from s to v for any node v in G as a list of nodes, or NULL if there is none. Make it as simple as possible. It should be where k is the number of nodes in the path.
b Given any two paths and in the search tree of G they will start with the same sequence of nodes in the least case, they will both start with s Note that if we reverse and append we get a path from to
We define least common ancestor of x and y as the last node that and have in common, denoted LCA
Example: and LCA
Explain how to use LCA information to give us a simple path from u to v Note that finding LCA is also a variation of Merge, like the ones we saw in the last homework.
c Based on your explanation in b show pseudocode to find simple paths between any two nodes in a graph, findSimplePath It would make calls to findPath findPath and LCApathl path
d Number the lines in your pseudocode, and analyze the time complexity of your algorithm referring to the line numbers. What is the running time?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
