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

Similar documents
CSE 100 Minimum Spanning Trees Prim s and Kruskal

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

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

Review for Midterm Exam

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?

Lecture 9 Graph Traversal

Homework Assignment #3 Graph

Exam 3 Practice Problems

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

CS 170 Second Midterm ANSWERS 7 April NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt):

MA/CSSE 473 Day 12. Questions? Insertion sort analysis Depth first Search Breadth first Search. (Introduce permutation and subset generation)

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

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

) $ f ( n) " %( g( n)

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

CSE 373 NOVEMBER 20 TH TOPOLOGICAL SORT

( ) n 3. n 2 ( ) D. Ο

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

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

Chapter 9 Graph Algorithms

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

CS521 \ Notes for the Final Exam

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

CS61BL. Lecture 5: Graphs Sorting

Graph Algorithms. Definition

Graph Algorithms (part 3 of CSC 282),

Problem Pts Score Grader Problem Pts Score Grader

Outline. Graphs. Divide and Conquer.

Data Structures Brett Bernstein

n 2 ( ) ( ) + n is in Θ n logn

CSci 231 Final Review

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

Graphs & Digraphs Tuesday, November 06, 2007

Chapter 9 Graph Algorithms

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

Info 2950, Lecture 16

Course Review for Finals. Cpt S 223 Fall 2008

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

CS 161 Fall 2015 Final Exam

( D. Θ n. ( ) f n ( ) D. Ο%

Graph Algorithms (part 3 of CSC 282),

RYERSON UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE CPS 616 FINAL EXAM WINTER 2018

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

INDIAN STATISTICAL INSTITUTE

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

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

Final Examination CSE 100 UCSD (Practice)

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Graphs. Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale Room - Faner 3131

DESIGN AND ANALYSIS OF ALGORITHMS

CMPSCI 311: Introduction to Algorithms Practice Final Exam

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI. Department of Computer Science and Engineering CS6301 PROGRAMMING DATA STRUCTURES II

Chapter 9 Graph Algorithms

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

CISC 320 Midterm Exam

CS4800: Algorithms & Data Jonathan Ullman

(Dijkstra s Algorithm) Consider the following positively weighted undirected graph for the problems below: 8 7 b c d h g f

CSE332 Summer 2012 Final Exam, August 15, 2012

Question Points Score TOTAL 50

Chapter 5. Decrease-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

CS 310 Advanced Data Structures and Algorithms

( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms

Brute Force: Selection Sort

COMP 251 Winter 2017 Online quizzes with answers

tree follows. Game Trees

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

CSE 417: Algorithms and Computational Complexity

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

CS 4349 Lecture October 18th, 2017

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

22.3 Depth First Search

CS490 Quiz 1. This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed.

Lecture 6 Basic Graph Algorithms

Minimum Spanning Trees

CSE 100: GRAPH ALGORITHMS

GRAPHS Lecture 17 CS2110 Spring 2014

Undirected Graphs. Hwansoo Han

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

Unweighted Graphs & Algorithms

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu

Graph. Vertex. edge. Directed Graph. Undirected Graph

Virtual University of Pakistan

RYERSON UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE CPS 616 MIDTERM WINTER 2017

CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14

CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

CSE 373: Practice Final

Lecture 3: Graphs and flows

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016

University of New Mexico Department of Computer Science. Final Examination. CS 362 Data Structures and Algorithms Spring, 2006

( ) 1 B. 1. Suppose f x

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

CS170 Discussion Section 4: 9/18

Quiz 2. Problem Parts Points Grade Grader. Total 120. Name: Recitation: Jayant 12 PM. Christina 10 AM. Jayant 1 PM. Jason 2 PM.

Konigsberg Bridge Problem

Plan. CMPSCI 311: Introduction to Algorithms. Recall. Adjacency List Representation. DFS Descriptions. BFS Description

Transcription:

Stony Brook University Midterm 2 CSE 373 Analysis of Algorithms November 22, 2016 Midterm Exam Name: ID #: Signature: Circle one: GRAD / UNDERGRAD INSTRUCTIONS: This is a closed book, closed mouth exam. You must use pencil in the multiple choice component. You must enter the multiple choice on the bubble sheet!!! Check to see that you have 8 pages. Write your algorithms in sufficient detail that we can be sure you understand what you are doing. Use the back of the pages if you need more room. Look over all problems before starting work. Think before you write. Good luck!! Problem Score Maximum 1 15 2 20 3 15 MC 34 (25/17) = 50 Total 100 1

1) (15 points) Describe a backtracking algorithm for efficiently listing all k-element subsets of n items. For n = 5, the 3-element subsets are: (1,2,3), (1,2,4), (1,2,5), (1,3,4), (1,3,5), (1,4,5), (2,3,4), (2,3,5), (2,4,5), (3,4,5). In particular, first describe the solution vector representation you use, and then describe how you partition the work among construct-candidates, is-a-solution, and process-solution. 2

2) (20 points) A monotonically non-decreasing subsequence of a sequence S of n numbers is a subsequence T of S such that T i T i 1. Ties are allowed, but not rearranging the order of the elements. As an example, the longest non-decreasing subsequence of the sequence S = (2, 5, 2, 8, 7, 3, 1, 6, 4) has length 4 and is either (2,2,3,4) or (2,2,3,6). (a) Give a longest non-decreasing subsequence of S = {2, 4, 3, 5, 1, 7, 6, 9, 8}. How long is it? (b) In English, define a function to compute which will permit a dynamic programming algorithm to find the length of the longest non-decreasing subsequence of S. (c) Give a recurrence relation to compute this function. (d) What is the running time, if we use dynamic programming to implement the recurrence? 3

3) (15 points) A minimum bottleneck spanning tree of a weighted graph G = (n, m) is a spanning tree which minimizes the length of the longest single edge in the tree. (a) The graph given below has a minimum bottleneck spanning tree whose longest edge is of length 11. Draw this tree. 1 A B 18 20 C D 2 4 1 4 13 E F G 22 H 10 5 6 11 5 I J 4 23 K L 11 3 9 12 9 9 M N O P 1 8 (b) Now describe a correct and efficient algorithm to find the minimum bottleneck spanning tree. You must give a convincing proof of correctness and give its big Oh running time for full credit. 4

Multiple Choice Answer these multiple choice problems in pencil on the bubble sheet! You may write on these pages but they will not be graded. Mark your test version on the bubble sheet NOW. You have test version 2. Neither the TA nor the instructor will answer any questions about these multiple choice problems. Use your best judgement about what they mean. For all questions on graphs, let n be the number of edges, m be the number of edges, and d(x) be the degree of a given node. 1. What is the running time for generating all the permutations of n distinct numbers using backtracking? A. Θ(n) B. Θ(n 2 ) C. Θ(2 n ) D. Θ(n!) 2. Which of these can be a possible output order of a backtracking algorithm to construct permutations of {1, 2, 3}? A. 2,3,1; 2,1,3; 1,2,3; 3,2,1; 3,1,2; 1,3,2 B. 3,1,2; 3,2,1; 1,3,2; 1,2,3; 2,1,3; 2,3,1 C. 2,1,3; 2,3,1; 3,2,1; 1,3,2; 3,1,2; 1,2,3 D. 1,2,3; 2,3,1; 1,3,2; 2,1,3; 3,1,2; 3,2,1 3. Let a 1, a 2,..., a n be a sequence of numbers. An increasing subsequence is a subsequence of not-necesssarily adjacent numbers which are getting strictly larger. What is the length of the longest increasing subsequence of {5, 2, 8, 6, 3, 9, 4, 1, 7}? A. 3 B. 4 C. 5 D. 6 4. What is the edit distance of the following two strings? string 1: SNOWY string 2: SUNY A. 2 B. 3 C. 4 D. 5 5. Which is the fastest algorithm for finding the shortest path between two vertices in an unweighted graph? A. Breadth-first search B. Depth-first search C. Dijkstra s shortest path D. Floyd s algorithm 6. Which of the following is true of every DAG with n vertices? A. every vertex is an articulation vertex B. there are o(n 2 ) edges C. there are Ω(n) edges D. there is at least one topological ordering of the vertices 7. Which of the following is true of every tree with n vertices? A. every vertex is an articulation vertex B. the adjacency list representation takes O(n) space. C. it is strongly-connected 5

D. there is at most one topological ordering of the vertices 8. What is the running time to compute the following recurrence, if properly implemented with dynamic programming, as a function of n? n 1 F (n) = (F (i) F (i 1)) i=1 A. Θ(n) B. Θ(n log n) C. Θ(n 2 ) D. Θ(n 3 ) 9. What is the running time to compute the following recurrence, if properly implemented with dynamic programming, as a function of n and k? F (n, k) = n 1 A. Θ(nk) B. Θ(n 2 k) C. Θ(n 2 k 2 ) D. Θ(n 3 k 3 ) i=0 j=0 k F (i, j) 10. Recall that Prim s algorithm keeps track of the distance from each node not yet in the minimum spanning tree (MST) to its closest neighbor in the MST, while Kruskal s algorithm sorts the set of edges and repeated adds nodes using union find to determine if they are already in the same component. Kruskal s algorithm performs better on ones. A. dense, sparse B. sparse, dense C. cyclic, acyclic D. acyclic, cyclic graphs, while Prim s performs better on 11. What is the space complexity of Djikstra s algorithm, not counting the input graph? A. O(n) B. O(n log n) C. O(1) D. O(m) 12. The stack data structure is largely associated with what graph traversal algorithm? 13. The queue data structure is largely associated with what graph traversal algorithm? 14. A graph with a cycle is traversed to produce a search tree. All of the non-tree edges in the cycle connect to ancestors. What graph traversal algorithm was used to traverse the graph? 15. An undirected graph is traversed to produce a search tree. All of the non-tree edges in each cycle connect to siblings on the same level. What graph traversal algorithm was used to traverse the graph? 16. Students must take certain prerequisite classes before taking advanced courses. What type of algorithm can be run to provide a valid order of classes to take? 6

17. In an unweighted graph, which of the following algorithms does not produce a minimum spanning tree? A. Topological Sort B. Breadth-First Search C. Kruskal s Algorithm D. Prim s Algorithm 18. Which algorithm does not allow for negative edge weights when computing an answer? A. Kruskal s algorithm B. Dijkstra s algorithm C. Prim s algorithm D. Connected components 19. When constructing all permutations of n elements, what is the advantage of Backtrack-DFS over a simple BFS? A. Space complexity B. Time complexity C. Simplicity of programming D. No real advantage 20. One issue with developing an algorithm for games with large search trees, such as Chess, is the exponential number of possibilities for future moves. What technique can be used to remove some possibilities when searching? A. Pruning B. Simulated Annealing C. Parallel Algorithms D. Backtracking 21. What is the best achievable space complexity for an O(n) algorithm that computes the Fibonnaci numbers using dynamic programming? A. O(1) B. O(n) C. O(n 2 ) D. O(2 n ) 22. You are tasked with finding the maximum number in a set of values, A, using dynamic programming. Which recurrence gives a valid definition of M ax(x)? A. Max(x) = max(a[x], A[x 1]) B. Max(x) = max(a[x 1], A[x 2]) C. Max(x) = max(a[x 1], Max(x)) D. Max(x) = max(a[x], Max(x 1)) 23. If the pre-order traversal sequence of a tree T is ACDEF HGB, the in-order traversal sequence is DECAHF BG, then what is the sequence of post-order traversal? A. HGF EDCBA B. EDCHBGF A C. BGF HEDCA D. EDCBGHF A 24. A simple undirected graph of 8 vertices can have at most ( ) edges. A. 14 B. 28 C. 56 D. 112 25. A connected, undirected graph of 8 vertices must have at least ( ) edges. A. 5 B. 6 C. 7 D. 8 26. The time complexity of the Floyd-Warshall algorithm is ( ). A. O(n) B. O(n log n) C. O(n 2 ) D. O(n 3 ) 27. Backtracking is essentially ( ). A. a recursive algorithm B. an iterative algorithm C. BFS D. DFS 7

Figure 1: Graph 1. 28. For the graph shown in Figure 1, suppose vertices A, B, C, D, E, F, G are stored in alphabetical order in this graph. What is DFS order of traversing this graph starting from vertex G? A. G, A, B, C, D, E, F B. G, A, B, D, C, E, F C. G, A, B, C, E, D, F D. G, A, B, C, F, E, D 29. For the graph shown in Figure 1, suppose vertices A, B, C, D, E, F, G are stored in alphabetical order in this graph. What is BFS order of traversing this graph starting from vertex G? A. G, A, F, B, C, D, E B. G, A, B, C, F, D, E C. G, A, C, F, B, E, D D. G, A, F, B, C, E, D 30. Which of the following does not involve DFS traversal on a graph? A. Finding cycles. B. Finding articulation vertices. C. Find the shortest path from the root to a node. D. Topological sorting of vertices. Figure 2: Graph 2. 31. When running Prim s algorithm on Graph 2 to find the minimum spanning tree, what can be the vertex order of this algorithm staring from vertex a? A. a, c, b, d, e, f, g B. a, c, b, e, d, f, g C. a, c, d, e, b, f, g D. a, c, b, e, f, g, d 32. What is the total weight of the minimum spanning tree of Graph 2? A. 21 B. 22 C. 23 D. 24 33. When running Dijkstra s algorithm on Graph 2 to find the shortest path from a to g, what can be the vertex order of this algorithm staring from vertex a? A. a, c, b, d, e, f, g B. a, c, b, e, d, f, g C. a, c, d, e, b, f, g D. a, c, b, e, f, g, d 34. What is the length of the shortest path from a to g in Graph 2? A. 3 B. 11 C. 12 D. 14 8