Question

For each of the following, give the Big-O time and explain your answer: a. Breadth-first search/traversal...

For each of the following, give the Big-O time and explain your answer:
a. Breadth-first search/traversal using an adjacency matrix.
b. Breadth-first search/traversal using an adjacency list.
c. Depth-first search/traversal using an adjacency matrix.
d. Depth-first search/traversal using an adjacency list.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a. Breadth-first search/traversal using an adjacency matrix.

in adjacency matrix graph is represented by using n*n Matrix where n is number of vertex in graph.

for loop runs two times in the logic. So complexity is O(V2)

============================================================================================
b. Breadth-first search/traversal using an adjacency list.

Complexity using an adjacency list is O(V+E) where V is vertices of the graph and E is edges of the graph.

BFS using adjacency list takes O(V) time to initialize the distance and predecessor for each vertex. then it traverse only the vertices reachable from a given source vertex so it takes max O(E) . so we get O(V+E).

if |E| >= |V| then  ∣V∣ + ∣E∣ <= ∣E∣+ ∣E∣ <= 2.|E| igonre constant then O(V+E) = O(E)

if |V| >= |E| then  ∣V∣ + ∣E∣ <= ∣V∣+ ∣V∣ <= 2.|V| igonre constant then O(V+E) = O(V)

============================================================================================
c. Depth-first search/traversal using an adjacency matrix.

in adjacency matrix graph is represented by using n*n Matrix where n is number of vertex in graph.

for loop runs two times in the logic. So complexity is O(V2)

============================================================================================
d. Depth-first search/traversal using an adjacency list.

Complexity using an adjacency list is O(V+E) where V is vertices of the graph and E is edges of the graph.

if |E| >= |V| then  ∣V∣ + ∣E∣ <= ∣E∣+ ∣E∣ <= 2.|E| igonre constant then O(V+E) = O(E)

if |V| >= |E| then  ∣V∣ + ∣E∣ <= ∣V∣+ ∣V∣ <= 2.|V| igonre constant then O(V+E) = O(V)

============================================================================================

Add a comment
Know the answer?
Add Answer to:
For each of the following, give the Big-O time and explain your answer: a. Breadth-first search/traversal...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT