Analysis of Algorithms

Size: px
Start display at page:

Download "Analysis of Algorithms"

Transcription

1 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) 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) 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 ~ The log (base ) of 5 is ~ (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

2 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 ~ The log (base ) of is ~ (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) 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 ~ ~ ~ ~ 0.18 (A) no legal value is listed (B) 0.10 (C) 0.15 (D) (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

3 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 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)

4 19. Consider inserting the following numbers, in the order given, into an empty AVL tree: 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: 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

5 . 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

6 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 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

7 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

Midterm solutions. n f 3 (n) = 3

Midterm solutions. n f 3 (n) = 3 Introduction to Computer Science 1, SE361 DGIST April 20, 2016 Professors Min-Soo Kim and Taesup Moon Midterm solutions Midterm solutions The midterm is a 1.5 hour exam (4:30pm 6:00pm). This is a closed

More information

Basic Data Structures (Version 7) Name:

Basic Data Structures (Version 7) Name: Prerequisite Concepts for Analysis of Algorithms Basic Data Structures (Version 7) Name: Email: Concept: mathematics notation 1. log 2 n is: Code: 21481 (A) o(log 10 n) (B) ω(log 10 n) (C) Θ(log 10 n)

More information

Algorithms. AVL Tree

Algorithms. AVL Tree Algorithms AVL Tree Balanced binary tree The disadvantage of a binary search tree is that its height can be as large as N-1 This means that the time needed to perform insertion and deletion and many other

More information

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

Outline. Definition. 2 Height-Balance. 3 Searches. 4 Rotations. 5 Insertion. 6 Deletions. 7 Reference. 1 Every node is either red or black. Outline 1 Definition Computer Science 331 Red-Black rees Mike Jacobson Department of Computer Science University of Calgary Lectures #20-22 2 Height-Balance 3 Searches 4 Rotations 5 s: Main Case 6 Partial

More information

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

CSE 548: Analysis of Algorithms. Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps ) CSE 548: Analysis of Algorithms Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Fall 2012 Fibonacci Heaps ( Fredman & Tarjan,

More information

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

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 1. O(logn) 2. O(n) 3. O(nlogn) 4. O(n 2 ) 5. O(2 n ) 2. [1 pt] What is the solution

More information

Analysis of Algorithms

Analysis of Algorithms Analysis of Algorithms Trees-I Prof. Muhammad Saeed Tree Representation.. Analysis Of Algorithms 2 .. Tree Representation Analysis Of Algorithms 3 Nomenclature Nodes (13) Size (13) Degree of a node Depth

More information

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

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I MCA 312: Design and Analysis of Algorithms [Part I : Medium Answer Type Questions] UNIT I 1) What is an Algorithm? What is the need to study Algorithms? 2) Define: a) Time Efficiency b) Space Efficiency

More information

Course Review for Finals. Cpt S 223 Fall 2008

Course Review for Finals. Cpt S 223 Fall 2008 Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,

More information

Properties of red-black trees

Properties of red-black trees Red-Black Trees Introduction We have seen that a binary search tree is a useful tool. I.e., if its height is h, then we can implement any basic operation on it in O(h) units of time. The problem: given

More information

( ) n 5. Test 1 - Closed Book

( ) n 5. Test 1 - Closed Book Name Test 1 - Closed Book Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each 1. During which operation on a leftist heap may subtree swaps be needed? A. DECREASE-KEY

More information

Lecture 6: Analysis of Algorithms (CS )

Lecture 6: Analysis of Algorithms (CS ) Lecture 6: Analysis of Algorithms (CS583-002) Amarda Shehu October 08, 2014 1 Outline of Today s Class 2 Traversals Querying Insertion and Deletion Sorting with BSTs 3 Red-black Trees Height of a Red-black

More information

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

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 2. O(n) 2. [1 pt] What is the solution to the recurrence T(n) = T(n/2) + n, T(1)

More information

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.

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. Assignment 3 1. Exercise [11.2-3 on p. 229] Modify hashing by chaining (i.e., bucketvector with BucketType = List) so that BucketType = OrderedList. How is the runtime of search, insert, and remove affected?

More information

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

Test 1 - Closed Book Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 3 points each CSE 5311 Test 1 - Closed Book Summer 2009 Name Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 3 points each 1. Which of the following statements is true?

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 9 - Jan. 22, 2018 CLRS 12.2, 12.3, 13.2, read problem 13-3 University of Manitoba COMP 3170 - Analysis of Algorithms & Data Structures

More information

CSE 332, Spring 2010, Midterm Examination 30 April 2010

CSE 332, Spring 2010, Midterm Examination 30 April 2010 CSE 332, Spring 2010, Midterm Examination 30 April 2010 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note. You may use a calculator for basic arithmetic only.

More information

Search Trees. Undirected graph Directed graph Tree Binary search tree

Search Trees. Undirected graph Directed graph Tree Binary search tree Search Trees Undirected graph Directed graph Tree Binary search tree 1 Binary Search Tree Binary search key property: Let x be a node in a binary search tree. If y is a node in the left subtree of x, then

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 9 - Jan. 22, 2018 CLRS 12.2, 12.3, 13.2, read problem 13-3 University of Manitoba 1 / 12 Binary Search Trees (review) Structure

More information

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

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree. The Lecture Contains: Index structure Binary search tree (BST) B-tree B+-tree Order file:///c /Documents%20and%20Settings/iitkrana1/My%20Documents/Google%20Talk%20Received%20Files/ist_data/lecture13/13_1.htm[6/14/2012

More information

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

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions: Direct Addressing - key is index into array => O(1) lookup Hash table: -hash function maps key to index in table -if universe of keys > # table entries then hash functions collision are guaranteed => need

More information

CS521 \ Notes for the Final Exam

CS521 \ Notes for the Final Exam CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )

More information

Course Review. Cpt S 223 Fall 2009

Course Review. Cpt S 223 Fall 2009 Course Review Cpt S 223 Fall 2009 1 Final Exam When: Tuesday (12/15) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program

More information

Lecture: Analysis of Algorithms (CS )

Lecture: Analysis of Algorithms (CS ) Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 1 Binary Search Trees Traversals, Querying, Insertion, and Deletion Sorting with BSTs 2 Example: Red-black Trees Height of a Red-black

More information

Recall: Properties of B-Trees

Recall: Properties of B-Trees CSE 326 Lecture 10: B-Trees and Heaps It s lunch time what s cookin? B-Trees Insert/Delete Examples and Run Time Analysis Summary of Search Trees Introduction to Heaps and Priority Queues Covered in Chapters

More information

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:

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: We have seen that the insert operation on a RB takes an amount of time proportional to the number of the levels of the tree (since the additional operations required to do any rebalancing require constant

More information

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.

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. CSE 5311 Test 1 - Closed Book Spring 004 Name Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 4 points each 1. To reduce the probability of having any collisions to < 0.5 when

More information

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

COSC160: Data Structures Balanced Trees. Jeremy Bolton, PhD Assistant Teaching Professor COSC160: Data Structures Balanced Trees Jeremy Bolton, PhD Assistant Teaching Professor Outline I. Balanced Trees I. AVL Trees I. Balance Constraint II. Examples III. Searching IV. Insertions V. Removals

More information

Advanced Set Representation Methods

Advanced Set Representation Methods Advanced Set Representation Methods AVL trees. 2-3(-4) Trees. Union-Find Set ADT DSA - lecture 4 - T.U.Cluj-Napoca - M. Joldos 1 Advanced Set Representation. AVL Trees Problem with BSTs: worst case operation

More information

Lecture Summary CSC 263H. August 5, 2016

Lecture Summary CSC 263H. August 5, 2016 Lecture Summary CSC 263H August 5, 2016 This document is a very brief overview of what we did in each lecture, it is by no means a replacement for attending lecture or doing the readings. 1. Week 1 2.

More information

Solutions to relevant spring 2000 exam problems

Solutions to relevant spring 2000 exam problems Problem 2, exam Here s Prim s algorithm, modified slightly to use C syntax. MSTPrim (G, w, r): Q = V[G]; for (each u Q) { key[u] = ; key[r] = 0; π[r] = 0; while (Q not empty) { u = ExtractMin (Q); for

More information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

More information

CSE 5311 Notes 4a: Priority Queues

CSE 5311 Notes 4a: Priority Queues Chart on p., CLRS (binary, Fibonacci heaps) CSE Notes a: Priority Queues (Last updated 9// : AM) MAKE-HEAP INSERT MINIMUM EXTRACT-MIN UNION (MELD/MERGE) DECREASE-KEY DELETE Applications - sorting (?),

More information

Lower Bound on Comparison-based Sorting

Lower Bound on Comparison-based Sorting Lower Bound on Comparison-based Sorting Different sorting algorithms may have different time complexity, how to know whether the running time of an algorithm is best possible? We know of several sorting

More information

Transform & Conquer. Presorting

Transform & Conquer. Presorting Transform & Conquer Definition Transform & Conquer is a general algorithm design technique which works in two stages. STAGE : (Transformation stage): The problem s instance is modified, more amenable to

More information

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

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues. Outline Computer Science 33 Heap Sort Mike Jacobson Department of Computer Science University of Calgary Lectures #5- Definition Representation 3 5 References Mike Jacobson (University of Calgary) Computer

More information

looking ahead to see the optimum

looking ahead to see the optimum ! Make choice based on immediate rewards rather than looking ahead to see the optimum! In many cases this is effective as the look ahead variation can require exponential time as the number of possible

More information

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

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn) CSE 0 Name Test Fall 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to find the maximum of the n elements of an integer array is in: A.

More information

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

Algorithm Theory, Winter Term 2015/16 Problem Set 5 - Sample Solution Albert-Ludwigs-Universität, Inst. für Informatik Prof. Dr. Fabian Kuhn M. Ahmadi, O. Saukh, A. R. Molla November, 20 Algorithm Theory, Winter Term 20/6 Problem Set - Sample Solution Exercise : Amortized

More information

Exercise 1 : B-Trees [ =17pts]

Exercise 1 : B-Trees [ =17pts] CS - Fall 003 Assignment Due : Thu November 7 (written part), Tue Dec 0 (programming part) Exercise : B-Trees [+++3+=7pts] 3 0 3 3 3 0 Figure : B-Tree. Consider the B-Tree of figure.. What are the values

More information

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

l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are: DDS-Heaps 1 Heaps - basics l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are: l insert an object, find the object of minimum key (find

More information

Chapter 6 Heap and Its Application

Chapter 6 Heap and Its Application Chapter 6 Heap and Its Application We have already discussed two sorting algorithms: Insertion sort and Merge sort; and also witnessed both Bubble sort and Selection sort in a project. Insertion sort takes

More information

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

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. CMSC 341 Fall 2013 Data Structures Final Exam B Name: Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. /12 TOTAL: /100 Instructions 1. This is a closed-book, closed-notes exam. 2. You

More information

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

l So unlike the search trees, there are neither arbitrary find operations nor arbitrary delete operations possible. DDS-Heaps 1 Heaps - basics l Heaps an abstract structure where each object has a key value (the priority), and the operations are: insert an object, find the object of minimum key (find min), and delete

More information

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

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology Introduction Chapter 4 Trees for large input, even linear access time may be prohibitive we need data structures that exhibit average running times closer to O(log N) binary search tree 2 Terminology recursive

More information

Chapter 4: Trees. 4.2 For node B :

Chapter 4: Trees. 4.2 For node B : Chapter : Trees. (a) A. (b) G, H, I, L, M, and K.. For node B : (a) A. (b) D and E. (c) C. (d). (e).... There are N nodes. Each node has two pointers, so there are N pointers. Each node but the root has

More information

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

Cpt S 223 Fall Cpt S 223. School of EECS, WSU Course Review Cpt S 223 Fall 2012 1 Final Exam When: Monday (December 10) 8 10 AM Where: in class (Sloan 150) Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes

More information

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

Chapter 5 Data Structures Algorithm Theory WS 2016/17 Fabian Kuhn Chapter 5 Data Structures Algorithm Theory WS 06/ Fabian Kuhn Examples Dictionary: Operations: insert(key,value), delete(key), find(key) Implementations: Linked list: all operations take O(n) time (n:

More information

Algorithms and Theory of Computation. Lecture 7: Priority Queue

Algorithms and Theory of Computation. Lecture 7: Priority Queue Algorithms and Theory of Computation Lecture 7: Priority Queue Xiaohui Bei MAS 714 September 5, 2017 Nanyang Technological University MAS 714 September 5, 2017 1 / 15 Priority Queues Priority Queues Store

More information

Course Review. Cpt S 223 Fall 2010

Course Review. Cpt S 223 Fall 2010 Course Review Cpt S 223 Fall 2010 1 Final Exam When: Thursday (12/16) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program

More information

CSCE750 Analysis of Algorithms Fall 2018 Fibonacci Heaps

CSCE750 Analysis of Algorithms Fall 2018 Fibonacci Heaps CSCE750 Analysis of Algorithms Fall 2018 Fibonacci Heaps This document contains slides from the lecture, formatted to be suitable for printing or individual reading, and with some supplemental explanations

More information

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

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY CS 251, LE 2 Fall 2016 MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY W1.) (i) Show one possible valid 2-3 tree containing the nine elements: 1 3 4 5 6 8 9 10 12. (ii) Draw the final binary search

More information

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

( ) n 3. n 2 ( ) D. Ο CSE 0 Name Test Summer 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n n matrices is: A. Θ( n) B. Θ( max( m,n, p) ) C.

More information

CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis CS711008Z Algorithm Design and Analysis Lecture 7. Binary heap, binomial heap, and Fibonacci heap Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 / 108 Outline

More information

CISC 621 Algorithms, Midterm exam March 24, 2016

CISC 621 Algorithms, Midterm exam March 24, 2016 CISC 621 Algorithms, Midterm exam March 24, 2016 Name: Multiple choice and short answer questions count 4 points each. 1. The algorithm we studied for median that achieves worst case linear time performance

More information

CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis CS700Z Algorithm Design and Analysis Lecture 7 Binary heap, binomial heap, and Fibonacci heap Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 / Outline Introduction

More information

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

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Sample Exam 1 75 minutes permitted Print your name, netid, and

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Binary Search Trees CLRS 12.2, 12.3, 13.2, read problem 13-3 University of Manitoba COMP 3170 - Analysis of Algorithms & Data Structures

More information

Final Examination CSE 100 UCSD (Practice)

Final Examination CSE 100 UCSD (Practice) Final Examination UCSD (Practice) RULES: 1. Don t start the exam until the instructor says to. 2. This is a closed-book, closed-notes, no-calculator exam. Don t refer to any materials other than the exam

More information

CISC 235: Topic 4. Balanced Binary Search Trees

CISC 235: Topic 4. Balanced Binary Search Trees CISC 235: Topic 4 Balanced Binary Search Trees Outline Rationale and definitions Rotations AVL Trees, Red-Black, and AA-Trees Algorithms for searching, insertion, and deletion Analysis of complexity CISC

More information

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

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n) CSE 0 Test Your name as it appears on your UTA ID Card Fall 0 Multiple Choice:. Write the letter of your answer on the line ) to the LEFT of each problem.. CIRCLED ANSWERS DO NOT COUNT.. points each. The

More information

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

Thus, it is reasonable to compare binary search trees and binary heaps as is shown in Table 1. 7.2 Binary Min-Heaps A heap is a tree-based structure, but it doesn t use the binary-search differentiation between the left and right sub-trees to create a linear ordering. Instead, a binary heap only

More information

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

Announcements. Midterm exam 2, Thursday, May 18. Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps. Break around 11:45am Announcements Midterm exam 2, Thursday, May 18 Closed book/notes but one sheet of paper allowed Covers up to stacks and queues Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps

More information

CSCI2100B Data Structures Trees

CSCI2100B Data Structures Trees CSCI2100B Data Structures Trees Irwin King king@cse.cuhk.edu.hk http://www.cse.cuhk.edu.hk/~king Department of Computer Science & Engineering The Chinese University of Hong Kong Introduction General Tree

More information

Balanced Search Trees. CS 3110 Fall 2010

Balanced Search Trees. CS 3110 Fall 2010 Balanced Search Trees CS 3110 Fall 2010 Some Search Structures Sorted Arrays Advantages Search in O(log n) time (binary search) Disadvantages Need to know size in advance Insertion, deletion O(n) need

More information

CMSC351 - Fall 2014, Homework #2

CMSC351 - Fall 2014, Homework #2 CMSC351 - Fall 2014, Homework #2 Due: October 8th at the start of class Name: Section: Grades depend on neatness and clarity. Write your answers with enough detail about your approach and concepts used,

More information

Multi-Way Search Trees

Multi-Way Search Trees Multi-Way Search Trees Manolis Koubarakis 1 Multi-Way Search Trees Multi-way trees are trees such that each internal node can have many children. Let us assume that the entries we store in a search tree

More information

CISC 320 Midterm Exam

CISC 320 Midterm Exam Name: CISC 320 Midterm Exam Wednesday, Mar 25, 2015 There are 19 questions. The first 15 questions count 4 points each. For the others, points are individually shown. The total is 100 points. Multiple

More information

Trees. Eric McCreath

Trees. Eric McCreath Trees Eric McCreath 2 Overview In this lecture we will explore: general trees, binary trees, binary search trees, and AVL and B-Trees. 3 Trees Trees are recursive data structures. They are useful for:

More information

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

Red-Black Trees. Based on materials by Dennis Frey, Yun Peng, Jian Chen, and Daniel Hood Red-Black Trees Based on materials by Dennis Frey, Yun Peng, Jian Chen, and Daniel Hood Quick Review of Binary Search Trees n Given a node n... q All elements of n s left subtree are less than n.data q

More information

Search Trees. COMPSCI 355 Fall 2016

Search Trees. COMPSCI 355 Fall 2016 Search Trees COMPSCI 355 Fall 2016 2-4 Trees Search Trees AVL trees Red-Black trees Splay trees Multiway Search Trees (2, 4) Trees External Search Trees (optimized for reading and writing large blocks)

More information

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

A red-black tree is a balanced binary search tree with the following properties: Binary search trees work best when they are balanced or the path length from root to any leaf is within some bounds. The red-black tree algorithm is a method for balancing trees. The name derives from

More information

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

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

CS350: Data Structures Red-Black Trees

CS350: Data Structures Red-Black Trees Red-Black Trees James Moscola Department of Engineering & Computer Science York College of Pennsylvania James Moscola Red-Black Tree An alternative to AVL trees Insertion can be done in a bottom-up or

More information

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

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

More information

COMP 251 Winter 2017 Online quizzes with answers

COMP 251 Winter 2017 Online quizzes with answers COMP 251 Winter 2017 Online quizzes with answers Open Addressing (2) Which of the following assertions are true about open address tables? A. You cannot store more records than the total number of slots

More information

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

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

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

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο CSE 0 Name Test Fall 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally

More information

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

Hierarchical data structures. Announcements. Motivation for trees. Tree overview Announcements Midterm exam 2, Thursday, May 18 Closed book/notes but one sheet of paper allowed Covers up to stacks and queues Today s topic: Binary trees (Ch. 8) Next topic: Priority queues and heaps

More information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

More information

CPS 231 Exam 2 SOLUTIONS

CPS 231 Exam 2 SOLUTIONS CPS 231 Exam 2 SOLUTIONS Fall 2003 1:00-2:25, Tuesday November 20th Closed book exam NAME: Problem Max Obtained 1 10 2 25 3 (a) 15 3 (b) 15 3 (c) 10 4 (a) 10 4 (b) 15 4 (c) 10 Total 110 1 [10 points ]

More information

Algorithms. Deleting from Red-Black Trees B-Trees

Algorithms. Deleting from Red-Black Trees B-Trees Algorithms Deleting from Red-Black Trees B-Trees Recall the rules for BST deletion 1. If vertex to be deleted is a leaf, just delete it. 2. If vertex to be deleted has just one child, replace it with that

More information

CS 380 ALGORITHM DESIGN AND ANALYSIS

CS 380 ALGORITHM DESIGN AND ANALYSIS CS 380 ALGORITHM DESIGN AND ANALYSIS Lecture 12: Red-Black Trees Text Reference: Chapters 12, 13 Binary Search Trees (BST): Review Each node in tree T is a object x Contains attributes: Data Pointers to

More information

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

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review 1 Review 1 Something I did not emphasize enough last time is that during the execution of depth-firstsearch, we construct depth-first-search trees. One graph may have multiple depth-firstsearch trees,

More information

Solution to CSE 250 Final Exam

Solution to CSE 250 Final Exam Solution to CSE 250 Final Exam Fall 2013 Time: 3 hours. December 13, 2013 Total points: 100 14 pages Please use the space provided for each question, and the back of the page if you need to. Please do

More information

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

9. Which situation is true regarding a cascading cut that produces c trees for a Fibonacci heap? 1 1 Name Test 1 - Closed Book Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each 1. During which operation on a leftist heap may subtree swaps be needed? A. DECREASE-KEY

More information

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

Trees. (Trees) Data Structures and Programming Spring / 28 Trees (Trees) Data Structures and Programming Spring 2018 1 / 28 Trees A tree is a collection of nodes, which can be empty (recursive definition) If not empty, a tree consists of a distinguished node r

More information

Section 05: Solutions

Section 05: Solutions Section 05: Solutions 1. Memory and B-Tree (a) Based on your understanding of how computers access and store memory, why might it be faster to access all the elements of an array-based queue than to access

More information

Binary Heaps in Dynamic Arrays

Binary Heaps in Dynamic Arrays Yufei Tao ITEE University of Queensland We have already learned that the binary heap serves as an efficient implementation of a priority queue. Our previous discussion was based on pointers (for getting

More information

Balanced Trees Part Two

Balanced Trees Part Two Balanced Trees Part Two Outline for Today Recap from Last Time Review of B-trees, 2-3-4 trees, and red/black trees. Order Statistic Trees BSTs with indexing. Augmented Binary Search Trees Building new

More information

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

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 Chapter 4 Trees 2 Introduction for large input, even access time may be prohibitive we need data structures that exhibit running times closer to O(log N) binary search tree 3 Terminology recursive definition

More information

We assume uniform hashing (UH):

We assume uniform hashing (UH): We assume uniform hashing (UH): the probe sequence of each key is equally likely to be any of the! permutations of 0,1,, 1 UH generalizes the notion of SUH that produces not just a single number, but a

More information

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

Binary search trees. Binary search trees are data structures based on binary trees that support operations on dynamic sets. COMP3600/6466 Algorithms 2018 Lecture 12 1 Binary search trees Reading: Cormen et al, Sections 12.1 to 12.3 Binary search trees are data structures based on binary trees that support operations on dynamic

More information

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

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012 1 University of Toronto Department of Electrical and Computer Engineering Midterm Examination ECE 345 Algorithms and Data Structures Fall 2012 Print your name and ID number neatly in the space provided

More information

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

Here is a recursive algorithm that solves this problem, given a pointer to the root of T : MaxWtSubtree [r] CSE 101 Final Exam Topics: Order, Recurrence Relations, Analyzing Programs, Divide-and-Conquer, Back-tracking, Dynamic Programming, Greedy Algorithms and Correctness Proofs, Data Structures (Heap, Binary

More information

FINAL EXAM SOLUTIONS

FINAL EXAM SOLUTIONS COMP/MATH 3804 Design and Analysis of Algorithms I Fall 2015 FINAL EXAM SOLUTIONS Question 1 (12%). Modify Euclid s algorithm as follows. function Newclid(a,b) if a

More information

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

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes CSE 250 Final Exam Fall 2013 Time: 3 hours. Dec 11, 2013 Total points: 100 14 pages Please use the space provided for each question, and the back of the page if you need to. Please do not use any extra

More information

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

An AVL tree with N nodes is an excellent data. The Big-Oh analysis shows that most operations finish within O(log N) time B + -TREES MOTIVATION An AVL tree with N nodes is an excellent data structure for searching, indexing, etc. The Big-Oh analysis shows that most operations finish within O(log N) time The theoretical conclusion

More information

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

Quiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g) Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology 6.006 Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1 Solutions Problem 1. Quiz 1 Solutions Asymptotic orders

More information

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

Trees (Part 1, Theoretical) CSE 2320 Algorithms and Data Structures University of Texas at Arlington Trees (Part 1, Theoretical) CSE 2320 Algorithms and Data Structures University of Texas at Arlington 1 Trees Trees are a natural data structure for representing specific data. Family trees. Organizational

More information