(b) Give as accurate (Big-Oh) an analysis as you can of the expected running time of each algorithm.

Size: px
Start display at page:

Download "(b) Give as accurate (Big-Oh) an analysis as you can of the expected running time of each algorithm."

Transcription

1 Problem DS (b) (e) Suppose you need to generate a random permutation of the first N integers. For example, 4, 3,, 5, 2 and 3,, 4, 2, 5 are legal permutation, but 5, 4,, 2, is not, because one number is duplicated and another 3 is missing. This routine is often used in simulation of algorithms. We assume the existence of a random number generator, RandInt(i, j), which generates integers between i and j with equal probability. Here are three algorithms:. Fill the array A from A[0] to A[N ] as follows: To fill A[i], generate random numbers until you get one that is not already in A[0], A[],..., A[i ]. 2. Same as algorithm (), but keep an extra array called Used array. When a random number, Ran, is first put in the array A, set Used[Ran] =. This means that when filling A[i] with a random number, you can test in one step to see whether the random number has been used, instead of the (possibly) i steps in the first algorithm. 3. Fill the array such that A[i] = i +. Then for( i=; i<n; i++) Swap( &A[i], &A[RandInt(0,i)]); (b) Give as accurate (Big-Oh) an analysis as you can of the expected running time of each algorithm. (e) What is the worst-case running time of each algorithm? Solution. (b) We assume that the running time for each call of RandInt(i, j) takes a constant time. For the first algorithm, the time to decide if a random number to be placed in A[i] has not been used earlier is O(i) because it needs to compare the result of A[i] generated by random number and every place before A[i] (i.e., between A[0] and A[i ]). The expected number of random numbers that need to be tried is N/(N i) and the probability of success is (N i)/n. Thus the expected number of independent trials is N/(N i). The time bound is thus N i=0 i N N N i < i=0 N 2 N N i = N 2 i=0 N i = N 2 N j= j = O(N 2 log N). The second algorithm saves a factor of i for each random number, and thus reduces the time bound to O(N log N) on average. The third algorithm is clearly linear. (e) The worst-case running time of algorithms and 2 cannot be bounded because there is always a finite probability that the program will not terminate by some given time T. The worst-case running time of the third algorithm is linear because its running time does not depend on the sequence of random numbers.

2 Problem DS-02- Given an efficient algorithm to determine if there exists an integer i such that A i = i in an array of integers A < A 2 < A 3 < < A N. What is the running time of your algorithm? Solution. Due to the facts that all integers in the array are distinct and permute in increasing order, we first give the following observation. For any given i between and N, if we check A i and obtain A i > i, then we have the result that A j j for all j > i (e.g., suppose we have A 5 = 8, it implies that A 6 9, A 7 0, A 8,... etc.) Oppositely, if A i < i, by the similar reasoning we have A j j for all j < i. Therefore, we can design the algorithm by using the binary search technique. #include<math.h> #include<stdio.h> int find(int A[], int N) int lower=, upper=n, mid; while (lower <= upper) mid = (lower+upper)/2; if (A[mid]>mid) upper = mid-; if (A[mid]<mid) lower = mid+; return mid; return NOT_FOUND; The worest-case running time of the program is O(log 2 N).

3 Problem DS-02-3 (a) (b) (a) Write a program to determine if a positive integer, N, is prime. (b) In terms of N, what is the worst-case running time of your program? (You should be able to do this in O( N).) Solution. (a) #include<math.h> #include<stdio.h> void main() int N,j,f=0; printf("please input a positive integer N for testing prime."); scanf("%d",&n); for(j=2; j<=sqrt(n); j++) if (N%j == 0) f=; break; if (f == 0) printf("n is a prime") printf("n is not a prime") (b) The worest-case running time of the program is O( N).

4 Problem DS-02-3 (c) (d) (e) (a) Write a program to determine if a positive integer, N, is prime. (b) In terms of N, what is the worst-case running time of your program? (You should be able to do this in O( N).) (c) Let B equal the number of bits in the binary representation of N. What is the value of B? (d) In therms of B, what is the worst-case running time of your program? (e) Compare the running times to determine if a 20-bits number and a 40-bits number are prime. Solution. For (a) and (b), see DS-02-3 (a) (b). (c) Since B = log 2 (N + ), we have B = O(log 2 N). (d) Since N 2 B, we have N (2 B ) /2 < 2 B/2. Thus, the worst-case running time of the algorithm is O(2 B/2 ). (e) Suppose that a 20-bit number can be tested in time T = O(2 20/2 ) = O(2 0 ). Then, a 40-bit number would require about T = O(2 40/2 ) = O(2 20 ) = T 2 time.

5 Supplementary Problem 02-0 Show directly that T (N) = N 2 + 3N 3 = Θ(N 3 ). That is, use the definitions of O and Ω to show that T (N) is in both O(N 3 ) and Ω(N 3 ). Proof. For proving T (N) = Θ(h(N)), we need to show that both T (N) = O(h(N)) and T (N) = Ω(h(N)). Since T (N) = N 2 + 3N 3, we consider h(n) = N 3. By definition, we can find c = 3, c 2 = 4, and n 0 = such that c h(n) T (N) c 2 h(n) holds. We verify as follows: T (N) = N 2 + 3N 3 4N 3 = O(N 3 ) if N n 0 = and T (N) = N 2 + 3N 3 3N 3 = Ω(N 3 ) if N n 0 = Thus, T (N) = Θ(N 3 ).

6 Supplementary Problem Using the definitions of O and Ω, show that T (N) = 6N N = O(N 3 ) but T (N) = 6N N Ω(N 3 ). Proof. To show T (N) = 6N N = O(N 3 ), by definition, we can find c = and n 0 = 9 such that 6N N < N 3 if N n 0 = 9. Thus, T (N) = O(N 3 ). On the other hand, for proving T (N) Ω(g(N)), we need to show that for any given positive constant c, there exists an integer n 0 > 0 such that T (N) < c g(n) when N n 0. We now consider T (N) = 6N N and g(n) = N 3. Then, for any given constant c > 0, we choose n 0 as follows: 9/c, if 0 < c < n 0 = 9, if c. It is easy to verify that 6N N < c N 3 if N n 0 (e.g., if c = 9/0, then n 0 = 0. In this case, 6N N < 9 0 N 3 if N n 0 = 0). Thus, T (N) Ω(N 3 ).

7 Supplementary Problem Given an algorithm for the following problem. Given a set of n distinct positive integers, partition the set into two subsets, each of size n/2, such that the difference between the sums of the integers in the two subsets is minimized. Determine the time complexity of your algorithm. You may assume that n is a multiple of 2.

8 Problem DS Swap two adjacent elements by adjusting only the pointers (and not the data) using: (a) singly linked lists (b) doubly linked lists. Solution. (a) Suppose that BeforeP points to the node before the two adjacent nodes that are to be swapped. void SwapTwoAdjacentNodes_Single(Position BeforeP, List L) Position P, AfterP; P = BeforeP->Next; AfterP = P->Next; P->Next = AfterP->Next; BeforeP->Next = AfterP; AfterP->Next = P; (b) Suppose that the declaration of node for doubly linked list is as follows: struct Node ElementType Element; Position Prev; Position Next; The following procedure can be used to swap node pointed by P and the node after P. void SwapTwoAdjacentNodes_Double(Position P, List L) Position BeforeP, AftertP; BeforeP = P->Prev; AfterP = P->Next; P->Next = AftertP->Next; BeforeP->Next = AfterP; AfterP->Next = P; P->Next->Prev = P; P->Prev = AfterP; AfterP->Prev = BeforeP;

9 Problem DS-03-6 (b) (d) Suppose we have an array-based list A[0... N ] and we want to delete all duplicates. LastPosition is initially N, but get smaller as elements are deleted. Consider the pseudocode program fragment in the following figure. The procedure Delete deletes the element in position j and collapses the list. for(i=0; i<lastposition; i++) j = i+; while(j<lastposition) if (A[i] == A[j]) Delete(j); j++; (b) Rewrite this procedure using general list operations. (d) what is the running time using a linked list implementation? Solution. (b) Suppose that L is a linked list and the function IsLast(P, L) can be used to test whether the position P is in the end of L in a constant time (See Page 47 for definition). Let P, Q, PrevQ be variables with type Position. P = L->Next; while(!islast(p,l)) PrevQ = P; while(!islast(prevq,l)) Q = PrevQ->Next; if (P->Element == Q->Element) PrevQ->Next = Q->Next; free(q) PrevQ = Q; Q = Q->Next; (d) It is trivial that the running time is O(N 2 ).

10 Problem DS-03-6 (e) Suppose we have an array-based list A[0... N ] and we want to delete all duplicates. LastPosition is initially N, but get smaller as elements are deleted. Consider the pseudocode program fragment in the following figure. The procedure Delete deletes the element in position j and collapses the list. for(i=0; i<lastposition; i++) j = i+; while(j<lastposition) if (A[i] == A[j]) Delete(j); j++; (e) Give an algorithm to solve this problem in O(N log N) time. Solution. adjacent). Sort the list, and make a scan to remove duplicates (which must now be void swap( int &a, int &b ) int temp = a; a = b; b = temp; void Quick_Sort( int p[], int left, int right ) int divided,i,j; if( left < right ) divided = left; do for( i=left+; p[i]<p[divided] && i<=right; i++ ); for( j=right; p[j]>p[divided] && j>=left; j-- ); if( i<j ) swap(p[i],p[j]); while( i<j ); swap( p[divided], p[j] ); Quick_Sort( p, left, j- ); Quick_Sort( p, j+, right );

11 void Remove_Duplicate( const int A[], int N ) Quick_Sort(A[],0,N-); int last = 0; for( k=; k<n; k++ ) if( A[last]!= A[k] ) A[last+] = A[k]; last = k; 2

12 Problem DS-03-7 An alternative to the deletion strategy we have given is to use lazy deletion. To delete an element, we merely mark it deleted (using an extra bit field). The number of deleted and nondeleted elements in the list is kept as part of the data structure. If there are as many deleted elements as nondeleted elements, we traverse the entire list, performing the standard deletion algorithm on all marked nodes. (a) List the advantages and disadvantages of lazy deletion. (b) Write routines to implement the standard linked list operations using lazy deletion. Solution. (a) The advantages are that it is simpler to code, and there is a possible savings if deleted keys are subsequently reinserted (in the same place). The disadvantage is that it uses more space, because each node needs an extra bit (which is typically a byte), and unused nodes are not freed. (b) Let the structure of nodes be defined as follows: struct Node ElementType Element; Position Next; char Marked; // set to if deleted, and 0 otherwise To check the number of deleted elements and the number of nondeleted elements, we define the following two variable. Initially, both variables are set to be zero. int Total_Count = 0; // the total number of elements in the list int Deleted_Count = 0; // the total number of deleted elements The following are the relevant functions: Position Find(ElementType X, List L) Position P = L->Next; while ( P!= NULL && (P->Element!= X P->Marked) ) P = P->Next; return P; int IsLast(Position P, List L) return P->Next == NULL;

13 void Lazy_Deletion(ElementType X, List L) Position P; P = Find( X, L); if (P) P->Marked = ; Delete_Count++; if( Total_Count - Deleted_Count == Deleted_Count ) // the number of deleted elements is the same as the number // of nondeleted elements in the list Deletion(List L); void Deletion(List L) Position P, Provious, TmpCell; Provious = L; P = L->Next; while (!IsLast(P,L) ) if ( P->Marked ) TmpCell = P; P = P->Next; Previous->Next = P; free( TmpCell ); Total_Count--; Delete_Count--; Provious = P; P = P->Next; 2

14 Problem DS-03-8 (b) following languages: (b) C languages (/* */, ( ), [ ], ). Solution. F are valid. Write a program to check for balancing symbols in the For the input C language file F, we suppose that all symbols appeared in Also, the function Read Next Symbol(F ) can be used to read the next symbol from the current reading position of F, and the status of end of file for F can be checked by using the function EOF(F ). In addition, we suppose that the stack used in the following program is similar to that defined in page 68 of the textbook excepting that the data type ElementType is replaced with Symbol. int Check_Balance(File F) Stack S = CreateStack(); Symbol sym = Read_Next_Symbol(F); while (!EOF(F) ) switch(sym) case /* : case ( : case [ : case : Push(sym, S); break; case */ : if (Top(S)== /* ) Pop(S); return false; break; case ) : if (Top(S)== ( ) Pop(S); return false; break; case ] : if (Top(S)== [ ) Pop(S); return false; break; case : if (Top(S)== ( ) Pop(S); return false; break; sym = Read_Next_Symbol(F); if ( IsEmpty(S) ) return true; return false;

15 Problem DS (a) Propose a data structure that supports the stack Push and Pop operations and a third operation FindMin, which returns the smallest element in the data structure, all in O() worst case time. Solution. We suppose that the stack used in the program has structure similar to that defined in page 68 of the textbook. The idea is the use of the so-called extended stack. Let E be our extended stack. We will implement E with two stacks. One stack, which we ll call S, is used to keep track of the P ush and P op operations, and the other, M, keeps track of the minimum. To implement P ush(x, E), we perform P ush(x, S). If X is smaller than or equal to the top element in stack M, then we also perform P ush(x, M). To implement P op(e), we perform P op(s). If X is equal to the top element in stack M, then we also P op(m). F indmin(e) is performed by examining the top of M. All these operations are clearly O(). struct StackRecord int Capacity; int TopOfStack; ElementType *Array; typedef struct StackRecord *Stack; struct ExtendedRecord Stack S; Stack M; typedef struct ExtendedRecord *ExtendedStack int IsFull(Stack S) return S->TopOfStack == S->Capacity - ; int IsEmpty(Stack S) return S->TopOfStack == -;

16 ElementType Top(stack M) if (!IsEmpty(M) ) return M->Array[M->TopOfStack]; retuen MaxValue; // return a maximum integer to avoid warning void Push(ElementType X, ExtendedStack E) if ( IsFull(E->S) ) Error( "Full stack" ); E->S->Array[++E->S->TopOfStack] = X; if ( X <= Top(E->M) ) E->M->Array[++E->M->TopOfStack] = X; ElementType Pop(ExtendedStack E) ElementType temp; //Push(X,E) //Push(X,S) //Push(X,M) //Pop(E) if ( IsEmpty(E->S) ) Error( "Empty stack" ); temp = E->S->Array[E->S->TopOfStack]; E->S->TopOfStack--; if (Top(E->M) == temp) E->M->TopOfStack-- return temp; //Pop(S) //Pop(M) ElementType FindMin(ExtendedStack E) if ( IsEmpty(E->M) ) Error( "Empty stack" ); return Top(E->M); 2

17 Problem DS A deque is a data structure consisting of a list of items, on which the following operations are possible: Puch(X,D): Insert item X on the front end of deque D. Pop(D): Remove the front item from deque D and return it. Inject(X,D): Insert item X on the rear end of deque D. Eject(D): Remove the rear item from deque D and return it. Write routines to support the deque that take O() time per operation. Solution. We suppose that the informations about the deque are stored in the following record: struct DequeRecord int Capacity; int Front; int Rear; ElementType *Array; ; typedef struct DequeRecord *Deque; For convenience, we always assume that there exists sufficient memory to support the design of the structure. We first need the following relevant functions: Deque CreateDeque(int MaxElements) Deque D; D = malloc( sizeof( struct DequeRecord ) ); D->Array = malloc( sizeof( ElementType ) * MaxElements ); D->Capacity = MaxElements; D->Front = D->Capacity / 2; D->Rear = D->Capacity / 2 - ; return D; We now give the functions Push(X,D), Pop(D), Inject(X,D) and Eject(D) as follows: void Push(ElementType X, Deque D) if ( D->Front == 0 ) Error( "Full deque" ); D->Front--; D->Array[D->Front] = X;

18 ElementType Pop(Deque D) ElementType temp; if ( D->Rear < D->Front ) Error( "Empty deque" ); temp = D->array[D->Front]; D->Front++; return temp; void Inject(ElementType X, Deque D) if ( D->Rear == D->Capacity - ) Error( "Full deque" ); D->Rear++; D->Array[D->Rear] = X; ElementType Eject(Deque D) ElementType temp; if ( D->Rear < D->Front ) Error( "Empty deque" ); temp = D->array[D->Rear]; D->Rear--; return temp; 2

19 Problem DS Suppose a binary tree has leaves l, l 2,..., l M at depths d, d 2,..., d M, respectively. Prove that M i= s d i and determine when the equality is true. Proof. Before the proof, we first give an example to see the inequality M i= s d i. Consider a tree with five leaves (i.e., M = 5) shown below. depth 0 depth depth 2 l l 4 l 5 depth 3 l 3 depth 4 l 2 Then, d = depth(l ) = 2, d 2 = depth(l 2 ) = 4, d 3 = depth(l 3 ) = 3, d 4 = depth(l 4 ) = 2, and d 5 = depth(l 5 ) = 2. Thus, 5 i= 2 d i = = = 5 6 For any tree T with M leaves, we denote by F (T ) = M i= s d i where d i = depth(l i ) for each leaf l i in T. The proof is by induction on the number of nodes in a tree. Clearly, in a tree T with no nodes, we have F (T ) = 0, and in a one-node tree T, the root is a leaf at depth zero, so F (T ) = and the claim is true. Suppose the result is true for all trees with at most N nodes. Consider any tree T with N + nodes. Without loss of generality, we assume that such a tree consists of a left subtree T L with k node and a right subtree T R with N k node. By the inductive hypothesis, F (T L ) and F (T R ). Because all leaves are one deeper with respect to the original tree T than with respect to the subtrees T L or T R, F (T ) = 2 F (T L) + 2 F (T R), proving the result. The equality is true if and only if there are no nodes with one child. If there is a node with one child, the equality cannot be true because adding the second child would increase the sum to higher than. If no nodes have one child, then we can find and remove two sibling leaves, creating a new tree. It is easy to see that this new tree has the same sum as the old. Applying this step repeatedly, we arrive at a single node, whose sum is. Thus the original tree had sum.

20 Problem DS-04-2 Suppose you want to perform an experiment to verify the problem that can be caused by random Insert/Delete pairs. Here is a strategy that is not perfectly random, but close enough. You build a tree with N elements by inserting N elements chosen at random from the range to M = αn. You than perform N 2 pairs of insertions followed by deletions. Assume the existence of a routine, RandomInteger(A, B), which returns a uniform random integer between A and B inclusive. (a) Explain how to generate a random integer between and M that is not already in the tree (so a random inset can be performed). In term of N and α, what is the running time of this operation? (b) Explain how to generate a random integer between and M that is already in the tree (so a random delete can be performed). In term of N and α, what is the running time of this operation? (c) What is a good choice of α? Why? Solution. (a) Keep a bit array B. If i is in the tree, then B[i] is true; otherwise, it is false. Repeatedly generate random integers until an unused one is found. If there are N elements already in the tree, then M N are not, and the probability of finding one of these is (M N)/M. Thus the expected number of trials is M/(M N) = α/(α ). (b) To find an element that is in the tree, repeatedly generate random integers until an already-used integer is found. The probability of finding one is N/M, so the expected number of trials is M/N = α. (c) The total cost for one insert and one delete is α/(α )+α = +α+. Setting α α = 2 minimizes this cost.

21 Problem DS-04-2 (a) How many bits are required per node to store the height of a node in an N-node AVL tree? (b) What is the smallest AVL tree that overflows an 8-bit height counter? Solution. (a) The answer is log( log N + ) bits. From pages 0 of the textbook, it tell us that the height of an AVL tree is at most roughly.44 log(n + 2).328, but in practice it is only slightly more than log N. Thus, the height of an AVL tree with N nodes is at about log N. It is well-known that the largest unsigned integer represented by k bits is 2 k. Thus, if log N = 2 k then k = log( log N + ). So, it requires log( log N + ) bits of memory to store an integer (i.e., the height) with the value log N. (b) Let h be the height of the smallest AVL tree that uses a k-bits counter to store its height, where k 8. From (a), we know that h = log N and log( log N + ) = k 8. Thus, we obtain log(h + ) 8, and it implies h 2 8 = 255. So, the desired AVL tree is an AVL tree with height at least 255.

22 Problem DS Two trees, T and T 2, are isomorphic if T can be transformed into T 2 by swapping left and right children of (some of the) nodes in T. For instance, the two trees in the following figure are isomorphic because they are the same if the children of A, B, and G, but not the other nodes, are swapped. A A B C C B D E G G E D F H H F (a) Give a polynomial time algorithm to decide if two trees are isomorphic. (b) What is the running time of your program (there is a linear solution)? Solution. (a) #define TRUE #define FALSE 0 int Isomorphic(BinaryTree T, BinaryTree T2) if ( T == NULL && T2 == NULL ) return TRUE; if ( T == NULL && T2!= NULL ) return FALSE; if ( T!= NULL && T2 == NULL) return FALSE; if (T->Element!= T2->Element ) return FALSE; return (Isomorphic(T->Left,T2->Left) && Isomorphic(T->Right,T2->Right)) (Isomorphic(T->Left,T2->Right) && Isomorphic(T->Right,T2->Left)); (b) The function shown above is clearly a linear time routine because in the worst case it does a traversal on both T and T 2 at most twice.

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

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. DATA STRUCUTRES A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. An algorithm, which is a finite sequence of instructions, each of which

More information

UNIT III BALANCED SEARCH TREES AND INDEXING

UNIT III BALANCED SEARCH TREES AND INDEXING UNIT III BALANCED SEARCH TREES AND INDEXING OBJECTIVE The implementation of hash tables is frequently called hashing. Hashing is a technique used for performing insertions, deletions and finds in constant

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

Analyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]:

Analyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]: CSE 101 Homework 1 Background (Order and Recurrence Relations), correctness proofs, time analysis, and speeding up algorithms with restructuring, preprocessing and data structures. Due Thursday, April

More information

p Write a program to evaluate a postfix expression. #ifndef _Stack_H #define _Stack_H #define ElementType double

p Write a program to evaluate a postfix expression. #ifndef _Stack_H #define _Stack_H #define ElementType double p.81 3.19 Write a program to evaluate a postfix expression. #ifndef _Stack_H #define _Stack_H #define ElementType double struct Node; typedef struct Node *PtrToNode; typedef PtrToNode Stack; int IsEmpty(Stack

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

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

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to

More information

Trees. A tree is a directed graph with the property

Trees. A tree is a directed graph with the property 2: Trees Trees A tree is a directed graph with the property There is one node (the root) from which all other nodes can be reached by exactly one path. Seen lots of examples. Parse Trees Decision Trees

More information

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof.

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof. Priority Queues 1 Introduction Many applications require a special type of queuing in which items are pushed onto the queue by order of arrival, but removed from the queue based on some other priority

More information

Data Structures Question Bank Multiple Choice

Data Structures Question Bank Multiple Choice Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution

More information

Data Structure - Stack and Queue-

Data Structure - Stack and Queue- Data Structure - Stack and Queue- Hanyang University Jong-Il Park STACK Stack ADT List that insertions and deletions can be performed at the end of the list Operations Push(X, S): insert X in the list

More information

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A; How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A; } if (n

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

Data Structures. and. Algorithm Analysis in C. (second edition)

Data Structures. and. Algorithm Analysis in C. (second edition) Data Structures and Algorithm Analysis in C (second edition) Solutions Manual Mark Allen Weiss Florida International University Preface Included in this manual are answers to most of the exercises in the

More information

Computer Science 302 Spring 2007 Practice Final Examination: Part I

Computer Science 302 Spring 2007 Practice Final Examination: Part I Computer Science 302 Spring 2007 Practice Final Examination: Part I Name: This practice examination is much longer than the real final examination will be. If you can work all the problems here, you will

More information

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

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# # 1. Prove that n log n n is Ω(n). York University EECS 11Z Winter 1 Problem Set 3 Instructor: James Elder Solutions log n n. Thus n log n n n n n log n n Ω(n).. Show that n is Ω (n log n). We seek a c >,

More information

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees (& Heaps) Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Spring 2015 Jill Seaman 1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root -

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

DDS Dynamic Search Trees

DDS Dynamic Search Trees DDS Dynamic Search Trees 1 Data structures l A data structure models some abstract object. It implements a number of operations on this object, which usually can be classified into l creation and deletion

More information

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example. Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except

More information

Solutions. (a) Claim: A d-ary tree of height h has at most 1 + d +...

Solutions. (a) Claim: A d-ary tree of height h has at most 1 + d +... Design and Analysis of Algorithms nd August, 016 Problem Sheet 1 Solutions Sushant Agarwal Solutions 1. A d-ary tree is a rooted tree in which each node has at most d children. Show that any d-ary tree

More information

NET/JRF-COMPUTER SCIENCE & APPLICATIONS. Time: 01 : 00 Hour Date : M.M. : 50

NET/JRF-COMPUTER SCIENCE & APPLICATIONS. Time: 01 : 00 Hour Date : M.M. : 50 1 NET/JRF-COMPUTER SCIENCE & APPLICATIONS UNIT TEST : DATA STRUCTURE Time: 01 : 00 Hour Date : 02-06-2017 M.M. : 50 INSTRUCTION: Attempt all the 25 questions. Each question carry TWO marks. 1. Consider

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

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 5.1 Introduction You should all know a few ways of sorting in O(n log n)

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

Data Structures and Algorithms Key to Homework 1

Data Structures and Algorithms Key to Homework 1 Data Structures and Algorithms Key to Homework 1 January 31, 2005 15 Define an ADT for a set of integers (remember that a set may not contain duplicates) Your ADT should consist of the functions that can

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

CS 315 Data Structures Spring 2012 Final examination Total Points: 80

CS 315 Data Structures Spring 2012 Final examination Total Points: 80 CS 315 Data Structures Spring 2012 Final examination Total Points: 80 Name This is an open-book/open-notes exam. Write the answers in the space provided. Answer for a total of 80 points, including at least

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS DATA STRUCTURES AND ALGORITHMS For COMPUTER SCIENCE DATA STRUCTURES &. ALGORITHMS SYLLABUS Programming and Data Structures: Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees, binary

More information

8. Binary Search Tree

8. Binary Search Tree 8 Binary Search Tree Searching Basic Search Sequential Search : Unordered Lists Binary Search : Ordered Lists Tree Search Binary Search Tree Balanced Search Trees (Skipped) Sequential Search int Seq-Search

More information

Assume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F].

Assume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F]. Question Assume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F]. a) Draw the linked node structure of L, including

More information

CSL 201 Data Structures Mid-Semester Exam minutes

CSL 201 Data Structures Mid-Semester Exam minutes CL 201 Data tructures Mid-emester Exam - 120 minutes Name: Roll Number: Please read the following instructions carefully This is a closed book, closed notes exam. Calculators are allowed. However laptops

More information

CP2 Revision. theme: dynamic datatypes & data structures

CP2 Revision. theme: dynamic datatypes & data structures CP2 Revision theme: dynamic datatypes & data structures structs can hold any combination of datatypes handled as single entity struct { }; ;

More information

Data Structure - Advanced Topics in Tree -

Data Structure - Advanced Topics in Tree - Data Structure - Advanced Topics in Tree - AVL, Red-Black, B-tree Hanyang University Jong-Il Park AVL TREE Division of Computer Science and Engineering, Hanyang University Balanced binary trees Non-random

More information

CSE 530A. B+ Trees. Washington University Fall 2013

CSE 530A. B+ Trees. Washington University Fall 2013 CSE 530A B+ Trees Washington University Fall 2013 B Trees A B tree is an ordered (non-binary) tree where the internal nodes can have a varying number of child nodes (within some range) B Trees When a key

More information

Final Examination. Algorithms & Data Structures II ( )

Final Examination. Algorithms & Data Structures II ( ) Final Examination Algorithms & Data Structures II (9.12.2014) 1. (12%) What is the running time of the following algorithms? Assume the number of elements is N in Questions a-c, and the graph in Question

More information

Priority Queues. T. M. Murali. January 29, 2009

Priority Queues. T. M. Murali. January 29, 2009 Priority Queues T. M. Murali January 29, 2009 Motivation: Sort a List of Numbers Sort INSTANCE: Nonempty list x 1, x 2,..., x n of integers. SOLUTION: A permutation y 1, y 2,..., y n of x 1, x 2,..., x

More information

S.E. Sem. III [INFT] Data Structures & Analysis. Primitive Linear Non Linear

S.E. Sem. III [INFT] Data Structures & Analysis. Primitive Linear Non Linear S.E. Sem. III [INFT] Data Structures & Analysis Time : 3 Hrs.] Prelim Paper Solution [Marks : 80 Q.1(a) Explain different types of data structures with examples. [5] Ans.: Types of Data Structure : Data

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS DATA STRUCTURES AND ALGORITHMS UNIT 1 - LINEAR DATASTRUCTURES 1. Write down the definition of data structures? A data structure is a mathematical or logical way of organizing data in the memory that consider

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure Model wer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in

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

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once. Chapter 8. Sorting in Linear Time Types of Sort Algorithms The only operation that may be used to gain order information about a sequence is comparison of pairs of elements. Quick Sort -- comparison-based

More information

4. Trees. 4.1 Preliminaries. 4.2 Binary trees. 4.3 Binary search trees. 4.4 AVL trees. 4.5 Splay trees. 4.6 B-trees. 4. Trees

4. Trees. 4.1 Preliminaries. 4.2 Binary trees. 4.3 Binary search trees. 4.4 AVL trees. 4.5 Splay trees. 4.6 B-trees. 4. Trees 4. Trees 4.1 Preliminaries 4.2 Binary trees 4.3 Binary search trees 4.4 AVL trees 4.5 Splay trees 4.6 B-trees Malek Mouhoub, CS340 Fall 2002 1 4.1 Preliminaries A Root B C D E F G Height=3 Leaves H I J

More information

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

) $ f ( n)  %( g( n) CSE 0 Name Test Spring 008 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to compute the sum of the n elements of an integer array is: # A.

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE TED (10)-3071 Reg. No.. (REVISION-2010) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours (Maximum marks: 100)

More information

S.E. Sem. III [CMPN] Data Structures. Primitive Linear Non Linear

S.E. Sem. III [CMPN] Data Structures. Primitive Linear Non Linear S.E. Sem. III [CMPN] Data Structures Time : 3 Hrs.] Prelim Paper Solution [Marks : 80 Q.1(a) Explain different types of data structures with examples. [5] Ans.: Types of Data Structure : Data Structures

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

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

(b) int count = 0; int i = 1; while (i<m) { for (int j=i; j<n; j++) { count = count + 1; i = i + 1; O(M + N 2 ) (c) int count = 0; int i,j,k; for (i=1

(b) int count = 0; int i = 1; while (i<m) { for (int j=i; j<n; j++) { count = count + 1; i = i + 1; O(M + N 2 ) (c) int count = 0; int i,j,k; for (i=1 CPS 100 Exam 2 Solutions Spring 199 Dr Rodger 1 (3 pts) A virtual function in C++ is bound dynamically or statically? dynamic 2 (3 pts) When does one use a class template in C++? Templates are used to

More information

CS 216 Exam 1 Fall SOLUTION

CS 216 Exam 1 Fall SOLUTION CS 216 Exam 1 Fall 2004 - SOLUTION Name: Lab Section: Email Address: Student ID # This exam is closed note, closed book. You will have an hour and fifty minutes total to complete the exam. You may NOT

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

Algorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48

Algorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48 Algorithm Analysis (Algorithm Analysis ) Data Structures and Programming Spring 2018 1 / 48 What is an Algorithm? An algorithm is a clearly specified set of instructions to be followed to solve a problem

More information

COMP Data Structures

COMP Data Structures COMP 2140 - Data Structures Shahin Kamali Topic 5 - Sorting University of Manitoba Based on notes by S. Durocher. COMP 2140 - Data Structures 1 / 55 Overview Review: Insertion Sort Merge Sort Quicksort

More information

Part 2: Balanced Trees

Part 2: Balanced Trees Part 2: Balanced Trees 1 AVL Trees We could dene a perfectly balanced binary search tree with N nodes to be a complete binary search tree, one in which every level except the last is completely full. A

More information

Section 1: True / False (2 points each, 30 pts total)

Section 1: True / False (2 points each, 30 pts total) Section 1: True / False (2 points each, 30 pts total) Circle the word TRUE or the word FALSE. If neither is circled, both are circled, or it impossible to tell which is circled, your answer will be considered

More information

Priority Queues. T. M. Murali. January 23, T. M. Murali January 23, 2008 Priority Queues

Priority Queues. T. M. Murali. January 23, T. M. Murali January 23, 2008 Priority Queues Priority Queues T. M. Murali January 23, 2008 Motivation: Sort a List of Numbers Sort INSTANCE: Nonempty list x 1, x 2,..., x n of integers. SOLUTION: A permutation y 1, y 2,..., y n of x 1, x 2,..., x

More information

3137 Data Structures and Algorithms in C++

3137 Data Structures and Algorithms in C++ 3137 Data Structures and Algorithms in C++ Lecture 4 July 17 2006 Shlomo Hershkop 1 Announcements please make sure to keep up with the course, it is sometimes fast paced for extra office hours, please

More information

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19 CSE34T/CSE549T /05/04 Lecture 9 Treaps Binary Search Trees (BSTs) Search trees are tree-based data structures that can be used to store and search for items that satisfy a total order. There are many types

More information

Binary Search Trees. Contents. Steven J. Zeil. July 11, Definition: Binary Search Trees The Binary Search Tree ADT...

Binary Search Trees. Contents. Steven J. Zeil. July 11, Definition: Binary Search Trees The Binary Search Tree ADT... Steven J. Zeil July 11, 2013 Contents 1 Definition: Binary Search Trees 2 1.1 The Binary Search Tree ADT.................................................... 3 2 Implementing Binary Search Trees 7 2.1 Searching

More information

COMP : Trees. COMP20012 Trees 219

COMP : Trees. COMP20012 Trees 219 COMP20012 3: Trees COMP20012 Trees 219 Trees Seen lots of examples. Parse Trees Decision Trees Search Trees Family Trees Hierarchical Structures Management Directories COMP20012 Trees 220 Trees have natural

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

THE UNIVERSITY OF WESTERN AUSTRALIA

THE UNIVERSITY OF WESTERN AUSTRALIA THE UNIVERSITY OF WESTERN AUSTRALIA MID SEMESTER EXAMINATION April 2018 DEPARTMENT OF COMPUTER SCIENCE & SOFTWARE ENGINEERING DATA STRUCTURES AND ALGORITHMS CITS2200 This Paper Contains: 6 Pages 10 Questions

More information

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1 QUESTION BANK ON COURSE: 304: PRELIMINARIES: 1. What is array of pointer, explain with appropriate example? 2 2. Differentiate between call by value and call by reference, give example. 3. Explain pointer

More information

CS 223: Data Structures and Programming Techniques. Exam 2

CS 223: Data Structures and Programming Techniques. Exam 2 CS 223: Data Structures and Programming Techniques. Exam 2 Instructor: Jim Aspnes Work alone. Do not use any notes or books. You have approximately 75 minutes to complete this exam. Please write your answers

More information

Trees, Part 1: Unbalanced Trees

Trees, Part 1: Unbalanced Trees Trees, Part 1: Unbalanced Trees The first part of this chapter takes a look at trees in general and unbalanced binary trees. The second part looks at various schemes to balance trees and/or make them more

More information

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017 CS 137 Part 8 Merge Sort, Quick Sort, Binary Search November 20th, 2017 This Week We re going to see two more complicated sorting algorithms that will be our first introduction to O(n log n) sorting algorithms.

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

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech

More information

CS102 Binary Search Trees

CS102 Binary Search Trees CS102 Binary Search Trees Prof Tejada 1 To speed up insertion, removal and search, modify the idea of a Binary Tree to create a Binary Search Tree (BST) Binary Search Trees Binary Search Trees have one

More information

Why Do We Need Trees?

Why Do We Need Trees? CSE 373 Lecture 6: Trees Today s agenda: Trees: Definition and terminology Traversing trees Binary search trees Inserting into and deleting from trees Covered in Chapter 4 of the text Why Do We Need Trees?

More information

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

( D. Θ n. ( ) f n ( ) D. Ο% CSE 0 Name Test Spring 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to run the code below is in: for i=n; i>=; i--) for j=; j

More information

CS 315 Data Structures mid-term 2

CS 315 Data Structures mid-term 2 CS 315 Data Structures mid-term 2 1) Shown below is an AVL tree T. Nov 14, 2012 Solutions to OPEN BOOK section. (a) Suggest a key whose insertion does not require any rotation. 18 (b) Suggest a key, if

More information

Problem. Input: An array A = (A[1],..., A[n]) with length n. Output: a permutation A of A, that is sorted: A [i] A [j] for all. 1 i j n.

Problem. Input: An array A = (A[1],..., A[n]) with length n. Output: a permutation A of A, that is sorted: A [i] A [j] for all. 1 i j n. Problem 5. Sorting Simple Sorting, Quicksort, Mergesort Input: An array A = (A[1],..., A[n]) with length n. Output: a permutation A of A, that is sorted: A [i] A [j] for all 1 i j n. 98 99 Selection Sort

More information

Section 1: True / False (1 point each, 15 pts total)

Section 1: True / False (1 point each, 15 pts total) Section : True / False ( point each, pts total) Circle the word TRUE or the word FALSE. If neither is circled, both are circled, or it impossible to tell which is circled, your answer will be considered

More information

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION DESIGN AND ANALYSIS OF ALGORITHMS Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION http://milanvachhani.blogspot.in EXAMPLES FROM THE SORTING WORLD Sorting provides a good set of examples for analyzing

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

CSci 231 Final Review

CSci 231 Final Review CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.

More information

The divide and conquer strategy has three basic parts. For a given problem of size n,

The divide and conquer strategy has three basic parts. For a given problem of size n, 1 Divide & Conquer One strategy for designing efficient algorithms is the divide and conquer approach, which is also called, more simply, a recursive approach. The analysis of recursive algorithms often

More information

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

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

More information

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

End-Term Examination Second Semester [MCA] MAY-JUNE 2006 (Please write your Roll No. immediately) Roll No. Paper Code: MCA-102 End-Term Examination Second Semester [MCA] MAY-JUNE 2006 Subject: Data Structure Time: 3 Hours Maximum Marks: 60 Note: Question 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

Linked Data Structures. Linked lists. Readings: CP:AMA The primary goal of this section is to be able to use linked lists and trees.

Linked Data Structures. Linked lists. Readings: CP:AMA The primary goal of this section is to be able to use linked lists and trees. Linked Data Structures Readings: CP:AMA 17.5 The primary goal of this section is to be able to use linked lists and trees. CS 136 Winter 2018 11: Linked Data Structures 1 Linked lists Racket s list type

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure using C Model wer Subject Code: 22317 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given

More information

O(n): printing a list of n items to the screen, looking at each item once.

O(n): printing a list of n items to the screen, looking at each item once. UNIT IV Sorting: O notation efficiency of sorting bubble sort quick sort selection sort heap sort insertion sort shell sort merge sort radix sort. O NOTATION BIG OH (O) NOTATION Big oh : the function f(n)=o(g(n))

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 Spring 2012 7p-9p, Tuesday, April 3 Name: NetID: Lab Section

More information

W4231: Analysis of Algorithms

W4231: Analysis of Algorithms W4231: Analysis of Algorithms From Binomial Heaps to Fibonacci Heaps Fibonacci Heaps 10/7/1999 We first prove that in Binomial Heaps insert and find-min take amortized O(1) time, while still having insert,

More information

Summer Final Exam Review Session August 5, 2009

Summer Final Exam Review Session August 5, 2009 15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding

More information

(D) There is a constant value n 0 1 such that B is faster than A for every input of size. n n 0.

(D) There is a constant value n 0 1 such that B is faster than A for every input of size. n n 0. Part : Multiple Choice Enter your answers on the Scantron sheet. We will not mark answers that have been entered on this sheet. Each multiple choice question is worth. marks. Note. when you are asked to

More information

Remember to also pactice: Homework, quizzes, class examples, slides, reading materials.

Remember to also pactice: Homework, quizzes, class examples, slides, reading materials. Exam 1 practice problems Remember to also pactice: Homework, quizzes, class examples, slides, reading materials. P1 (MC) For all the questions below (except for the True or False questions), the answer

More information

Total Points: 60. Duration: 1hr

Total Points: 60. Duration: 1hr CS800 : Algorithms Fall 201 Nov 22, 201 Quiz 2 Practice Total Points: 0. Duration: 1hr 1. (,10) points Binary Heap. (a) The following is a sequence of elements presented to you (in order from left to right):

More information

COMP 250 Fall Solution - Homework #4

COMP 250 Fall Solution - Homework #4 COMP 250 Fall 2013 - Solution - Homework #4 1) // Evaluates a single operation static public double apply(string op, double x1, double x2) { if (op.equals("add")) return x1+x2; if (op.equals("mult")) return

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours TED (10)-3071 Reg. No.. (REVISION-2010) (Maximum marks: 100) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours PART

More information

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) _ UWNetID: Lecture Section: A CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will give

More information

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

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

6. Asymptotics: The Big-O and Other Notations

6. Asymptotics: The Big-O and Other Notations Chapter 7 SEARCHING 1. Introduction, Notation 2. Sequential Search 3. Binary Search 4. Comparison Trees 5. Lower Bounds 6. Asymptotics: The Big-O and Other Notations Outline Transp. 1, Chapter 7, Searching

More information

INF2220: algorithms and data structures Series 1

INF2220: algorithms and data structures Series 1 Universitetet i Oslo Institutt for Informatikk A. Maus, R.K. Runde, I. Yu INF2220: algorithms and data structures Series 1 Topic Trees & estimation of running time (Exercises with hints for solution) Issued:

More information

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE A6-R3: DATA STRUCTURE THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered in the TEAR-OFF

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