Design and Analysis of Algorithms - - Assessment

Similar documents
Review of course COMP-251B winter 2010

CS521 \ Notes for the Final Exam

CSci 231 Final Review

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G.

CS61BL. Lecture 5: Graphs Sorting

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

Course Review for Finals. Cpt S 223 Fall 2008

Data Structures Question Bank Multiple Choice

Recitation 9. Prelim Review

COMP 251 Winter 2017 Online quizzes with answers

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

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

END-TERM EXAMINATION

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

Exam 3 Practice Problems

Review for Midterm Exam

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

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

Graph Algorithms (part 3 of CSC 282),

CSE 373 Final Exam 3/14/06 Sample Solution

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

1 Format. 2 Topics Covered. 2.1 Minimal Spanning Trees. 2.2 Union Find. 2.3 Greedy. CS 124 Quiz 2 Review 3/25/18

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

Data Structures Brett Bernstein

CISC 320 Midterm Exam

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

Question 7.11 Show how heapsort processes the input:

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

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

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

Practice Problems for the Final

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions


Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

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

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination T09:00

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

University of the Western Cape Department of Computer Science

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1

DATA STRUCTURES AND ALGORITHMS

Algorithm Design (8) Graph Algorithms 1/2

Reference Sheet for CO142.2 Discrete Mathematics II

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

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

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

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

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

UCS-406 (Data Structure) Lab Assignment-1 (2 weeks)

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

Prelim 2 Solution. CS 2110, November 19, 2015, 5:30 PM Total. Sorting Invariants Max Score Grader

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

CSE 373: Practice Final

Contents. CS 124 Final Exam Practice Problem 5/6/17. 1 Format and Logistics 2

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

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

22 Elementary Graph Algorithms. There are two standard ways to represent a

Graph Algorithms (part 3 of CSC 282),

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

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

Problem Set 6 Solutions

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

Weighted Graphs and Greedy Algorithms

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

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

Lecture Summary CSC 263H. August 5, 2016

DESIGN AND ANALYSIS OF ALGORITHMS

CSE 100: GRAPH ALGORITHMS

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination

Dijkstra s Algorithm Last time we saw two methods to solve the all-pairs shortest path problem: Min-plus matrix powering in O(n 3 log n) time and the

CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008

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

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

CS:3330 (22c:31) Algorithms

Test points UTA Student ID #

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix

Second Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

Chapter 9 Graph Algorithms

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

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

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

Lecture Notes for Advanced Algorithms

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms

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

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

SUGGESTION : read all the questions and their values before you start.

Dijkstra s algorithm for shortest paths when no edges have negative weight.

Greedy Approach: Intro

Weighted Graph Algorithms Presented by Jason Yuan

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

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

Prelim 2, CS2110. SOLUTION

Transcription:

X Courses» Design and Analysis of Algorithms Week 1 Quiz 1) In the code fragment below, start and end are integer values and prime(x) is a function that returns true if x is a prime number and false otherwise. i := 0; j := 0; k := 0; for (m := start; m <= end; m := m+1){ k := k + m; if (prime(m)){ i := i + m; }else{ j := j + m; } } At the end of the loop: k < i+j k = i+j k > i+j Depends on start and end ) How many times is the comparison i <= n performed in the following program? int i = 10, n = 100; main(){ while (i <= n){ i = i+1; n = n-1; } } 45 46 47 90 3) An algorithm has two phases. The first phase, initialization, takes time O(n ). The second phase, which is the main computation, takes time O(n log n). What is the most accurate description of the complexity of the overall algorithm? O(n log n) O(n ) file:///users/madhavan/mirror/projects/nptel/algorithms-015/daa_allquizzes.html Page 1 of 9

O(n log n) O(n + log n) 4) Let f(n) = 560n 3 +3n+107 and g(n) = 3n 3 +5000n. Which of the following is true? f(n) is O(g(n)), but g(n) is not O(f(n)) g(n) is O(f(n)), but f(n) is not O(g(n)) f(n) is not O(g(n)) and g(n) is not O(f(n)) f(n) is O(g(n)) and g(n) is O(f(n)) 5) if T(n) = n n then T(n) = O(n) T(n) = O(n log n) T(n) = O(n ) None of the above Week Quiz 6) Assume that a CPU can process 10 8 operations per second. Suppose you have to sort an array with 10 6 elements. Which of the following is true? Insertion sort will always take more than.5 hours while merge sort will always take less than 1 second. Insertion sort will always take more than.5 hours while quicksort will always take less than 1 second Insertion sort could take more than.5 hours while merge sort will always take less than 1 second. Insertion sort could take more than.5 hours while quicksort will always take less than 1 second. 7) Suppose our aim is to sort an array in descending order. Which of the following statements is true? Input in descending order is worst case for both selection sort and insertion sort. Input in ascending order is worst case for both selection sort and insertion sort. Input in descending order is worst case for insertion sort but not for selection sort. Input in ascending order is worst case for selection sort but not for insertion sort. 8) Suppose we want to sort an array in descending order and we implement quicksort so that we always choose the last element in the array as the pivot element. Assume that the input is a permutation of {1,,, n}. Which of the following would be a worst case permutation of this input for this implementation of quicksort? {1,,, n} with all even numbers in random order followed by all odd numbers in descending order. {1,,..., n} in descending order. {1,,...,n} in some random order. {1,,..., n} with all odd numbers in ascending order followed by all even numbers in random order. 9) Which of the following statements is not true? For every fixed strategy to choose a pivot for quicksort, we can construct a worst case input that requires time O(n ). If we randomly choose a pivot element each time, quicksort will always terminate in time O(n log n). If we could find the median in time O(n), quicksort would have worst case complexity O(n log n). Quicksort and merge sort are both examples of divide and conquer algorithms. 10)We have a list of [(7,1),(3,5),(6,1),(6,5),(0,),(9,0)]. We sort these in ascending order by the second coordinate. Which of the folllowing corresponds to a stable sort of this input? file:///users/madhavan/mirror/projects/nptel/algorithms-015/daa_allquizzes.html Page of 9

[(9,0),(7,1),(6,1),(0,),(3,5),(6,5)] [(0,),(3,5),(6,1),(6,5),(7,1),(9,0)] [(9,0),(6,1),(7,1),(0,),(3,5),(6,5)] [(9,0),(7,1),(6,1),(0,),(6,5),(3,5)] Week 3 Quiz 11)An undirected graph G has 100 nodes and there is a path from every vertex to every other vertex in G. Suppose v1 and v are two vertices in G. Then, what can we say about the shortest path from v1 to v? The path has at most edges. The path has at most 50 edges. The path has at most 99 edges. None of the above. 1)An undirected graph G has 300 edges. The degree of a vertex v, deg(v), is the number of edges connected to v. Suppose V = {v1,v,...,v30}. What is the value of deg(v1)+ deg(v) + + deg(v30)? 300 600 900 None of these 13)Which of the following is not true of depth-first search (DFS) starting at a vertex v? DFS identifies all vertices reachable from v. Using an adjacency list instead of an adjacency matrix can improve the worst case complexity. DFS will identify the shortest paths from v in any graph without edge weights. DFS numbering can be used to identify cycles in the graph. 14)How many topological orderings does the following directed acyclic graph have? 6 1 18 4 15)Anjali has enrolled for a part-time Masters programme where she has to complete 8 courses, numbered 1,,..., 8. Each course takes a full semester to complete. She can take as many or as few courses as she wants in each semester. Some courses are prerequisites for other courses. If course A is a prerequisite for course B, she can take course B the semester after she finishes course A, or any time after that, but not before. Given the following information about prerequisites, compute the minimum number of semesters she needs to complete these courses Prerequisites for course 1: course,4,5,7 Prerequisites for course : course 3 Prerequisites for course 3: course 5,6 file:///users/madhavan/mirror/projects/nptel/algorithms-015/daa_allquizzes.html Page 3 of 9

Prerequisites for course 4: course 8 Prerequisites for course 5: course 8 Prerequisites for course 6: course 7,8 3 4 5 6 Week 4 Quiz 16)Consider the following fragment of code for a graph algorithm on an undirected graph. for each vertex i in V mark i as visited for each edge (j,i) pointing into i update weight(j,i) to weight(j,i) + k Which of the following is the most accurate description of the complexity of this fragment. (Recall that n is the number of vertices, m is the number of edges.) O(n) O(nm) O(n+m) O(m) 17)Consider the following strategy to solve the single source shortest path problem with edge weights from source s. 1. Replace each edge with weight w by w edges of weight 1 connected by new intermediate nodes. Run BFS(s) on the modified graph to find the shortest path to each of the original vertices in the graph. Which of the following statements is correct? This strategy will solve the problem correctly but is not as efficient as Dijkstra's algorithm. This strategy will solve the problem correctly and is as efficient as Dijkstra's algorithm.s st This strategy will not solve the problem correctly. This strategy will only work if the graph is acyclic. 18)Consider the following strategy to convert a graph with negative edge weights to one that does not have negative edge weights. Let the maximum magnitude negative edge weight in the graph be -k. Then, for each edge in the graph with weight w, update the weight to w+k+1. Consider the following claim: To solve the shortest path problem in the original graph, we can run Dijkstra's algorithm on the modified graph and subtract the added weights to get the original distances. Which of the following is not correct. The claim is not true in general. The claim is true for all graphs. The claim is true for connected acyclic graphs. The claim is not true in general for connected graphs with cycles. 19)Consider the following algorithm on a graph with edge weights. file:///users/madhavan/mirror/projects/nptel/algorithms-015/daa_allquizzes.html Page 4 of 9

Sort the edges as [e1,e,...,em] in decreasing order of cost. Start with the original graph. Consider each edge ej. If this edge is part of a cycle delete it. Which of the following is not true. After processing all m edges, the resulting graph is connected. What remains at the end is a minimum cost spanning tree. Exactly m-n+1 edges will be deleted. At most n-1 edges will be deleted. 0)Suppose we have a graph with negative edge weights. We take the largest magnitude negative edge weight -k and reset each edge weight w to w+k+1. Which of the following is true? Kruskal's algorithm will identify the same spanning tree on the new graph as on the old graph. Minimum cost spanning trees in the original graph will not correspond to minimum cost spanning trees in the new graph. Prim's algorithm will not work on the original graph but will work on the modified graph. There are more minimum cost spanning trees in the modified graph than in the original graph. Week 5 Quiz 1)Suppose we want to extend the union-find data structure to support the operation Reset(c), which takes as input the name of a component c and then breaks up c into singleton components, like MakeUnionFind(). For instance if c = 3 and c currently consists of {1,3,7}, then Reset(c) will produce three components called 1, 3 and 7 consisting of {1}, {3} and {7}, respectively. Which of the following is correct about the cost of adding Reset(c) to the array and pointer implementations of union-find discussed in the lecture? Array representation: O(n), Pointer representation: O(n) Array representation: O(size(c)), Pointer representation: O(n) Array representation: O(n), Pointer representation: O(size(c)) Array representation: O(size(c)), Pointer representation: O(size(c)) )Suppose we want to delete an arbitrary element from a max heap. (Assume we have auxiliary arrays NodeToHeap[] and HeapToNode[] required for the update() operation.) Consider the following strategies. Strategy 1: Remove the element from the array, compress the array and reheapify. Strategy : Update the value of this node to the current maximum value in the heap + 1, then delete_max. Strategy 1 takes time O(n log n) and Strategy takes time O(n) Strategy 1 takes time O(n) and Strategy takes time O(n log n) Strategy 1 takes time O(log n) and Strategy takes time O(n) Strategy 1 takes time O(n) and Strategy takes time O(log n) 3)Suppose we want to support the operations predecessor and successor in a heap. Given a value v in the heap, pred(v) tells us the next smaller value currently in the heap and succ(v) tells us the next larger value currently in the heap. In both min heaps and max heaps, both operations take time O(n). In both min heaps and max heaps, both operations take time O(log n). In a min heap, pred(v) takes time O(log n) and succ(v) takes O(n) whereas in a max heap pred(v) takes time O(n) and succ(v) takes O(log n). In a min heap, pred(v) takes time O(n) and succ(v) takes O(log n) whereas in a max heap pred(v) file:///users/madhavan/mirror/projects/nptel/algorithms-015/daa_allquizzes.html Page 5 of 9

takes time O(log n) and succ(v) takes O(n). 4)Suppose we do merge sort with a three-way split: divide the array into 3 equal parts, sort each part and do a 3 way merge. What would the worst-case complexity of this version be? O(n ) O(n log3n) O(n logn) O(n (logn) ) 5)In the closest pair of problem, we have assumed that no two have the same x or y coordinate. Which of the following steps would become more complicated to justify without this assumption. Constructing QY and RY from PY in time O(n) in the divide step. Constructing QX and RX from PX in time O(n) in the divide step. Constructing SY from QY and RY in time O(n) the combine step. Arguing that every d/ side square in the d-band around the separator can have at most one point. Week 6 Quiz 6)What is the complexity of inorder traversal for a binary search tree with n nodes? O(log n) whether the tree is balanced or unbalanced. O(log n) if the tree is balanced, O(n) otherwise. O(n) whether the tree is balanced or unbalanced. O(n) if the tree is balanced, O(n log n) otherwise. 7)Suppose we do not have a parent pointer in the nodes of a search tree, only left-child and right-child. Which of the following operations can be computed in time O(log n) for a balanced search tree? find, insert, delete, but not min, max, pred, succ find, insert, delete, min, max, but not pred, succ find, insert, delete, pred, succ but not min, max All of find, insert, delete, min, max, pred, succ 8)Consider the following algorithm to build a balanced search tree from a sorted sequence. Make the mid-point of the sequence the root of the tree Recursively construct balanced search trees from elements to the left and right of the midpoint and make these the left and right subtrees of the root. What is the complexity of this procedure where the sorted sequence is a sorted array? O(n) O(n log n) O(n ) Depends on the contents of the original sequence 9)Consider the following algorithm to build a balanced search tree from a sorted sequence. Make the mid-point of the sequence the root of the tree Recursively construct balanced search trees from elements to the left and right of the midpoint and make these the left and right subtrees of the root. file:///users/madhavan/mirror/projects/nptel/algorithms-015/daa_allquizzes.html Page 6 of 9

What is the complexity of this procedure where the sorted sequence is a sorted list? O(n) O(n log n) O(n ) Depends on the contents of the original sequence. 30)Which of the following is not a greedy algorithm? Dijkstra's algorithm for single source shortest paths Bellman-Ford algorithm for single source shortest paths Prim's algorithm for minimum cost spanning tree Kruskal's algorithm for minimum cost spanning tree Week 7 Quiz 31)We want to write down a recursive expression for Profit[i]. Profit[N] = 0 For 1 i < N, Profit[i] =?? max(profit[i+1], Profit[i+] + Price[i+1] - Price[i] - ) max(profit[i+] + Price[i+1] - Price[i] -, Profit[i+3] + Price[i+] - Price[i] -,... Profit[N] + Price[n-1] - Price[i] -, Price[n] - Price[i] - ) max(profit[i+1], Profit[i+] + Price[i+1] - Price[i] -, Profit[i+3] + Price[i+] - Price[i] -,... Profit[N] + Price[n-1] - Price[i] - ) max(profit[i+1], Profit[i+] + Price[i+1] - Price[i] -, Profit[i+3] + Price[i+] - Price[i] -,... Profit[N] + Price[n-1] - Price[i] -, Price[n] - Price[i] - ) 3)What is the size of the memo table for this problem? N N-1 N+1 N 33)What is a good order to compute the values of Profit[i] using dynamic programming? From Profit[1] to Profit[N] From Profit[N] to Profit[1] Either from Profit[1] to Profit[N] or from Profit[N] to Profit[1] None of these 34)How much time will dynamic programming take to compute Profit[1]? O(N) O(N log N) O(N ) O(N log N) 35)What is the value of Profit[1] in the example given in the problem statement? 6 7 8 file:///users/madhavan/mirror/projects/nptel/algorithms-015/daa_allquizzes.html Page 7 of 9

9 Week 8 Quiz 36)Which of the following is not a linear constraint? 8x 3y + 5 5x + 6xy 5 9x 7y + 8z 5y + 3x 33 37)When we model a graph problem using LP, mapping each path to a variable is not a good strategy because: Paths can be hard to compute. We have to be careful to avoid cycles. A graph has exponentially many paths. Edges may be directed. 38)Suppose we compute the maximum s-t flow F in a network. Then, which of the following is true of s-t cuts? From F, we can identify a minimum s-t cut in polynomial time. From F, we can identify all minimum s-t cuts in polynomial time. From F, we know the capacity of the minimum s-t cut, but identifying such a cut can take exponential time. F gives a lower bound for the capacity of the minimum s-t cut but not the exact capacity. 39)We have an exponential time algorithm for problem A, and problem A reduces in polynomial time to problem B. From this we can conclude that: B has an exponential time algorithm. B cannot have a polynomial time algorithm. A cannot have a polynomial time algorithm. None of the above. 40)Suppose SAT reduces to a problem C. To claim that C is NP-complete, we additionally need to show that: There is a checking algorithm for C. Every instance of C maps to an instance of SAT. Every instance of SAT maps to an instance of C. C does not have an efficient algorithm. file:///users/madhavan/mirror/projects/nptel/algorithms-015/daa_allquizzes.html Page 8 of 9

file:///users/madhavan/mirror/projects/nptel/algorithms-015/daa_allquizzes.html Page 9 of 9