Analysis of Algorithms

Similar documents
Midterm solutions. n f 3 (n) = 3

Basic Data Structures (Version 7) Name:

Algorithms. AVL Tree

Outline. Definition. 2 Height-Balance. 3 Searches. 4 Rotations. 5 Insertion. 6 Deletions. 7 Reference. 1 Every node is either red or black.

CSE 548: Analysis of Algorithms. Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps )

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

Analysis of Algorithms

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

Course Review for Finals. Cpt S 223 Fall 2008

Properties of red-black trees

( ) n 5. Test 1 - Closed Book

Lecture 6: Analysis of Algorithms (CS )

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

Solutions. Suppose we insert all elements of U into the table, and let n(b) be the number of elements of U that hash to bucket b. Then.

Test 1 - Closed Book Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

COMP Analysis of Algorithms & Data Structures

CSE 332, Spring 2010, Midterm Examination 30 April 2010

Search Trees. Undirected graph Directed graph Tree Binary search tree

COMP Analysis of Algorithms & Data Structures

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

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

CS521 \ Notes for the Final Exam

Course Review. Cpt S 223 Fall 2009

Lecture: Analysis of Algorithms (CS )

Recall: Properties of B-Trees

We will show that the height of a RB tree on n vertices is approximately 2*log n. In class I presented a simple structural proof of this claim:

1. To reduce the probability of having any collisions to < 0.5 when hashing n keys, the table should have at least this number of elements.

COSC160: Data Structures Balanced Trees. Jeremy Bolton, PhD Assistant Teaching Professor

Advanced Set Representation Methods

Lecture Summary CSC 263H. August 5, 2016

Solutions to relevant spring 2000 exam problems

V Advanced Data Structures

CSE 5311 Notes 4a: Priority Queues

Lower Bound on Comparison-based Sorting

Transform & Conquer. Presorting

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues.

looking ahead to see the optimum

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

Algorithm Theory, Winter Term 2015/16 Problem Set 5 - Sample Solution

Exercise 1 : B-Trees [ =17pts]

l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are:

Chapter 6 Heap and Its Application

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

l So unlike the search trees, there are neither arbitrary find operations nor arbitrary delete operations possible.

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

Chapter 4: Trees. 4.2 For node B :

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

Chapter 5 Data Structures Algorithm Theory WS 2016/17 Fabian Kuhn

Algorithms and Theory of Computation. Lecture 7: Priority Queue

Course Review. Cpt S 223 Fall 2010

CSCE750 Analysis of Algorithms Fall 2018 Fibonacci Heaps

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

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

CS711008Z Algorithm Design and Analysis

CISC 621 Algorithms, Midterm exam March 24, 2016

CS711008Z Algorithm Design and Analysis

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

COMP Analysis of Algorithms & Data Structures

Final Examination CSE 100 UCSD (Practice)

CISC 235: Topic 4. Balanced Binary Search Trees

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

Thus, it is reasonable to compare binary search trees and binary heaps as is shown in Table 1.

Announcements. Midterm exam 2, Thursday, May 18. Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps. Break around 11:45am

CSCI2100B Data Structures Trees

Balanced Search Trees. CS 3110 Fall 2010

CMSC351 - Fall 2014, Homework #2

Multi-Way Search Trees

CISC 320 Midterm Exam

Trees. Eric McCreath

Red-Black Trees. Based on materials by Dennis Frey, Yun Peng, Jian Chen, and Daniel Hood

Search Trees. COMPSCI 355 Fall 2016

A red-black tree is a balanced binary search tree with the following properties:

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CS350: Data Structures Red-Black Trees

Round 3: Trees. Tommi Junttila. Aalto University School of Science Department of Computer Science. CS-A1140 Data Structures and Algorithms Autumn 2017

COMP 251 Winter 2017 Online quizzes with answers

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

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

Hierarchical data structures. Announcements. Motivation for trees. Tree overview

V Advanced Data Structures

CPS 231 Exam 2 SOLUTIONS

Algorithms. Deleting from Red-Black Trees B-Trees

CS 380 ALGORITHM DESIGN AND ANALYSIS

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

Solution to CSE 250 Final Exam

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

Trees. (Trees) Data Structures and Programming Spring / 28

Section 05: Solutions

Binary Heaps in Dynamic Arrays

Balanced Trees Part Two

Introduction. for large input, even access time may be prohibitive we need data structures that exhibit times closer to O(log N) binary search tree

We assume uniform hashing (UH):

Binary search trees. Binary search trees are data structures based on binary trees that support operations on dynamic sets.

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

Here is a recursive algorithm that solves this problem, given a pointer to the root of T : MaxWtSubtree [r]

FINAL EXAM SOLUTIONS

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

An AVL tree with N nodes is an excellent data. The Big-Oh analysis shows that most operations finish within O(log N) time

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)

Trees (Part 1, Theoretical) CSE 2320 Algorithms and Data Structures University of Texas at Arlington

Transcription:

Analysis of Algorithms Concept Exam Code: 16 All questions are weighted equally. Assume worst case behavior and sufficiently large input sizes unless otherwise specified. Strong induction Consider this statement: n ( 1) i i = ( 1) n i=1 n (n + 1), for n 1. Consider a proof, by strong induction and using Lusthian style, to show that the above statement is true. 1. What would we need to prove for the base case, assuming we wish to have only one base case? (A) ( 1) 0 0 = ( 1) 0 1 (1+1) (B) ( 1) 0 0 = 0 (C) 0 (0+1) = 0 (D) 1 (1+1) = 1 (E) ( 1) 1 1 = 1 1 (F) ( 1) i i = ( 1) 1 i=0 (G) ( 1) 1 1 = ( 1) 1 1 (1+1) 1 (1 + 1). What would the inductive hypothesis be, assuming b is the largest base case value? (A) Assume true for b n (B) Assume true for b (C) Assume true for b < k < n (D) Assume true for b < n (E) Assume true for b k < n (F) Assume true for n (G) Assume true for b k n (H) Assume true for b < k n. If the first line of the inductive case sets up the inductive step, then the right-hand side of the second line (which shows the inductive step that was taken) should be: n (A) = ( 1) n+1 (n + 1) + i n+1 (F) = ( 1) 1 1 + i i=1 (B) = ( 1) n+1 (n + 1) + n (n+1) (C) = n (n+1) + (n 1) ((n 1)+1) (D) = ( 1) n n + ( 1) n 1 (n 1) ((n 1)+1) n (E) = ( 1) 1 1 + i i= i= n 1 (G) = ( 1) n n + i=1 i (H) = (n+1) ((n+1)+1) + n (n+1) Master recurrence theorem. In terms of the master recurrence theorem as described in Cormen, et al., where does the equation T (n) = 5T ( n 5 ) + n log n fall? (A) case (B) case 1 (C) the equation is not in the correct form (D) case (E) between case and case (F) between case 1 and case 5. In terms of the master recurrence theorem as described in Cormen, et al., where does the equation T (n) = 5T ( n ) + n log n fall? The log (base 5) of is ~ 0.68. The log (base ) of 5 is ~ 1.65. (A) between case 1 and case (B) the equation is not in the correct form (C) case (D) case (E) case 1 (F) between case and case

6. In terms of the master recurrence theorem as described in Cormen, et al., where does the equation T (n) = 9T ( n ) + n log n fall? (A) case (B) between case and case (C) case 1 (D) between case 1 and case (E) the equation is not in the correct form (F) case 7. In terms of the master recurrence theorem as described in Cormen, et al., where does the equation T (n) = T ( n ) + 1 fall? (A) case 1 (B) between case and case (C) between case 1 and case (D) case (E) case (F) the equation is not in the correct form 8. Consider using the master recurrence theorem to solve the equation T (n) = T ( n ) + n. What is the smallest listed value of ϵ that can be used in the solution? The log (base ) of is ~ 1.585. The log (base ) of is ~ 0.61. (A) the master theorem cannot be used (B) ϵ is not used in the solution (C) 0. (D) 0 (E) no legal value is listed (F) 0.6 9. Consider using the master recurrence theorem and the regularity condition for case to solve the equation T (n) = T ( n ) + n. What is the smallest legal value of the constant c listed for the solution? Useful numbers: log 0.79 log 1.6 6 ~ 0.069 ~ 1. 0.75 9 ~ 0. 16 0.1875 7 ~ 0.18 (A) no legal value is listed (B) 0.10 (C) 0.15 (D) 0.075 (E) case does not apply Self-balancing trees References to binary search trees, red-black trees, and AVL trees refer to typical implementations, unless otherwise specified. For red-black trees, null pointers are not considered nodes but do have a color (black). In a red-black tree, all nodes being inserted start out red. The length of a path in a tree is the minimum number of steps from the starting vertex to the ending vertex. The depth (or height) of a tree is the length of the path from the root to the furthest leaf. 10. Consider a right-rotation of a node n upwards in a BST. The former left child of n, assuming it exists: (A) remains the left child of n (B) becomes the niece or nephew of n (C) becomes a child of the former parent of n (D) becomes the right child of n (F) becomes a sibling of n 11. Suppose you allowed, at most, two red nodes in a row on any path from an interior node to a leaf in a red-black tree (as opposed to a standard red-black tree where you can have, at most, one red node in a row). Suppose further that all leaves in the tree are black. Of the answers listed, what is the tightest upper bound on the ratio of the longest path from the root to a leaf and the shortest path from the root to a leaf. Also, will searches and insertions would still take O(log n) time? (A), yes (B), yes (C), no (D), yes (E), no (F) infinity, no (G) none of the other answers are correct (H), no

1. The number of node recolorings that occur after an insertion into a red-black tree is: (A) Θ(1) (B) Θ(n) (C) Θ(log n) (D) Θ(n log n) 1. Consider a red-black tree with a perfect binary tree shape, that has an odd-numbered depth (e.g. depth is 11), and that has a maximum number of red nodes. Which of the following is a constraint on this tree, where B is the number of black nodes and R is the number of red nodes? (A) B = R (B) B = R (C) B = R (D) none of the other answers are correct (E) B + 1 = R (F) B = R + 1 (G) B = R + 1 (H) B = R + 1 1. What is the minimum number of operations that can yield an all-black red-black tree that has more than one node? Also, what are those operations (listed in order from first to last) (A) (insert, insert, insert) (B) (insert, insert) (C) (insert, insert, insert, insert) (insert, insert, insert, insert, delete) (E) 6 (insert, insert, insert, insert, delete, delete) (F) 6 (insert, insert, insert, delete, insert, delete) (G) 5 (insert, insert, insert, delete, delete) (H) (insert, insert, insert, delete) 15. Inserting the integers 1,,, 5, and into an empty red-black tree, in the order given, yields how many recolorings, single rotations, and double rotations, respectively? Don t forget to color the root black, if need be. (A) 8, 1, 1 (B) 7, 1, 1 (D) 9,, 0 (E) 9, 0, (F) 9, 1, 1 (G) 8,, 0 (H) 8, 0, 16. The worst case number of rotations that occur after an insertion into an AVL tree is: (A) Θ(1) (B) Θ(log log n) (C) Θ(n) (D) Θ(log n) 17. Consider an AVL tree having a root whose left side has nodes. What is the most number of nodes that can appear on the right side? (A) 15 (B) 16 (C) 11 (D) 8 (E) 7 (F) 1 (G) none of the other answers are correct 18. Consider a node n with two children in an AVL tree. If one of the children is a leaf, what is the most number of descendants the parent of n can have? (A) 15 (B) 1 (C) 0 (F)

19. Consider inserting the following numbers, in the order given, into an empty AVL tree: 1 7 8 5 9 6 Which insertion causes the first double rotation? (A) (C) (D) 7 (E) there are no double rotations (F) 6 (G) 1 Binomial heaps Assume min-heaps unless otherwise directed. When inserting into a binomial heap, the node to be inserted node is placed at the far left of the root list. During the extractmin operation, child lists are placed at the far right of the root list (in increasing degree order). Consolidation moves along the root list from left to right. After consolidation, the root list is ordered in increasing degree order. 0. Consider inserting the following values, in the order given: 9 8 5 6 1 7 0 into an empty binomial heap. After deleting the value 5, the value 6 is found in a subheap whose root has which value? (B) 1 (C) (D) none of the other answers are correct (E) (F) 7 (G) 6 (H) 1. Consider inserting the consecutive integers from 0 to 1, inclusive and in increasing order, into an empty binomial heap. After an extractmin operation, followed by deleting the value 5, the value 8 can be found in the subheap whose root has value: (C) (D) 6 (E) 1 (F) 0 (G) (H). Consider inserting the consecutive integers from 0 to 16, inclusive and in the order given, into an empty binomial heap. After four extractmins, how many subheaps are in the root list? (A) (B) 1 (C) 6 (F) 7 (G) (H). Consider inserting the consecutive integers from 1 to 1, inclusive and not necessarily in order, into an empty binomial heap. After all the insertions, what is the largest possible root value of the largest heap in the root list? (A) 6 (C) 8 (D) 7 (E) 9 (F) 1 (G) 11 (H) 10

. Consider inserting the consecutive integers from 1 to 1, inclusive and not necessarily in order, into an empty binomial heap. After all the insertions, what is the second largest possible root value of the largest heap in the root list? (A) 6 (B) 11 (C) 10 (D) 7 (E) 9 (F) none of the other answers are correct (G) 1 (H) 8 Fibonacci heaps Assume min-heaps unless otherwise directed. When inserting into a Fibonacci heap (including cut nodes), the node to be inserted node is placed at the far left of the root list. During the extractmin operation, child lists are placed at the far right of the root list (in increasing degree order). Consolidation moves along the root list from left to right. After consolidation, the root list is ordered in increasing degree order. 5. After seven consecutive inserts into an empty Fibonacci heap, how many subheaps are in the root list? (A) (B) 8 (C) (E) (F) 1 (G) 6 (H) 7 6. Consider a series of consecutive insertions into an initially empty Fibonacci heap. What is the worst-case and average cost, respectively, of a single insertion? (A) none of the other answers are correct (B) log and log (C) constant and log linear (D) constant and constant (E) constant and linear (F) log and log linear (G) constant and log (H) log and linear 7. Consider inserting the consecutive integers from 0 to 1, inclusive and in increasing order, into an empty Fibonacci heap. After an extractmin operation, followed by an 8-to-0 decreasekey operation, followed by another extractmin, the value 7 can be found in the subheap whose root has value: (A) none of the other answers are correct (B) (C) 7 (D) (E) 6 (F) 5 (G) 1 (H) 8. For a Fibonacci heap, what is the smallest possible number of nodes in a subheap of degree 6? Hint: look at smaller degreed subheaps and extrapolate. (A) 0 (C) 8 (D) 6 (E) 7 (F) 6 (G) 1 (H) 1 When cutting a node out of a Fibonacci subheap, the degree of the parent is decremented. In addition, the parent of the node (unless it is a root) is either marked, if it hasn t been previously marked, or cut, if it has. Root nodes are never marked. 9. What is the most number of nodes that can be cut in a single cascade when a leaf is cut in a subheap that starts out with degree 5? Include the leaf in your count. (B) 8 (C) (D) 1 (E) 7 (F) (G) 6 (H) 5

Disjoint sets The following questions assume a tree implementation of a disjoint set. Assume each value has a pointer to its parent with the root of the tree serving as the representative of the set. When performing a union between two trees of equal rank, assume the smaller valued root becomes the parent of the larger valued root. Assume path compression and union-by-rank unless specified otherwise. 0. The find-set operation (with path compression but no union by rank) takes a worst case time of: (A) θ(n ) (B) θ(log n) (D) θ(1) (E) θ(n) (F) θ(n log n) 1. Assuming n values, no path compression, and no union by rank, the total work of a series of m disjoint set operations is: (A) θ(n log m) (B) θ(m log n) (D) θ(m) (E) θ(nm) (F) θ(log n) (G) θ(1) (H) θ(n). Theoretically speaking, with path compression and union by rank, the total work of a series of m disjoint set operations is: (A) logarithmic (B) quadratic (C) log linear (D) linear (F) constant. Suppose one performs a series of n make-set operations followed by enough union operations so that a single set remains. What is the fewest number of union operations to achieve this result? Assume n is a power of two. (A) n + 1 (B) log n (C) n 1 (D) n (E) n (F) none of the other answers are correct For the following set of questions, consider the following sequence of operations: for each i in 0..10 do make-set(i) union(1,); union(,8); union(0,); union(,); union(5,6); union(,7) union(5,7); union(9,7); find-set(1); find-set(); union(8,6);. Immediately after the union(5,7) operation, how many nodes in the tree rooted by 1 s representative are more than one step away from the root? (A) none of the other answers are correct (B) (C) 5 (D) 1 (E) (F) 5. Immediately before the first findset operation, how many children does s representative have? (B) 1 (C) (D) none of the other answers are correct (E) (F) 6

6. After all operations, how many nodes do not have a root as a parent? (B) (C) (D) (E) 0 (F) 1 Graphs Assume graphs are simple, undirected, and connected unless otherwise specified. The length of a walk, tour, path, or cycle is the number of edges on that walk, tour, path, or cycle. 7. The degree of a vertex is count of edges that connect it to other vertices (i.e. the incident edges). The min-degree of a graph is the degree of the vertex with the least number of incident edges. Consider a graph with 6 vertices and 11 edges. What is the smallest min-degree possible in a graph with those vertex and edge counts? (A) (B) (C) 6 (E) (F) 1 8. The longest possible walk, tour, path, and cycle, respectively, in a graph with V vertices and E edges is: (A) infinite, infinite, infinite, infinite (B) V+E, E, V, V+1 (D) infinite, E+V, V-, V-1 (E) V+E, E, V, V+1 (F) V+E, E, V-, V-1 (G) infinite, E, V, V+1 (H) infinite, E, V-1, V 9. What is the primary characteristic of a complete graph? Choose the most specific answer. (A) each vertex has two edges or no edges (B) there exists a path between every pair of vertices (C) all vertices have a degree greater than some threshold (D) there exists an edge between every pair of vertices 0. T or F: If a graph has a cycle, it must have a Hamiltonian cycle. 7