# solhw3 - COT5405 Analysis of Algorithms Homework 3...

This preview shows pages 1–3. Sign up to view the full content.

COT5405 Analysis of Algorithms Homework 3 Solutions 1. Prove or give a counter example: (a) In the textbook, we have two routines for graph traversal - DFS( G ) and BFS( G , s ) - where G is a graph and s is any node in G . These two procedures will create a DFS tree and a BFS tree respectively. If G = ( V, E ) is a connected, undirected graph then the height of DFS( G ) tree is always larger than or equal to the height of any of the BFS trees created by BFS( G , s ). Answer 1 2 3 4 5 Counter example: The DFS can start from any arbitrary node. So we pick the center node. For BFS we pick any of the boundary nodes. Then the height of DFS tree is 1, whereas the height of BFS tree is 2. For this problem, if you make an assumption that DFS and BFS always start at the same node and prove that the height of the DFS tree is always larger than that of BFS tree, then also you’ll get credit – if your proof is good. (b) BFS and DFS algorithms on a undirected, connected graph G = ( V, E ), produce the same tree if and only if G is a tree. Answer First we show that G is a tree when both BFS-tree and DFS-tree are same. If G and T are not same, then there should exist an edge e ( u, v ) in G , that does not belong to T . In such a case: 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
– in the DFS-tree, one of the u or v , should be an ancestor of the other. – in the BFS-tree, u and v can differ by only one level. Since, both DFS-tree and BFS-tree are same tree T , it follows that one of u and v should be an ancestor of the other and they can differ by only one level. This implies that the edge connecting them must be in T . So, there can not be any edges in G which are not in T . In the second part of the proof: Since G is a tree, each node has a unique path from the root. So, both BFS and DFS produce the same tree, and the tree is same as G . 2. When an adjacency-matrix representation is used, most graph algorithms require time Ω( V 2 ), but there are some exceptions. Show that determining whether a directed graph G contains a universal sink – a vertex with in-degree | V | - 1 and out-degree 0 – can be determined in time O ( V ), given an adjacency matrix for G . Answer We are looking for a universal sink i.e. a vertex in degree of | V | - 1 and out degree of zero. In the adjacent matrix the elements the element in row i represent the edges that are out-going from node i to other nodes. And the elements in column j represent the edges that are in-coming to node j . The task is to find k , such that row k has all zero’s and column k has all 1 s except for the element in row k (which is a zero).
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern