

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions to homework assignment 7 in a data structures and algorithms course. It includes the adjacency matrix and list representations for a given graph, the depth-first and breadth-first search trees, and a proof that a free tree has n-1 edges using mathematical induction.
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


1 2 3 4 5 6 1 0 10 0 20 0 2 2 10 0 3 5 0 0 3 0 3 0 0 15 0 4 20 5 0 0 11 10 5 0 0 15 11 0 3 6 2 0 0 10 3 0 (b) Draw the adjacency list representation for the same graph.
1 2 3 4 5 6 (^2 10 4 20 )
(^1 10 3 3 )
2 3 5 15
(^1 20 2 5 5 11 6 )
(^3 15 4 11 6 )
1 2 4 10 5 3
(c) If a pointer requires 4 bytes, a vertex label requires 2 bytes, and an edge weight requires 2 bytes, which representation requires more space for this graph? Both graphs need to store a vertex label for each of the 6 vertices:
6 × 2 bytes = 12 bytes.
In addition the adjacency matrix will store 36 edge labels for a total of
36 × 2 bytes + 12 bytes = 84 bytes.
Data Structures and Algorithms, Key to Homework 7 2
There are 9 edges, and the adjacency list will store each edge weight twice. So this will increase the total for the list to
18 × 2 bytes + 12 bytes = 48 bytes.
In addition, for each of the 18 edge nodes, the list will store a pointer:
18 × 4 bytes + 48 bytes = 120 bytes.
Finally, the list will require 6 pointers for the heads of the lists, giving a grand total of
6 × 4 bytes + 120 bytes = 144 bytes.
So the adjacency list requires more space for this graph.
1
2 4 6
3 5