A1 Write a function Connected Component (G,v) which takes as in- put a dictionary representing a graph G, and one of its vertices v, and returns a set of nodes representing the connected com- ponent of v, implementing the method given in the notes. Hint: Create and update lists called visitednodes repres- enting previously visited nodes, latestnodes representing the most recently visited nodes, and newnodes representing nodes neighbouring those in latestnodes and not included in either of the previous categories. A2 Write a function NumberOfComponents (G) which takes as in- put a dictionary representing a graph G and returns a positive integer representing its number of connected components. A3 Recall that an ordinary (unweighted) graph can be considered a weighted graph by assigning every edge weight 1. The "shortest path" from a to b in this interpretation is simply the path from a to b with the fewest edges. This makes Dijkstra's algorithm simpler as the shortest path from a to b will simply be the first one found.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question
A1 Write a function Connected Component (G,v) which takes as in-
put a dictionary representing a graph G, and one of its vertices
v, and returns a set of nodes representing the connected com-
ponent of v, implementing the method given in the notes.
Hint: Create and update lists called visitednodes repres-
enting previously visited nodes, latestnodes representing the
most recently visited nodes, and newnodes representing nodes
neighbouring those in latestnodes and not included in either
of the previous categories.
A2 Write a function NumberOfComponents (G) which takes as in-
put a dictionary representing a graph G and returns a positive
integer representing its number of connected components.
A3 Recall that an ordinary (unweighted) graph can be considered a
weighted graph by assigning every edge weight 1. The "shortest
path" from a to b in this interpretation is simply the path from
a to b with the fewest edges. This makes Dijkstra's algorithm
simpler as the shortest path from a to b will simply be the first
one found.
Transcribed Image Text:A1 Write a function Connected Component (G,v) which takes as in- put a dictionary representing a graph G, and one of its vertices v, and returns a set of nodes representing the connected com- ponent of v, implementing the method given in the notes. Hint: Create and update lists called visitednodes repres- enting previously visited nodes, latestnodes representing the most recently visited nodes, and newnodes representing nodes neighbouring those in latestnodes and not included in either of the previous categories. A2 Write a function NumberOfComponents (G) which takes as in- put a dictionary representing a graph G and returns a positive integer representing its number of connected components. A3 Recall that an ordinary (unweighted) graph can be considered a weighted graph by assigning every edge weight 1. The "shortest path" from a to b in this interpretation is simply the path from a to b with the fewest edges. This makes Dijkstra's algorithm simpler as the shortest path from a to b will simply be the first one found.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning