# A. V. Gerbessiotis CS Spring 2014 PS 3 Mar 24, 2014 No points

Save this PDF as:

Size: px
Start display at page:

Download "A. V. Gerbessiotis CS Spring 2014 PS 3 Mar 24, 2014 No points"

## Transcription

1 A. V. Gerbessiotis CS Spring 2014 PS 3 Mar 24, 2014 No points Problem 1. Suppose that we insert n keys into a hash table of size m using open addressing and uniform hashing. Let p(n, m) be the probability that no collisions occur. Show that p(n, m) exp( n(n 1)/(2m)). Argue that when n exceed m, the probability of avoiding collisions goes rapidly to zero. Hint: Use induction... Also use exp(x) 1 + x for any real x. Note that exp(x) = e x. Problem 2. Suppose that we are given a key k to search for in a hash table with positions 0,..., m 1, and suppose that we have a hash function h mapping the key space into the set {0,..., m 1}. The search scheme is as follows. 1. Compute the value i = h(k) and set j = Probe in position i for the desired k. If you find it, or if this position is empty, terminate the search. 3. Set j = (j + 1) mod m and i = (i + j) mod m and return to step 2. Assume that m is a power of 2. a. Show that this scheme is an instance of the general quadratic probing scheme by exhibiting the appropriate constant c 1, c 2 for h(k, i) = (h(k) + c 1 i + c 2 i 2 ) mod m. b. Prove that this algorithm examines every table position in the worst case. Problem 3. Given two strings a = a 0 a 1... a k and b = b 0 b 1... b m, where each a i and b j belongs to some ordered set of characters (e.g. english alphabet, binary set) we say that string a is lexicographically less than string b if either 1. there exists an integer j, where 0 j min(k, m), such that a i = b i for all i = 0,..., j 1 and a j < b j, or 2. k < m and a i = b i for all i = 0,..., k Black / \ 0 / \ 1 / \ / \ --/ Red Black Figure: A binary radix tree. \ 1 0 / Black Red /--\- \ 1 0/ \ / Red Red Black \ 1 ---\-- Red For example, 010 is lexicographically less than 0100 which is less than A binary radix tree is a tree built out of a collection of binary strings and one is depicted in the attached Figure. In a binary radix tree an edge leading to a left child can be labeled 0 and to a right child can be labeled 1. A node is either black or red; a black node indicates that the string (using the implied edge labels) corresponding to the path from the root to the black node is NOT in the tree, whereas a red node indicates that the string is in the tree. When searching for a in such a tree we traverse a left child at depth i if a i = 0, and a right child if a i = 1. If a red node is reached, a is in the tree, otherwise it is not. Searching for 101 leads to a black node and for 1011 to a red node: the former string does not exist, the latter does. Let A be a set of distinct binary strings whose total length sum is n. Show how to use a radix tree to sort A in lexicographic order in Θ(n) time. Sorting the tree above with n = 13 would give the strings 0, 011, 10, 100, 1011 in lexicographic order. 1

2 Problem 4. Consider inserting keys 1, 3, 5, 6, 12, 23, 10, 17, 34 into a hash table of length N = 11 using open addressing with the primary hash function h (k) = k mod N. Illustrate the result of inserting these keys using (i) linear probing with hash function h(k, i) = (h (k) + i) mod N, (ii) quadratic probing with hash function h(k, i) = (h (k) + i 2 ) mod N. Problem 5. The maximum-spanning tree problem is defined similarly to the minimum-spanning tree problem except that we want to maximize the sum of the weights of the edges of the tree. Give an algorithm that finds the maximum-spanning tree of an undirected graph G = (V, E, W ) where edges have weights represented in the weight matrix W. What is the running time of the algorithm? Problem 6. You are given six polynomials f 1,... f 6 of degrees 1, 2, 3, 1, 4, 5 respectively. We are interested in finding the product f = f 1 f 2 f 3 f 4 f 5 f 6. Assume that the cost of multiplying two polynomials of degree a and b is a b. Find a schedule for multiplying the six polynomials that is of the lowest possible total cost. Problem 7. a. What is the largest k such that if you can multiply 3 3 matrices using k multiplications (not assuming commutativity of multiplication), then you can multiply n n matrices in time o(n lg 7 )? What would the running time of this algorithm be? b. V. Pan has discovered a way of multiplying matrices using multiplications, matrices using multiplications, matrices using multiplications. Which method yields the best asymtotic running time when used in a divide and conquer matrix multiplication algorithm? How does it compare to Strassen s algorithm? Problem 8. You are given a directed graph with positive weights on its edges. Show how you can solve the minimum cost directed cycle problem in that graph in time faster than o(n 4 ) (this is a little-oh) in the worst-case. A directed cycle is a directed path that starts and ends in the same vertex and has at least one edge. A minimum cost directed cycle is one for which the sum of the weights of the edges of the cycle is minimal. Problem 9. How would you detect the existence of a negative-weight cycle in Floyd-Warshall? Problem 10. You are given an acyclic connected and undirected graph G = (V, E). Can you determine in O(n) time whether it has or not a cyle (note that the bound involves only n but not m)? Problem 11. You are given an undirected graph G = (V, E). Can you determine in O(n) time whether it has or not a cyle (note that the bound involves only n but not m)? Assume an adjacency list representation of the graph. Problem 12. We have an undirected weighed graph whose edges have weights that are only 10 or 20. Can you find the minimum spanning tree of this graph in O(n + m) time? Explain. Problem 13. What s the best way to find the product M 0 M 1 M 2 M 3 where the matrices are of dimension , , , and respectively? (In Problem 6, you had to deal with polynomials. The polynomials have now become matrices.) 2

3 PS 3 Solution Outline Problem 1. Consider p(n + 1, m) and argue similarly to the derivation for Insertion done in class. For the n + 1-sty key not to cause any collision in a hash table with n keys inserted with no collisions, it must hit an empty slot an event that occurs with probability 1 n/m. Therefore p(n + 1, m) = (1 n/m)p(n, m), since the probability that the insertion of say n + 1 cause not collision is the probability that the insertion of the n + 1-st key causes no collisions and the prior insertion of the remaining n keys caused no collisions; the latter is p(n, m). Therefore p(n + 1, m) = (1 n/m)p(n, m) = (1 n/m)(1 (n 1)/m)p(n 1, m) = (1 n/m)(1 (n 1)/m)... (1 1/m)(1 0/m)p(0, m) = (1 n/m)(1 (n 1)/m)... (1 1/m) Since e x 1 + x, setting x = i/m we obtain that 1 i/m e i/m. Therefore p(n + 1, m) = (1 n/m)(1 (n 1)/m)... (1 1/m) exp( n/m) exp( (n 1)/m)... exp( 1/m) exp( ( n)/m) = exp( n(n + 1)/2m) Therefore p(n, m) exp( (n 1)n/(2m)) as required. Consider n m, the n(n 1)/2m 1, and thus p(n, m) is upper bounded by exp( A), where A is large and positive. However exp( A) goes to zero and thus p(n, m) goes to zero as well. This problem is a variant known as the Birthday problem. Let m = 365 (forget about leap years). Suppose you have n people in a room. What is the probability of having no two with the same birthday? For what value of n is the probability of having two people with the same birthday close to 1? One can see that for n = m collisions start to show up with a significant (non negligible) probability, i.e. people exist with the same birthday. Problem 2. a. The hashing scheme searches entries h(k), h(k) + 1, h(k) , h(k) ,..., h(k) j modm, where m is a power of two. The value of i after j iterations (i.e. after j probes) is i = h(k, j) = h(k) j = h(k) + j(j + 1)/2 = h(k) + 1/2j + 1/2j 2 mod m, i.e. we indeed have a quadratic probing scheme with c 1 = c 2 = 1/2 and hash function h(k, j). b. (Proof by contradiction). Suppose that the algorithm does not examine every table position in the m probes h(k, j), j = 0,..., m 1. This means that at least one table entry is visited at least twice (and at least one is not visited at all) i.e. there exist 0 l, r m 1 such that h(k, l) = h(k, r), l r and therefore h(k, l) h(k, r) 0 (mod m). Without loss of generality, we assume l < r. We shall then show that for l, r as above we have that h(k, l) h(k, r), and therefore h(k, l) h(k, r) 0 (mod m), i.e. a contradiction. It is true that h(k, r) h(k, l) = r(r + 1)/2 l(l + 1)/2 = (r l)(r + l + 1)/2 0 (mod m). Consider (r l)(r + l + 1)/2 0 (mod m) or in the other words. (r l)(r + l + 1)/2 = Am for some integer A. For this to be true, m or a power of two must divide r l or r + l + 1 or both. We distinguish two major cases. 1. Let r l be even (i.e. r, l are both odd or both even). Then, r + l + 1 is odd and it is not divisible by m or 2 as both m (a power of 2) and 2 are even and r +l +1 was shown to be odd. On the other hand, r l m 1 as r, l m 1 < m. Then (r l)/2 < m and therefore m cannot divide (r l)/2 either. This means that (r l)(r +l +1)/2 0 (mod m), since m can divide neither r + l + 1 nor r l. 2. Let r l be odd. Then, if one of r, l is odd, the other one is even, and the sum r + l + 1 is even. As r l is odd it is not divisible by m or 2. We shall show that (r + l + 1)/2 is not divisible by m as well. As r, l m 1, r + l + 1 2(m 1) + 1 = 2m 1. r + l + 1 is even, 2m 1 is odd, thus r + l + 1 can not be equal to 2m 1 and therefore r + l + 1 2m 2 = 2(m 1). Then (r + l + 1)/2 m 1 < m, and therefore it is not divisible by m (as this would imply that (r + l + 1)/2 m). This means that (r l)(r + l + 1)/2 0 (mod m) as well. For both cases we derived a contradiction h(k, l) h(k, r) = (r l)(r + l + 1)/2 0 (mod m) to the assumption that h(k, l) h(k, r) 0 (mod m). Since no two values among the 0 through m 1 collide with each other, the cover all the values/indices/slots of the hash table as required. 3

4 Problem 3. First insert the strings and then perform a preorder traversal. In the preorder traversal a string is printed only for the red nodes (not for the black nodes that do not correspond to strings). Note that the preorder is the correct traversal as a node is printed before its descendants. A printed node x is a red node and the string corresponding to that node should be printed before the strings corresponding to its descendants (in the left or right subtree of x). Strings corresponding to nodes of x s left subtree must be printed before the ones corresponding to nodes of x s right subtree as up to node x both strings are the same, but just after x the strings in the left subtree have a leading zero and the ones in the right subtree have a leading 1; the former must be printed before the latter ones. Preorder traversal guarantees that. Running time of algorithm is O(n), as insertion takes time proportional to length of individual string being inserted and sum of all strings is n. Problem 4. means a,b,c keys caused collision in the indicated slot. LinearProbing Quadratic Probing Slot 0 : 10 1 : : : : : : : : 34 9 : 10 : In the Linear probing case you can observe the long cluster that causes problems to 34. Observe that for quadratic probing the collisions are fewer (by one). Problem 5. If the graph is G = (V, E, W ) consider graph G = (V, E, W ) i.e. we negate the weights of all the edges in G. A maximum spanning tree T in G is a minimum spanning tree in G. Note that the conversion of W into W takes time O(m). If G is represented by an adjacency-matrix we find all the edges and negate the corresponding weights in O(n 2 ) time. If G is represented by an adjacency-list we go through all the edges in time O(m) and negate the corresponding weights. Whatever the cost is O(m lg m), the running time of Kruskal s algorithm will contribute more. The maximum-spanning tree problem is defined similarly to the minimum-spanning tree problem Problem 6. Multiply them any way you like. The final result is a polynomial of degree 16 and the total cost is 100. Note that 100 is the sum of all products d i d j for every combination of two polynomials f i and f j among the six and d i and d j are respectively the degrees of f i and f j. In our example we have 6(6 1)/2 such pairs of polynomials. 100 = d 1 (d 2 + d 3 + d 4 + d 5 + d 6 ) + d 2 (d 3 + d 4 + d 5 + d 6 ) + d 3 (d 4 + d 5 + d 6 ) + d 4 (d 5 + d 6 ) + d 5 d 6 = 1( ) + 2( ) + 3( ) + 1(4 + 5) = This sum is independent of the order of the evaluation of the products; an easy proof is by induction (eg. with reference to the 6 polynomials above, the product of five of them f 2,..., f 6 takes time equal to the 4 summands except the first one d 1 (d 2 + d 3 + d 4 + d 5 + d 6 ); in the last step of an inductive proof the polynomial f 1 whose degree is d 1 is multiplied by the result f 2... f 6 whose degree is d d 6 and the cost of that multiplication is the missing/absent (first) term. Permute the polynomial and the result remains the same except that the pairs of the products d i d j get rearranged.). Note. One of the reasons that this is so is that polynomials satisfy commutativity therefore f 1 f 2 = f 2 f 1. What happens if instead of polynomials you have matrices and the operation is matrix multiplication? The cost then depends on the specific schedule that you choose. [Check Subject 8 (to appear), pp. 4-7, on how to determine the optimal schedule using dynamic programming]. 4

5 Problem 7. a. Strassen s algorithm uses the pattern of multiplication for 2 2 matrices and divide-and-conquer by splitting a matrix multiplication of n n matrices into a matrix multiplication of n/2 n/2 matrices to derive a time bound for matrix multiplication given by the recurrence T (n) = 7T (n/2) + O(n 2 ). In such a recurrence the 7 indicates the number of scalar multiplications in multiplying 2 2 matrices or the number of n/2 n/2 matrix multiplications in the recursive (divide-and-conquer) decomposition. Note that Strassen s method on 2 2 matrices can not be improved. We cannot multiply 2 2 matrices with say 6 (scalar) multiplications. Now if we can multiply 3 3 matrices and k is the number of scalar multiplications required and we use a recursive decomposition of an n n matrix into n/3 n/3 matrices we get a recurrence for the running time of this method of T (n) = kt (n/3) + O(n 2 ). The solution of this recurrence (master method) yields T (n) = Θ(n log 3 k ). Therefore if we compare the exponent log 3 k to lg 7, then for k = 21 we have log < = lg 7. For that value of k = 21 or smaller a by 3 decomposition beats Strassen s method. b. This is similar to part (a). If we decompose not by-2 or by-3, but by-t, where t now is 68, 70, 72 we obtain that the running time for such a decomposition is given by the recurrence, T (n) = kt (n/t) + O(n 2 ). with an asymptotically tight solution given by T (n) = Θ(n log t k ). Therefore if we compare the exponent log t k to lg 7, then for t = 68, log = , t = 70, log = , t = 72, log = All three of them beat Strassen s exponent. The best of the three is the t = 70 split. Calculations used the Unix bc calculator and hopefully are correct! Problem 8. Set a ii =. Run Floyd-Warshall. Then a n ii among all a n ii for all i. will give the length of the smallest cycle from i to i. Find the minimum Problem 9. At every iteration inspect the diagonal elements. Initially, they are all zero. If a value along the diagonal changes it can only grow smaller, i.e. negative. A negative a k ii < 0 show the existence of a cycle with end-points i whose all intermediate vertices are k or less. Problem 10. Yes! G is a tree and thus m = n 1. Therefore depth-first-search solves this problem in O(n + m) time which is O(n) as well. Problem 11. Yes! Run depth first search by also using two counters for each connected component discovered during the top-level call. One counts the vertices discovered and the other the edges discovered. If edges discovered is equal or more than vertices discovered, we have a cycle by the simple observation that in a tree edges are one less than vertices, and if in a connected component searched through depth-first-search we have discovered a number of edges equal to or more than the number of vertices, a cycle should exist there. Note that in this algorithm the running time is i O(n i + m i ), where n i is the number of vertices in the i-th component searched and m i the number of edges searched in that component. Naturally i n i = n. Given that the search process stops as soons as m i n i, we have m i n i. Therefore i m i = O(n). Combining the two we obtain that i O(n i + m i ) = O(n) as well. Problem 12. Yes! We only need to maintain a heap whose operations are O(1) rather than the traditional O(lg n). Note that in Prim s algorithm the key in a heap is the edge weight. We can only have two values 10 or 20. Therefore we can implement a heap with an array of size two that stores two (doubly) linked lists. We attach to element 0 a linked list of all edges of weight 10, and to element 1 a linked list of all edges of weight 20. We only insert or delete from the head of the list to mainain O(1) time operations. Insert inserts the weight of edge (u, v) into the Heap as the weight of v. We insert either to the linked list attached to element 0 or to the one attached to element 1. Either time is constant. At the same time we point point[v] to this location (we can also choose to record in (u, v) information that this edge is related to v). ExtractMin takes O(1) time. Check list 0 first. If list 0 is not empty, extract its element pointed by head. If list 0 is empty go to list 1 and extract an element through the head pointer. If both lists 0 and 1 are empty return underflow. 5

6 Decrease takes constant time because we use doubly linked lists. We might move an element (edge) from one list to the other. Note that in accordance to Prim s algorithm for every vertex in an array of size n we store a pointer point[v] that points to the position of the vertex in the linked list/heap. Therefore DecreaseMin(v) (lines 10-12), first locates v in the corresponding linked list using point[v] (and this should be the list attached to element 1) and if the value needs to be decreased (i.e. from 20 to 10) then the element pointed to by point[v] is deleted in constant time, a new element is inserted in the linked list of element 0 and point[v] points to this new location (and also the new location points to v). Problem 13. Easy. at a cost of 2,200,000. ((M 0 (M 1 M 2 )) M 3 ) j=i+b M 1.2M 2.2M i 1 0 1M 3M 2 0 5M < N[i,i+1] M=1,000, < N[i.i]=0 Example Calculation - Diagonal elements are 0 by N[i,i] initialization - Elements over diagonal are computed by N[i,i+1]=di di+1 di+2 formulae - Elements below the diagonal are irrelevant - Consider N[0,2] (the entry that will become 1.2M); This is N[i,j]=N[i,i+b] - Its entry is determined by elements of the same row and column - One choice is M[0,0]*M[1,2] with M[0,0]=0 M[1,2]=1M - Another choice is M[0,1]*M[2,2] with M[0,1]=10M M[2,2]=0 - First choice gives 0+ 1M + 100x200x10 = 1.2M - Second choice gives 10M x500x10 } = 10.5M - The smallest of the two and original value (infinity) is 1.2 M - Therefore so far (M0 x (M1 x M2)) is the way to go. - For an element N[i,j] - the element of the same row used is N[i,k] and di - the element of the same column used is N[k+1,j] and dk+1 and dj+1 6

### CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.

Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure

### CMPS 102 Solutions to Homework 1

CMPS 0 Solutions to Homework Lindsay Brown, lbrown@soe.ucsc.edu September 9, 005 Problem..- p. 3 For inputs of size n insertion sort runs in 8n steps, while merge sort runs in 64n lg n steps. For which

### Sample Questions Csci 1112 A. Bellaachia

Sample Questions Csci 1112 A. Bellaachia Important Series : o S( N) 1 2 N N i N(1 N) / 2 i 1 o Sum of squares: N 2 N( N 1)(2N 1) N i for large N i 1 6 o Sum of exponents: N k 1 k N i for large N and k

### Exam study sheet for CS2711. List of topics

Exam study sheet for CS2711 Here is the list of topics you need to know for the final exam. For each data structure listed below, make sure you can do the following: 1. Give an example of this data structure

### 2.3 Scheduling jobs on identical parallel machines

2.3 Scheduling jobs on identical parallel machines There are jobs to be processed, and there are identical machines (running in parallel) to which each job may be assigned Each job = 1,,, must be processed

### Data Structure [Question Bank]

Unit I (Analysis of Algorithms) 1. What are algorithms and how they are useful? 2. Describe the factor on best algorithms depends on? 3. Differentiate: Correct & Incorrect Algorithms? 4. Write short note:

### Binary Search Trees CMPSC 122

Binary Search Trees CMPSC 122 Note: This notes packet has significant overlap with the first set of trees notes I do in CMPSC 360, but goes into much greater depth on turning BSTs into pseudocode than

### 2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

Code No: R05220502 Set No. 1 1. (a) Describe the performance analysis in detail. (b) Show that f 1 (n)+f 2 (n) = 0(max(g 1 (n), g 2 (n)) where f 1 (n) = 0(g 1 (n)) and f 2 (n) = 0(g 2 (n)). [8+8] 2. (a)

### Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Tutorial#1 Q 1:- Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2:- What is a Data Type? Differentiate

### Analysis of Algorithms, I

Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, February 26, 2015 Outline 1 Recap 2 Representing graphs 3 Breadth-first search (BFS) 4 Applications

### Intro. to the Divide-and-Conquer Strategy via Merge Sort CMPSC 465 CLRS Sections 2.3, Intro. to and various parts of Chapter 4

Intro. to the Divide-and-Conquer Strategy via Merge Sort CMPSC 465 CLRS Sections 2.3, Intro. to and various parts of Chapter 4 I. Algorithm Design and Divide-and-Conquer There are various strategies we

### Universal hashing. In other words, the probability of a collision for two different keys x and y given a hash function randomly chosen from H is 1/m.

Universal hashing No matter how we choose our hash function, it is always possible to devise a set of keys that will hash to the same slot, making the hash scheme perform poorly. To circumvent this, we

### Tables so far. set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n)

Hash Tables Tables so far set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n) Worst O(lg n) O(lg n) O(lg n) Table naïve array implementation

### Data Structures and Algorithms Written Examination

Data Structures and Algorithms Written Examination 22 February 2013 FIRST NAME STUDENT NUMBER LAST NAME SIGNATURE Instructions for students: Write First Name, Last Name, Student Number and Signature where

### Lecture 15 An Arithmetic Circuit Lowerbound and Flows in Graphs

CSE599s: Extremal Combinatorics November 21, 2011 Lecture 15 An Arithmetic Circuit Lowerbound and Flows in Graphs Lecturer: Anup Rao 1 An Arithmetic Circuit Lower Bound An arithmetic circuit is just like

### The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge, cheapest first, we had to determine whether its two endpoints

### DATA STRUCTURES USING C

DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give

### CS473 - Algorithms I

CS473 - Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm View in slide-show mode 1 Reminder: Merge Sort Input array A sort this half sort this half Divide Conquer merge two sorted halves Combine

### Quiz 1 Solutions. (a) T F The height of any binary search tree with n nodes is O(log n). Explain:

Introduction to Algorithms March 9, 2011 Massachusetts Institute of Technology 6.006 Spring 2011 Professors Erik Demaine, Piotr Indyk, and Manolis Kellis Quiz 1 Solutions Problem 1. Quiz 1 Solutions True

### DATA ANALYSIS II. Matrix Algorithms

DATA ANALYSIS II Matrix Algorithms Similarity Matrix Given a dataset D = {x i }, i=1,..,n consisting of n points in R d, let A denote the n n symmetric similarity matrix between the points, given as where

### 5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

1. The advantage of.. is that they solve the problem if sequential storage representation. But disadvantage in that is they are sequential lists. [A] Lists [B] Linked Lists [A] Trees [A] Queues 2. The

### Chapter Objectives. Chapter 9. Sequential Search. Search Algorithms. Search Algorithms. Binary Search

Chapter Objectives Chapter 9 Search Algorithms Data Structures Using C++ 1 Learn the various search algorithms Explore how to implement the sequential and binary search algorithms Discover how the sequential

### GRAPH THEORY LECTURE 4: TREES

GRAPH THEORY LECTURE 4: TREES Abstract. 3.1 presents some standard characterizations and properties of trees. 3.2 presents several different types of trees. 3.7 develops a counting method based on a bijection

### Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Sorting revisited How did we use a binary search tree to sort an array of elements? Tree Sort Algorithm Given: An array of elements to sort 1. Build a binary search tree out of the elements 2. Traverse

### CS2 Algorithms and Data Structures Note 11. Breadth-First Search and Shortest Paths

CS2 Algorithms and Data Structures Note 11 Breadth-First Search and Shortest Paths In this last lecture of the CS2 Algorithms and Data Structures thread we will consider the problem of computing distances

### CS 102: SOLUTIONS TO DIVIDE AND CONQUER ALGORITHMS (ASSGN 4)

CS 10: SOLUTIONS TO DIVIDE AND CONQUER ALGORITHMS (ASSGN 4) Problem 1. a. Consider the modified binary search algorithm so that it splits the input not into two sets of almost-equal sizes, but into three

### Lecture 1: Course overview, circuits, and formulas

Lecture 1: Course overview, circuits, and formulas Topics in Complexity Theory and Pseudorandomness (Spring 2013) Rutgers University Swastik Kopparty Scribes: John Kim, Ben Lund 1 Course Information Swastik

### Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

### Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in

### Approximation Algorithms

Approximation Algorithms or: How I Learned to Stop Worrying and Deal with NP-Completeness Ong Jit Sheng, Jonathan (A0073924B) March, 2012 Overview Key Results (I) General techniques: Greedy algorithms

### 1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated

### 12 Abstract Data Types

12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).

### SHARP BOUNDS FOR THE SUM OF THE SQUARES OF THE DEGREES OF A GRAPH

31 Kragujevac J. Math. 25 (2003) 31 49. SHARP BOUNDS FOR THE SUM OF THE SQUARES OF THE DEGREES OF A GRAPH Kinkar Ch. Das Department of Mathematics, Indian Institute of Technology, Kharagpur 721302, W.B.,

### Lecture 3: Linear Programming Relaxations and Rounding

Lecture 3: Linear Programming Relaxations and Rounding 1 Approximation Algorithms and Linear Relaxations For the time being, suppose we have a minimization problem. Many times, the problem at hand can

### Dynamic Programming. Lecture 11. 11.1 Overview. 11.2 Introduction

Lecture 11 Dynamic Programming 11.1 Overview Dynamic Programming is a powerful technique that allows one to solve many different types of problems in time O(n 2 ) or O(n 3 ) for which a naive approach

### Converting a Number from Decimal to Binary

Converting a Number from Decimal to Binary Convert nonnegative integer in decimal format (base 10) into equivalent binary number (base 2) Rightmost bit of x Remainder of x after division by two Recursive

### Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik Demaine and Shafi Goldwasser Quiz 1 Quiz 1 Do not open this quiz booklet until you are directed

### B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

### Divide And Conquer Algorithms

CSE341T/CSE549T 09/10/2014 Lecture 5 Divide And Conquer Algorithms Recall in last lecture, we looked at one way of parallelizing matrix multiplication. At the end of the lecture, we saw the reduce SUM

### Analysis of Algorithms I: Binary Search Trees

Analysis of Algorithms I: Binary Search Trees Xi Chen Columbia University Hash table: A data structure that maintains a subset of keys from a universe set U = {0, 1,..., p 1} and supports all three dictionary

### Finding and counting given length cycles

Finding and counting given length cycles Noga Alon Raphael Yuster Uri Zwick Abstract We present an assortment of methods for finding and counting simple cycles of a given length in directed and undirected

### Fast Sequential Summation Algorithms Using Augmented Data Structures

Fast Sequential Summation Algorithms Using Augmented Data Structures Vadim Stadnik vadim.stadnik@gmail.com Abstract This paper provides an introduction to the design of augmented data structures that offer

### A Note on Maximum Independent Sets in Rectangle Intersection Graphs

A Note on Maximum Independent Sets in Rectangle Intersection Graphs Timothy M. Chan School of Computer Science University of Waterloo Waterloo, Ontario N2L 3G1, Canada tmchan@uwaterloo.ca September 12,

### PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

### 1 2-3 Trees: The Basics

CS10: Data Structures and Object-Oriented Design (Fall 2013) November 1, 2013: 2-3 Trees: Inserting and Deleting Scribes: CS 10 Teaching Team Lecture Summary In this class, we investigated 2-3 Trees in

### The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

CHAPTER 5 The Tree Data Model There are many situations in which information has a hierarchical or nested structure like that found in family trees or organization charts. The abstraction that models hierarchical

### Mathematical Induction. Lecture 10-11

Mathematical Induction Lecture 10-11 Menu Mathematical Induction Strong Induction Recursive Definitions Structural Induction Climbing an Infinite Ladder Suppose we have an infinite ladder: 1. We can reach

### Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li Advised by: Dave Mount May 22, 2014 1 INTRODUCTION In this report we consider the implementation of an efficient

### IE 680 Special Topics in Production Systems: Networks, Routing and Logistics*

IE 680 Special Topics in Production Systems: Networks, Routing and Logistics* Rakesh Nagi Department of Industrial Engineering University at Buffalo (SUNY) *Lecture notes from Network Flows by Ahuja, Magnanti

### Any two nodes which are connected by an edge in a graph are called adjacent node.

. iscuss following. Graph graph G consist of a non empty set V called the set of nodes (points, vertices) of the graph, a set which is the set of edges and a mapping from the set of edges to a set of pairs

### Homework Exam 1, Geometric Algorithms, 2016

Homework Exam 1, Geometric Algorithms, 2016 1. (3 points) Let P be a convex polyhedron in 3-dimensional space. The boundary of P is represented as a DCEL, storing the incidence relationships between the

### Lecture 2 February 12, 2003

6.897: Advanced Data Structures Spring 003 Prof. Erik Demaine Lecture February, 003 Scribe: Jeff Lindy Overview In the last lecture we considered the successor problem for a bounded universe of size u.

### Full and Complete Binary Trees

Full and Complete Binary Trees Binary Tree Theorems 1 Here are two important types of binary trees. Note that the definitions, while similar, are logically independent. Definition: a binary tree T is full

### AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm

AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm Time: Three Hours] [Maximum Marks: 60 Note Attempts all the questions. All carry equal marks Section A

### Binary Search. Search for x in a sorted array A.

Divide and Conquer A general paradigm for algorithm design; inspired by emperors and colonizers. Three-step process: 1. Divide the problem into smaller problems. 2. Conquer by solving these problems. 3.

### Problem Set 7 Solutions

8 8 Introduction to Algorithms May 7, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik Demaine and Shafi Goldwasser Handout 25 Problem Set 7 Solutions This problem set is due in

### Dynamic Programming. Applies when the following Principle of Optimality

Dynamic Programming Applies when the following Principle of Optimality holds: In an optimal sequence of decisions or choices, each subsequence must be optimal. Translation: There s a recursive solution.

### princeton univ. F 13 cos 521: Advanced Algorithm Design Lecture 6: Provable Approximation via Linear Programming Lecturer: Sanjeev Arora

princeton univ. F 13 cos 521: Advanced Algorithm Design Lecture 6: Provable Approximation via Linear Programming Lecturer: Sanjeev Arora Scribe: One of the running themes in this course is the notion of

### MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS 1. SYSTEMS OF EQUATIONS AND MATRICES 1.1. Representation of a linear system. The general system of m equations in n unknowns can be written a 11 x 1 + a 12 x 2 +

### Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Binary Search Trees Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 27 1 Properties of Binary Search Trees 2 Basic BST operations The worst-case time complexity of BST operations

### International Journal of Software and Web Sciences (IJSWS) www.iasir.net

International Association of Scientific Innovation and Research (IASIR) (An Association Unifying the Sciences, Engineering, and Applied Research) ISSN (Print): 2279-0063 ISSN (Online): 2279-0071 International

### Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Binary Search Trees A Generic Tree Nodes in a binary search tree ( B-S-T) are of the form P parent Key A Satellite data L R B C D E F G H I J The B-S-T has a root node which is the only node whose parent

### 8.1 Min Degree Spanning Tree

CS880: Approximations Algorithms Scribe: Siddharth Barman Lecturer: Shuchi Chawla Topic: Min Degree Spanning Tree Date: 02/15/07 In this lecture we give a local search based algorithm for the Min Degree

### CMPSCI611: Approximating MAX-CUT Lecture 20

CMPSCI611: Approximating MAX-CUT Lecture 20 For the next two lectures we ll be seeing examples of approximation algorithms for interesting NP-hard problems. Today we consider MAX-CUT, which we proved to

### Ordered Lists and Binary Trees

Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 6-0:

### Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity.

7 Catalan Numbers Thomas A. Dowling, Department of Mathematics, Ohio State Uni- Author: versity. Prerequisites: The prerequisites for this chapter are recursive definitions, basic counting principles,

### root node level: internal node edge leaf node CS@VT Data Structures & Algorithms 2000-2009 McQuain

inary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from each

### A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

Chapter 12: Binary Search Trees A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: For all nodes x and y, if y belongs to the left subtree

### Linear Programming. March 14, 2014

Linear Programming March 1, 01 Parts of this introduction to linear programming were adapted from Chapter 9 of Introduction to Algorithms, Second Edition, by Cormen, Leiserson, Rivest and Stein [1]. 1

### Social Media Mining. Graph Essentials

Graph Essentials Graph Basics Measures Graph and Essentials Metrics 2 2 Nodes and Edges A network is a graph nodes, actors, or vertices (plural of vertex) Connections, edges or ties Edge Node Measures

### A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

CmSc 250 Intro to Algorithms Chapter 6. Transform and Conquer Binary Heaps 1. Definition A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called

### Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally

Recurrence Relations Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally modeled by recurrence relations. A recurrence relation is an equation which

### Matrix Algebra. Some Basic Matrix Laws. Before reading the text or the following notes glance at the following list of basic matrix algebra laws.

Matrix Algebra A. Doerr Before reading the text or the following notes glance at the following list of basic matrix algebra laws. Some Basic Matrix Laws Assume the orders of the matrices are such that

### Theory of Computation Prof. Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology, Madras

Theory of Computation Prof. Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture No. # 31 Recursive Sets, Recursively Innumerable Sets, Encoding

### Introduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24

Introduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24 The final exam will cover seven topics. 1. greedy algorithms 2. divide-and-conquer algorithms

### Some Polynomial Theorems. John Kennedy Mathematics Department Santa Monica College 1900 Pico Blvd. Santa Monica, CA 90405 rkennedy@ix.netcom.

Some Polynomial Theorems by John Kennedy Mathematics Department Santa Monica College 1900 Pico Blvd. Santa Monica, CA 90405 rkennedy@ix.netcom.com This paper contains a collection of 31 theorems, lemmas,

### Data Structures in Java. Session 15 Instructor: Bert Huang http://www1.cs.columbia.edu/~bert/courses/3134

Data Structures in Java Session 15 Instructor: Bert Huang http://www1.cs.columbia.edu/~bert/courses/3134 Announcements Homework 4 on website No class on Tuesday Midterm grades almost done Review Indexing

### 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

### A permutation can also be represented by describing its cycles. What do you suppose is meant by this?

Shuffling, Cycles, and Matrices Warm up problem. Eight people stand in a line. From left to right their positions are numbered,,,... 8. The eight people then change places according to THE RULE which directs

### MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS Systems of Equations and Matrices Representation of a linear system The general system of m equations in n unknowns can be written a x + a 2 x 2 + + a n x n b a

### n 2 + 4n + 3. The answer in decimal form (for the Blitz): 0, 75. Solution. (n + 1)(n + 3) = n + 3 2 lim m 2 1

. Calculate the sum of the series Answer: 3 4. n 2 + 4n + 3. The answer in decimal form (for the Blitz):, 75. Solution. n 2 + 4n + 3 = (n + )(n + 3) = (n + 3) (n + ) = 2 (n + )(n + 3) ( 2 n + ) = m ( n

### Homework until Test #2

MATH31: Number Theory Homework until Test # Philipp BRAUN Section 3.1 page 43, 1. It has been conjectured that there are infinitely many primes of the form n. Exhibit five such primes. Solution. Five such

### Algorithm Design and Analysis

Algorithm Design and Analysis LECTURE 27 Approximation Algorithms Load Balancing Weighted Vertex Cover Reminder: Fill out SRTEs online Don t forget to click submit Sofya Raskhodnikova 12/6/2011 S. Raskhodnikova;

### Lecture 12: Chain Matrix Multiplication

Lecture 12: Chain Matrix Multiplication CLRS Section 15.2 Outline of this Lecture Recalling matrix multiplication. The chain matrix multiplication problem. A dynamic programming algorithm for chain matrix

### , each of which contains a unique key value, say k i , R 2. such that k i equals K (or to determine that no such record exists in the collection).

The Search Problem 1 Suppose we have a collection of records, say R 1, R 2,, R N, each of which contains a unique key value, say k i. Given a particular key value, K, the search problem is to locate the

### Solution to Homework 2

Solution to Homework 2 Olena Bormashenko September 23, 2011 Section 1.4: 1(a)(b)(i)(k), 4, 5, 14; Section 1.5: 1(a)(b)(c)(d)(e)(n), 2(a)(c), 13, 16, 17, 18, 27 Section 1.4 1. Compute the following, if

### Data Structures Fibonacci Heaps, Amortized Analysis

Chapter 4 Data Structures Fibonacci Heaps, Amortized Analysis Algorithm Theory WS 2012/13 Fabian Kuhn Fibonacci Heaps Lacy merge variant of binomial heaps: Do not merge trees as long as possible Structure:

### DATABASE DESIGN - 1DL400

DATABASE DESIGN - 1DL400 Spring 2015 A course on modern database systems!! http://www.it.uu.se/research/group/udbl/kurser/dbii_vt15/ Kjell Orsborn! Uppsala Database Laboratory! Department of Information

### 6.3 Conditional Probability and Independence

222 CHAPTER 6. PROBABILITY 6.3 Conditional Probability and Independence Conditional Probability Two cubical dice each have a triangle painted on one side, a circle painted on two sides and a square painted

### Discrete Mathematics Problems

Discrete Mathematics Problems William F. Klostermeyer School of Computing University of North Florida Jacksonville, FL 32224 E-mail: wkloster@unf.edu Contents 0 Preface 3 1 Logic 5 1.1 Basics...............................

### Operation Count; Numerical Linear Algebra

10 Operation Count; Numerical Linear Algebra 10.1 Introduction Many computations are limited simply by the sheer number of required additions, multiplications, or function evaluations. If floating-point

### 4. MATRICES Matrices

4. MATRICES 170 4. Matrices 4.1. Definitions. Definition 4.1.1. A matrix is a rectangular array of numbers. A matrix with m rows and n columns is said to have dimension m n and may be represented as follows:

### The Goldberg Rao Algorithm for the Maximum Flow Problem

The Goldberg Rao Algorithm for the Maximum Flow Problem COS 528 class notes October 18, 2006 Scribe: Dávid Papp Main idea: use of the blocking flow paradigm to achieve essentially O(min{m 2/3, n 1/2 }

### Binary Trees and Huffman Encoding Binary Search Trees

Binary Trees and Huffman Encoding Binary Search Trees Computer Science E119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Motivation: Maintaining a Sorted Collection of Data A data dictionary

### Section 6-2 Mathematical Induction

6- Mathematical Induction 457 In calculus, it can be shown that e x k0 x k k! x x x3!! 3!... xn n! where the larger n is, the better the approximation. Problems 6 and 6 refer to this series. Note that

### Spring 2007 Math 510 Hints for practice problems

Spring 2007 Math 510 Hints for practice problems Section 1 Imagine a prison consisting of 4 cells arranged like the squares of an -chessboard There are doors between all adjacent cells A prisoner in one

### Lecture 18: Applications of Dynamic Programming Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY 11794 4400

Lecture 18: Applications of Dynamic Programming Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena Problem of the Day

### To My Parents -Laxmi and Modaiah. To My Family Members. To My Friends. To IIT Bombay. To All Hard Workers

To My Parents -Laxmi and Modaiah To My Family Members To My Friends To IIT Bombay To All Hard Workers Copyright 2010 by CareerMonk.com All rights reserved. Designed by Narasimha Karumanchi Printed in