CSci 231 Final Review

Similar documents
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)

Course Review for Finals. Cpt S 223 Fall 2008

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

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

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

CS521 \ Notes for the Final Exam

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

Lecture Summary CSC 263H. August 5, 2016

Solutions to Exam Data structures (X and NV)

Review of course COMP-251B winter 2010

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

CSci 231 Homework 7. Red Black Trees. CLRS Chapter 13 and 14

CSci 231 Homework 7. Red Black Trees. CLRS Chapter 13 and 14

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

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

Review for Midterm Exam

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

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

Introduction to Algorithms Third Edition

INDIAN STATISTICAL INSTITUTE

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?

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

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

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

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

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

( ) 1 B. 1. Suppose f x

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

ECE250: Algorithms and Data Structures Final Review Course

Data Structures and Algorithm Analysis in C++

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

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

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

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

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

AP Computer Science 4325

Heaps. Heapsort. [Reading: CLRS 6] Laura Toma, csci2000, Bowdoin College

CS Final - Review material

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms

Course Review. Cpt S 223 Fall 2009

Design and Analysis of Algorithms - - Assessment

Chapter 1 Introduction

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

Midterm solutions. n f 3 (n) = 3

Sorting Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

CS 303 Design and Analysis of Algorithms

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

COMP Data Structures

CS61BL. Lecture 5: Graphs Sorting

Data Structures and Algorithms Chapter 4

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

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

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

Data Structures and Algorithms Week 4

2. (a) Explain the concept of virtual functions in C++ with suitable examples. (b) Explain the concept of operator overloading in C++.

CISC 320 Midterm Exam

Design and Analysis of 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

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

5. For recursive algorithms, what do we need to define and solve to do the runtime analysis?

END-TERM EXAMINATION

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

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

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

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

Week 12: Minimum Spanning trees and Shortest Paths

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

Multiple-choice (35 pt.)

CSC 1700 Analysis of Algorithms: Minimum Spanning Tree

Computer Science 302 Spring 2007 Practice Final Examination: Part I

Jana Kosecka. Linear Time Sorting, Median, Order Statistics. Many slides here are based on E. Demaine, D. Luebke slides

Week 11: Minimum Spanning trees

Lecturers: Sanjam Garg and Prasad Raghavendra March 20, Midterm 2 Solutions

9. Which situation is true regarding a cascading cut that produces c trees for a Fibonacci heap?

DESIGN AND ANALYSIS OF ALGORITHMS

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

Lecture 5: Sorting Part A

CPSC 311 Lecture Notes. Sorting and Order Statistics (Chapters 6-9)

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

Design and Analysis of Algorithms

CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

DATA STRUCTURES AND ALGORITHMS

Computer Science Spring 2005 Final Examination, May 12, 2005

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

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

Computer Science 302 Spring 2017 (Practice for) Final Examination, May 10, 2017

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

Virtual University of Pakistan

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions:

Module 2: Classical Algorithm Design Techniques

Lecture: Analysis of Algorithms (CS )

Chapter 6 Heapsort 1

CS 310 Advanced Data Structures and Algorithms

CSE 100: GRAPH ALGORITHMS

Course Review. Cpt S 223 Fall 2010

Cpt S 223 Course Overview. Cpt S 223, Fall 2007 Copyright: Washington State University

Transcription:

CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks. 1. Asymptotic growth of functions (O, Ω, Θ) 2. Summations Basic summations Bounding summations 3. Recurrences Iteration Substitution (induction) 4. (Comparison-based) Sorting Insertion sort Mergesort Quicksort (Partition) Randomized quicksort Heapsort Comparison-based sorting lower bound 5. Linear-time sorting Counting sort Radix sort Bucket sort (remember stable sort, in-place sort) 6. Selection 7. (Abstract) Data structures Priority queue (FIND-MIN, DELETE-MIN, INSERT, DELETE, CHANGE-KEY) Max priority queue, Min priority queue Dictionary (INSERT, DELETE, SEARCH) Union-Find (MAKE-SET, FIND-SET, UNION-SET) 1

8. Data structure implementations Priority queue Heap heap property HEAPIFY, BUILDHEAP Dictionary Hash tables Direct addressing Hashing, hash function, collision with chaining (Universal hashing) Binary search trees (INSERT, DELETE, SEARCH, MIN, MAX, PRED, SUCC) binary search tree property tree walks Red-black trees red-black tree invariants (Skip lists) Union-Find Linked list (and pointers to head of list) weighted-union heuristic 9. Augmented search trees augment every node x with some additional information f(x); maintain f(x) under INSERT and DELETE in the same asymptotic bounds. Sufficient if f(x) can be computed using only f(left(x)) and f(right(x)). implement SELECT(i), RANK(x) by augmenting every node x with size(x) Interval tree 10. Dynamic programming optimal substructure, overlapping subproblems Matrix-chain multiplication, 0-1 Knapsack recursive formulation, running time without storing table running time with dynamic programming (storing table) 11. Greedy algorithms Correctness proof Activity selection, make change, pharmacist 2

12. Amortized analysis Accounting method conditions for charged costs to give an upper bound on total running time Potential method conditions for potential to give an upper bound on total running time Stack with MULTIPOP, binary counter, dynamic table Splay trees SPLAY operation, running time (analysis of SPLAY running time) 13. Graph algorithms Basic definitions, graph representation (adjacency list, adjacency matrix) Graph traversal: BFS G directed or undirected find connected components (G undirected), check bipartiteness (G undirected), compute shortest paths (G un-weighted, all edges have weight 1) Graph traversal: DFS G directed or undirected find cycles (back edges), topological sort (G directed, acyclic) Minimum spanning tree (MST) G connected, undirected, weighted Prim s MST algorithm Kruskal s MST algorithm Shortest paths: SSSP Dijkstra s SSSP algorithm G directed or undirected, weighted, non-negative weights SP on DAGs 3

Review Questions 1. Is it true that i=n i=0 (3/4)i = O(1)? 2. Give a formula for the arithmetic sum: 0 + 1 + 2 +... + n = i=n i=0 i = 3. Is it true that 7 lg n = O(n 3 )? 4. Is it true that 7 lg n = Ω(n 2 )? 5. Is it true that log n = Θ( log n)? 6. Is Mergesort stable? 7. Is Quicksort in place? 8. Is is true that the running time of Quicksort is Θ(n 2 )? 9. Is it true that the worst-case running time of Quicksort is Θ(n 2 )? 10. What is the running time of Mergesort when input is sorted in reverse order? 11. What is the running time of Heapsort when input is sorted? 12. Which of the following algorithms (as presented in class) is stable: Quicksort, Heapsort, Counting Sort? 13. Recall that a sorting algorithm is in place is it requires O(1) additional storage. Which of the following algorithms (as presented in class) is in place: Quicksort, Heapsort, Counting Sort? 14. You have a heap containing n keys. As a function of n, how long does it take to change a key? To delete a key? 15. Is it true that any sorting algorithm must take Ω(n log n) in the worst-case? 4

16. Counting Sort sorts n integers in time O(n + k). What is the assumption? 17. How fast can one find the minimum element in an array of n elements in the best case? In the worst case? 18. Is it true that SELECT (A, n), where A is an array of n elements, returns the largest element in the array? 19. Given a node x in a min heap, with children nodes l and r, what does the heap property tell us about x.key, l.key, r.key? 20. Is it true that building a heap of n elements takes O(n)? 21. Given a heap with n keys, is it true that you can search for a key in O(log n) time? 22. Given a binary search tree with n elements, its height can be as small as Ω( ) and as large as O( ). 23. Is it true that the height of a red-black tree with n elements is Θ(log n)? 24. How long does it take, in the worst case, to build a red-black tree of n elements? 25. You have a binary search tree T with n elements. Is it true that the predecessor of an element in T can be found in O(1) time? 26. Is it true that some dynamic programming problems can be solved faster using greedy algorithms? 27. Describe how you can INSERT an element in a splay tree using the SPLAY operation. 28. Is it true that a splay tree is a binary search tree? 29. Is it true that the height of a splay tree of n nodes is O(log n)? 5

30. You have a splay tree T of n elements. Is it true that INSERTing, DELETing, or SEARCHing a node in T takes O(log n) in the worst case? 31. You have a splay tree T of n elements. Is it true that a sequence of n INSERT, DELETE and SEARCH operations take O(n log n) time in the worst case? 32. As a function of V, what is the minimum number of edges in a connected undirected graph with V vertices? 33. How many edges are in a complete graph with V vertices? 34. You have an undirected, connected, weighted graph G and a source vertex s. Is it true that BFS computes shortest paths from s to every other vertex? 35. Is it true that Prim s and Kruskal s algorithms are greedy? 36. Is it true that Dijkstra s SSSP algorithm works only on graphs with non-negative edge weights? 37. Let p = u v 1 v 2... v k v be the shortest path from u to v in a graph G. Let v i and v j be two vertices on p such that 1 i < j k. Is it true that the subpath v i v i+1... v j in p is the shortest path in G from v i to v j? 38. Can a shortest path contain cycles? 39. Is it true that running Dijkstra s algorithm on a graph G = (V, E) takes O( E log V )? 40. You have a complete graph with V vertices. How long does it take to run Dijkstra s algorithm on this graph? 41. Is it true that Kruskal s algorithm uses a Union-Find data structure? 42. How long does it take to run Prim s algorithm on a graph G = (V, E)? 43. Is it true that Prim s algorithm only works on undirected graphs? 6

Review problems 1. (Duke Midterm 2002) Consider the following recurrence T (n) = { T ( n) + log log n if n > 4 1 otherwise (a) Using the iteration method find an asymptotic tight bound for T (n). (b) Using the substitution method prove that the recurrence has solution T (n) = O((log log n) 2 ). 2. Rank the following functions in increasing order of asymptotic growth. 500n 3, 17n + (2/n 2 ), 7n log log n, 4 log 3 n, 20 log(n 2 ), 2 3 log n, 2 n 3. You are given an array A[1..n] of real numbers, some positive, some negative. Design an O(n log n) algorithm which determines whether A contains two elements A[i] and A[j] such that A[i] = A[j]. (If A contains the element 0, then the answer is always YES.) 7

4. Consider a binary search tree in which each node v contains a key as well as an additional value called addend. The addend of node v is implicitly added to all keys in the subtree rooted at v (including v). Let (key, addend) denote the contents of any node v. For example, the following tree contains the elements {5, 6, 7}: (4,2) (3,0) (4,1) (a) Which elements does the following tree contain? (6,4) (0,2) (15, -3) (-1,0) (2,0) (4,6) (10,7) (0,1) (b) Let h be the height of a tree as defined above. Describe how to perform the following operations in O(h) time: (7,0) FIND(x, T): return YES if element x is stored in tree T INSERT(x, T): inserts element x in tree T PUSH(x, k, T): add k to all elements x (c) Describe how it can be ensured that h = O(log n) during the above operations. (Hint: show how to perform rotations.) 8

5. (Duke Final 2002) Let x = x 1 x 2... x n and y = y 1 y 2... y m and z = z 1 z 2... z n+m be three strings of length n, m, and n + m, respectively. We say that z is a merge of x and y if x and y can be found as two disjoint subsequences in z. Example: algodatastrucri tuthresms is a merge of algorithms and datastructures. For 0 i n and 0 j m, Merge(i, j) is true if z = z 1 z 2... z i+j is a merge of x = x 1 x 2... x i and y = y 1 y 2... y j (x = x 1 x 2... x i is the empty string if i = 0. Similarly for y and z.) We can compute M erge(i, j) using the following formula X ij Y ij if i, j 1 X Merge(i, j) = ij if i 1, j = 0 Y ij if i = 0, j 1 true if i = 0, j = 0 where X ij is defined as (z i+j = x i ) Merge(i 1, j) and Y ij is defined as (z i+j = y j ) Merge(i, j 1) This can be implemented as follows Merge(i,j) IF i=0 AND j=0 THEN RETURN True IF i>0 THEN X = (z[i+j]==x[i] AND Merge(i-1,j)) IF j>0 THEN Y = (z[i+j]==y[j] AND Merge(i,j-1)) IF i>0 and j>0 THEN RETURN X OR Y IF j=0 THEN RETURN X IF i=0 THEN RETURN Y END a) Show that the running time of Merge(n, m) is exponential in n and m. b) Describe an O(nm) algorithm for solving the problem. Remember to argue for both running time and correctness. If Merge(n, m) = True we are interested in knowing which subsequence of z corresponds to x and which corresponds to y in a possible merge. We can characterize such a merge by the indexes of z where a new subsequence starts. Example: The merge of algorithms and datastructures into algodatastrucri tuthresms is described by the indices 1, 5, 14, 16, 18, 20, 23. c) Describe how your O(nm) algorithm can be extended such that if Merge(n, m) =True, the algorithm also returns the list of indexes defining a possible merge. 9

6. (Duke Final 2002) Consider a meta-stack consisting of an infinite series of stacks S 0, S 1, S 2,... where the ith stack S i can hold at most 2 i elements. An element x is Pushed onto a metastack by Pushing x onto S 0. If S 0 is full, its elements are Pushed onto stack S 1. In general, if S i runs full all its elements are Pushed onto stack S i+1. 0 1 2 3 i 2 2 2 2 2 a) What is the worst-case running time of a meta-stack Push operation in a sequence of n such operations? b) Argue that the amortized cost of a meta-stack Push operation in a sequence of n such operations is O(log n). 10

7. (Duke Final 2000) Consider a pole-graph which is an undirected graph with positive edge weights, consisting of two poles connected through a layer of nodes as follows: Let n be the number of vertices in a pole-graph and assume that the graph is given in normal edge-list representation. (a) How long would it take Dijkstra s algorithm to find the single-source-shortest-paths from one of the poles in a pole-graph to all other nodes? (b) Describe and analyze a more efficient algorithm for solving the single-source-shortestpaths problem on a pole-graph. Remember to prove that the algorithm is correct. 11