CSE Winter 2015 Quiz 1 Solutions

Similar documents
CSE 101, Winter Discussion Section Week 1. January 8 - January 15

Final Exam in Algorithms and Data Structures 1 (1DL210)

CISC 320 Midterm Exam

Solutions. (a) Claim: A d-ary tree of height h has at most 1 + d +...

Exercise 1. D-ary Tree

Asymptotic Analysis Spring 2018 Discussion 7: February 27, 2018

Data Structure and Algorithm, Spring 2013 Midterm Examination 120 points Time: 2:20pm-5:20pm (180 minutes), Tuesday, April 16, 2013

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

0.1 Welcome. 0.2 Insertion sort. Jessica Su (some portions copied from CLRS)

UCSD CSE 101 MIDTERM 1, Winter 2008

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

asymptotic growth rate or order compare two functions, but ignore constant factors, small inputs

INDIAN STATISTICAL INSTITUTE

Quiz 1 Solutions. Asymptotic growth [10 points] For each pair of functions f(n) and g(n) given below:

Chapter 8 Sort in Linear Time

[ 11.2, 11.3, 11.4] Analysis of Algorithms. Complexity of Algorithms. 400 lecture note # Overview

PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS

Midterm 1 for CS 170

EECS Sample Midterm Exam

Assignment 1 (concept): Solutions

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# #

Total Score /1 /20 /41 /15 /23 Grader

CS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

We don t have much time, so we don t teach them [students]; we acquaint them with things that they can learn. Charles E. Leiserson

100 points total. CSE 3353 Homework 1 Fall 2014

Introduction to Algorithms and Complexity Theory

Final Exam in Algorithms and Data Structures 1 (1DL210)

Quiz 1 Solutions. (a) If f(n) = Θ(g(n)) and g(n) = Θ(h(n)), then h(n) = Θ(f(n)) Solution: True. Θ is transitive.

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment

Multiple-choice (35 pt.)

Solving problems on graph algorithms

Introduction to Data Structure

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

Quiz 1 Practice Problems

CS261: Problem Set #1

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

Data Structures Question Bank Multiple Choice

Analysis of Algorithm. Chapter 2

Complexity of Algorithms

Quiz 1 Practice Problems

Problem Pts Score Grader Problem Pts Score Grader

UNIT 1 ANALYSIS OF ALGORITHMS

CSE 331 Introduction to Algorithm Analysis and Design. Sample Mid-term Exam-I: Fall 2018

CSE 332, Spring 2010, Midterm Examination 30 April 2010

Algorithms Activity 6: Applications of BFS

Analyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]:

CSE 247 Data Structures and Algorithms Fall Exam I

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2010

Exam Sample Questions CS3212: Algorithms and Data Structures

Data Structures and Algorithms Chapter 2

Homework Assignment #3 Graph

END-TERM EXAMINATION

CS141: Intermediate Data Structures and Algorithms Analysis of Algorithms

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Algorithms and Data Structures

Solutions to relevant spring 2000 exam problems

Midterm solutions. n f 3 (n) = 3

Analysis of Algorithms

COMPSCI 311: Introduction to Algorithms First Midterm Exam, October 3, 2018

U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions

Overview. CSE 101: Design and Analysis of Algorithms Lecture 1

CSci 231 Final Review

Graph: representation and traversal

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

CS141: Intermediate Data Structures and Algorithms Analysis of Algorithms

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

DATA STRUCTURES AND ALGORITHMS

Lower bound for comparison-based sorting

Problem Score Maximum MC 34 (25/17) = 50 Total 100

Algorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48

CS 360 Exam 1 Fall 2014 Name. 1. Answer the following questions about each code fragment below. [8 points]

Chapter 2: Complexity Analysis

Jessica Su (some parts copied from CLRS / last quarter s notes)

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

CS 173 [A]: Discrete Structures, Fall 2012 Homework 8 Solutions

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

Solutions to Midterm 2 - Monday, July 11th, 2009

Internal Sorting by Comparison

CSE Winter 2015 Quiz 2 Solutions

L.J. Institute of Engineering & Technology Semester: VIII (2016)

Algorithms (IX) Guoqiang Li. School of Software, Shanghai Jiao Tong University

Copyright 2000, Kevin Wayne 1

Data Structure and Algorithm Homework #1 Due: 1:20pm, Tuesday, March 21, 2017 TA === Homework submission instructions ===

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 10 Notes. Class URL:

Quiz 2 Solutions. (a) T F Topological sort requires Ω(V lg V ) if the edge weights are unbounded. Explain:

STA141C: Big Data & High Performance Statistical Computing

Complexity of Algorithms. Andreas Klappenecker

CS2 Practical 6 CS2Bh 24 January 2005

n 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

Review for Midterm Exam

Your favorite blog : (popularly known as VIJAY JOTANI S BLOG..now in facebook.join ON FB VIJAY

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

CSE 331: Introduction to Algorithm Analysis and Design Graphs

Prelim 2 Solutions. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Homework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm

looking ahead to see the optimum

CSE 638: Advanced Algorithms. Lectures 10 & 11 ( Parallel Connected Components )

Transcription:

CSE 101 - Winter 2015 Quiz 1 Solutions January 12, 2015 1. What is the maximum possible number of vertices in a binary tree of height h? The height of a binary tree is the length of the longest path from the root vertex to any vertex in the tree. [2 h+1 1] Solution Testing with small values we guess that the answer is 2 h+1 1. We will prove this by induction. When h = 0 this is indeed true as there is just one root vertex. Now suppose it is true for h = k. Now we create a tree of height k + 1 by joining two trees of height k through a root node. This gives the total number of vertices = 2 k 1 + 2 k 1 + 1 = 2 k+1 1 which is what we wanted. 2. Perform DFS on the following directed graph starting at vertex A. How many trees are present in the DFS search forest that is obtained? [B] A. 0 B. 1 (correct) C. 2 D. 3 Solution All the vertices of the given graph are reachable from vertex A. As a result, performing DFS starting from A will result in only one DFS tree, which contains all the vertices of the graph. 1

3. We want to count monotone paths between points with integer coordinates. Only two kinds of steps are allowed: a right-step which increments the x coordinate and an up-step which increments the y coordinate. Suppose that there is an obstacle at (5, 4) such that no path can pass through this point. How many monotone paths are there from (0, 0) to (9, 6)? [Note : Monotone path is simply a staircase path that only uses rightward and upward edges to get from the source to the destination.] [C(15, 6) C(9, 5) C(6, 4) = 3115] Solution A path from origin to (9, 6) will require 9 right steps and 6 up steps, giving a total of C(15, 6) paths from origin to (9, 6). The number of paths that pass through the point (5, 4) are the paths that first reach (5, 4) and then go to (9, 6). (5, 4) can be reached from origin in C(9, 5) ways and (9, 6) can be reached from (5, 4) in C(6, 4) ways. The number of paths passing through (5, 4) is thus C(9, 5) C(6, 4). The required number of paths is therefore C(15, 6) C(9, 5) C(6, 4). 4. Suppose an undirected graph has 13 vertices and 8 of the vertices have degree 2 each. What could be a possible value of the sum of degrees of the other five vertices? (Hint : the handshake lemma) A. 10 (correct) B. 5 C. 15 D. 25 Solution Apply the handshake lemma to see that the sum of the degrees of all vertices of the graph must be even. Thus, as eight of the nodes have degree two each, then the sum of the degrees of the remaining five vertices must be even too. The only possible option is 10. Hence option A is correct. 5. In a connected graph containing N vertices, there is exactly one path between any two vertices. The minimum possible number of edges in this graph, and the maximum number of edges in this graph, are respectively: [D] A. Θ(N) and Θ(N 2 ) B. Θ(1) and Θ(N 2 ) C. Θ(1) and Θ(N) D. Θ(N) and Θ(N) (correct) Solution The given condition is one of the if and only if conditions for a graph G to be a tree. Hence G is a tree and has N 1 edges. If we define functions f(n) = N 1 and g(n) = N, then we can say that f(n) = Θ(g(N)) = Θ(N). 2

6. Let f(n) = 2 n3 and g(n) = n!. Which of the following best represents the relationship between f(n) and g(n)? (Hint : take logs) [C] A. f(n) = O(g(n)) B. f(n) = Θ(g(n)) C. f(n) = Ω(g(n)) (correct) Solution Let s consider the ratio log(f(n)) log(g(n)) as n. Thus f(n) = Ω(g(n)). log(f(n)) 3n log(2) = log(g(n)) log(n!) (1) 3n log(2) = Θ(n) log(n!) Θ(n logn) (2) Θ(n) Θ(n logn) = 0 (3) 7. Given an arbitrary, connected, undirected and unweighted (i.e., all edge costs = 1) graph G = (V, E), which of the following will always find the shortest path from a given starting vertex s V to any other vertex t V? [B] A. DFS starting from s B. BFS starting from s (correct) C. Both (A) and (B) D. Neither (A) nor (B) Solution DFS (DPV textbook, p96) may find the shortest path from s to t, but it is not guaranteed and there are counterexamples showing how DFS fail to find a shortest path. This counterexample shows DFS find a path A > B > C > E first, therefore it fails to find a shortest path A > D > E. 3

8. The tightest time complexity of DFS in a graph G = (V, E), which holds for ANY graph G, is: A. O( V + E ) (correct) B. O( V E ) C. O( V 2 ) D. O( E 2 ) Solution The time complexity of DFS is O( V + E ), which follows directly from the procedure as analysed in Section 3.2.2 of the DPV textbook. 9. For the pseudo-code given below, select the correct asymptotic running time in Θ notation: for i = 1 to n do j = i while j < n do j = j + 4 end while end for A. Θ(n 2 ) (correct) B. Θ(log(n)) C. Θ( n) D. Θ(n 3 ) (Credit: Berkeley CS 170 website) Solution In the given pseudo-code, line 2 and the condition in while are unit time operations in the outer loop which is executed n times. Line 4 is another unit time operation that is within the inner loop which is executed n/4 times for each iteration of the outer loop. Line 4 is thus executed a total of n (n/4) times. The total number of unit-time operations is 2n + n(n/4) = n 2 /4 + 2n = O(n 2 ). Since n 2 /4 + 2n is also Ω(n 2 ), the correct answer is Θ(n 2 ). 10. After running DFS on a directed graph, a vertex v has pre label 8 and post label 12. A vertex u has pre label 13 and post label 17. If (u, v) is an edge of the graph, then it is a: [C] A. Back edge B. Forward edge C. Cross edge (correct) 4

D. Tree edge Solution It can be seen that the pre and post numbers of vertices v and u do not overlap; i.e. [8, 12] and [13, 17] are disjoint intervals. Hence, the edge from u to v, (u, v), corresponds to a Cross edge of the graph. 5