CSE101: Design and Analysis of Algorithms (CSE, UCSD, Winter-2016) Homework-02 Name: ID number: There are 6 questions for a total of 10 points. 1. (1/2 point) Prove or disprove: Let G be any strongly connected undirected graph with at least two vertices. Then G has at least two vertices that have the same degree. (Degree of a vertex is the number of edges incident on that vertex.) 1 of 10 CSE101: Design and Analysis of Algorithms (CSE, UCSD, Winter-2016) Homework-02 2. (1/2 point) Run BFS on the undirected graph below with starting vertex A. Show the vertices present in each of the layers. 2 of 10 CSE101: Design and Analysis of Algorithms (CSE, UCSD, Winter-2016) Homework-02 3. (2 points) In the adjacency list representation for directed graphs, for every vertex v, a list of vertices to which v has a directed edge is stored. The in-degree of a vertex v is the number of vertices that have a directed edge to v. Given a directed graph in adjacency list representation, design an algorithm to computes the in-degrees of all the vertices. Give pseudocode for your algorithm and discuss running time. 3 of 10 CSE101: Design and Analysis of Algorithms (CSE, UCSD, Winter-2016) 4 of 10 Homework-02 CSE101: Design and Analysis of Algorithms (CSE, UCSD, Winter-2016) Homework-02 4. (2 points) A rooted tree has a special node r called the root and zero or more rooted subtrees T1 , ..., Tk each of whose roots are connected to r. The root of each subtree is called the child of r and r is called the parent of each child. Nodes with no children are called leaf nodes. The depth of a node is the number of edges from the root to that node. The height of a node is the number of edges from that node to deepest leaf in the subtree rooted at that node. The height of a rooted tree is the height of its root. Rooted trees can be thought of as directed graphs where there is a directed edge from parent to its child. Given this, rooted trees may be given in adjacency list representation. Design an algorithm that computes the height of a rooted tree given in the adjacency list representation. Give pseudocode and discuss running time. 5 of 10 CSE101: Design and Analysis of Algorithms (CSE, UCSD, Winter-2016) 6 of 10 Homework-02 CSE101: Design and Analysis of Algorithms (CSE, UCSD, Winter-2016) Homework-02 5. (2 points) A binary tree is a rooted tree in which each node has at most two children. Show by induction that in any binary tree the number of nodes with two children is exactly one less than the number of leaves. 7 of 10 CSE101: Design and Analysis of Algorithms (CSE, UCSD, Winter-2016) 8 of 10 Homework-02 CSE101: Design and Analysis of Algorithms (CSE, UCSD, Winter-2016) Homework-02 6. (3 points) Suppose you are given an undirected graph G = (V, E) and two nodes s and t such that all paths between s and t have length strictly greater than |V |/2. Show that there will exist a node v 6= s, t such that removing v will disconnect s and t. That is, consider the graph G0 obtained by removing v and its edges from G. Then there is no path between s and t in G0 . Design an algorithm to find such a node. Give pseudocode and discuss correctness and running time. (Hint: Use BFS.) 9 of 10 CSE101: Design and Analysis of Algorithms (CSE, UCSD, Winter-2016) 10 of 10 Homework-02
© Copyright 2026 Paperzz