Question: Question 1 : Dead Ends ( 2 5 points ) You work for a road construction company and your manager asks you to list all
Question : Dead Ends points
You work for a road construction company and your manager asks you to list all deadended intersections in the city. You are given an undirected graph G with vertices representing intersections, and edges representing roads in the city. You can assume that there are no vertices with edges, ie all roads are connected. Dead ends are represented as vertices that have only one edge.
a Describe at a high level how you would determine which vertices are deadended. Your function should return a list of vertices, and the only parameter should be the graph G with GV as a list of vertices and GE as a list of edges. points
b Provide the pseudocode for your function. points
Your manager now wants you to find which roads edges lead to deadends, rather than just the intersections. Remember that the order of choosing edges from a vertex in a breadthfirst search is arbitrary. An edge leads to a deadend if a breadthfirst traversal beginning from a deadended intersection MUST traverse that edge in a deterministic order. For example:
In the image to the right, intersections A and J are deadends. A breadthfirst search from A MUST traverse AB then B C and CD in that exact order, so those will be roads that lead to deadends. Once we reach D we can arbitrarily choose any of DED G or DF so those roads will not be marked as deadended.
A breadthfirst search from J must traverse JI so that road leads to a deadend. However, from point I we can choose either of mathrmImathrmH or mathrmImathrmK to traverse, so these roads will not be marked as deadended.
c Write the pseudocode for an algorithm that, given a graph G will return a list of edges that lead to deadends. You may use the function you wrote in part b as a subprocedure. points
d Provide the bigO runtimes of part b and c and explain your answer. points
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
