AS2261 M.Sc.(First Semester) Examination2013 Paper fourth SubjectData structure with algorithm


 Evangeline Peters
 2 years ago
 Views:
Transcription
1 AS2261 M.Sc.(First Semester) Examination2013 Paper fourth SubjectData structure with algorithm Time: Three Hours] [Maximum Marks: 60 Note Attempts all the questions. All carry equal marks Section A (10 2=20) 1.1 The time factor when determining the efficiency of algorithm is measured by a. Counting microseconds b. counting the number of key operations c. Counting the number of statements. d. Counting the kilobytes of algorithm Ans. b. counting the number of key operations 1.2 The number of nodes in a complete binary tree of depth d (with root at depth 0) is. Ans. 2 d The average case of quick sort has order Ans. O(n log n) 1.4 Inorder to get the information stored in a BST in the descending order, one should traverse it in which of the following order? (A) left, root, right (B) root, left, right (C) right, root, left (D) right, left, root Ans. (C) right, root, left 1.5 Every internal node in a Btree of minimum degree 2 can have (A) 2, 3 or 4 children (B) 1, 2 or 3 children (C) 2, 4 or 6 children (D) 0, 2 or 4 children Ans. (B) 1, 2 or 3 children 1.6 A full binary tree with 'n' nonleaf nodes contains..total nodes (leaf+non leaf) Ans. 2n+1 nodes 1.7 In tree the difference between the height of the left sub tree and height of right sub tree, for each node, is not more than one Ans. AVL 1.8 The number of comparisons required to sort 5 numbers in ascending order using bubble sort is. (A) 7 (B) 6 (C) 10 (D) 5 Ans. (C ) In a binary tree, the number of terminal or leaf nodes is 10. The number of nodes with two children is. Ans The complexity of Binary search algorithm is. Ans. O( log n)
2 Section B (4 10=40) Attempt any four questions out of seven. All carry equal marks (4 10=40) 2. Sort the given values using Quick Sort Ans. Here 65 is pivot element at 0 th position, let p is a index which position is at 1 st position element that is 70 and another index q which position is at last element that is 45. Now p will search an element whose value is greater than 65 and q will search al element whose value is less than 65, in this way p will increment by 1 and q will decrement by 1, and when these values are found, they will interchanged, and if p and q are meet or crossover then value at q will exchange with pivot element in this way the list is divided into two part in first part all the elements are less than qth position element and in next part all the values are greater than qth position element. Now apply the same procedure to each part. Applying this procedure step by step we will got the following sorted elements. First 70 is greater than 65 and 45 is less than 65, so 70 and 45 are interchanged Now p will be at 75 which is greater than 65 and q will be at 50 less than 65 so again exchange Now p is at 80 greater than 65 and q will be at 55 less than 65 so again exchange Now p is at 85 greater than 65, and q at 60 less than 65, so again exchange Now here p and q crossover to each other so value at q that is 60 will exchange with pivot element that is 65 and we get Here the list is divided into two parts, one containing all elements less than 65 and other containing all elements greater than 65. Now apply same procedure step by step, and we get the following sorted list What is bubble sort and how do you perform it also write the algorithm? Ans. In bubble sort, each element is compared with its adjacent element. If the first element is larger than the second one, then the positions of the elements are interchanged, otherwise it is not changed. Then next element is compared with its adjacent element and the same process is repeated for all the elements in the array until we get a sorted array.
3 Let A be a linear array of n numbers. Sorting of A means rearranging the elements of A so that they are in order. Here we are dealing with ascending order. i.e., A[1] < A[2] < A[3] <... A[n]. Suppose the list of numbers A[1], A[2], A[n] is an element of array A. The bubble sort algorithm works as follows: Step 1: Compare A[1] and A[2] and arrange them in the (or desired) ascending order, so that A[1] < A[2].that is if A[1] is greater than A[2] then interchange the position of data by swap = A[1]; A[1] = A[2]; A[2] = swap. Then compare A[2] and A[3] and arrange them so that A[2] < A[3]. Continue the process until we compare A[N 1] with A[N]. Note: Step1 contains n 1 comparisons i.e., the largest element is bubbled up to the nth position or sinks to the nth position. When step 1 is completed A[N] will contain the largest element. Step 2: Repeat step 1 with one less comparisons that is, now stop comparison at A [n 1] and possibly rearrange A[N 2] and A[N 1] and so on. Note: in the first pass, step 2 involves n 2 comparisons and the second largest element will occupy A[n1]. And in the second pass, step 2 involves n 3 comparisons and the 3rd largest element will occupy A[n 2] and so on. Step n 1: compare A[1]with A[2] and arrange them so that A[1] < A[2] After n 1 steps, the array will be a sorted array in increasing (or ascending) order. The following figures will depict the various steps (or PASS) involved in the sorting of an array of 5 elements. The elements of an array A to be sorted are: 42, 33, 23, 74, 44 ALGORITHM Let A be a linear array of n numbers. Swap is a temporary variable for swapping (or interchange) the position of the numbers. 1. Input n numbers of an array A 2. Initialise i = 0 and repeat through step 4 if (i < n) 3. Initialize j = 0 and repeat through step 4 if (j < n i 1) 4. If (A[j] > A[j + 1]) (a) Swap = A[j] (b) A[j] = A[j + 1] (c) A[j + 1] = Swap 5. Display the sorted numbers of array A 6. Exit. TIME COMPLEXITY The time complexity for bubble sort is calculated in terms of the number of comparisons f (n) (or of number of loops); here two loops (outer loop and inner loop) iterates (or repeated) the comparisons. The number of times the outer loop iterates is determined by the number of elements in the list which is asked to sort (say it is n). The inner
4 loop is iterated one less than the number of elements in the list (i.e., n1 times) and is reiterated upon every iteration of the outer loop f (n) = (n 1) + (n 2) = n(n 1) = O(n2). BEST CASE In this case you are asked to sort a sorted array by bubble sort algorithm. The inner loop will iterate with the if condition evaluating time that is the swap procedure is never called. In best case outer loop will terminate after one iteration, i.e., it involves performing one pass, which requires n 1 comparisons f (n) = O(n) WORST CASE In this case the array will be an inverted list (i.e., 5, 4, 3, 2, 1, 0). Here to move first element to the end of the array, n 1 times the swapping procedure is to be called. Every other element in the list will also move one location towards the start or end of the loop on every iteration. Thus n times the outer loop will iterate and n (n1) times the inner loop will iterate to sort an inverted array f(n) = (n(n 1))/2 = O(n2). AVERAGE CASE Average case is very difficult to analyse than the other cases. In this case the input data(s) are randomly placed in the list. The exact time complexity can be calculated only if we know the number of iterations, comparisons and swapping. In general, the complexity of average case is: f(n) = (n(n 1))/2 = O(n2). 4. Describe warshall s algorithm with example. Ans. Warshall s Algorithm Let G be directed weighted graph with m nodes v1,v2,..vm. Suppose we want to find the path matrix P of the graph G. warshall gave an algorithm for this purpose. First we define msquare Boolean matrices P0, P1,P2,..Pm as follows. Let Pk[i,j] denote the ij entry of the matrix Pk, Then we define : 1 if there is simple path from vi to vj which does not use any other nodes except possibly v1,v2 vk Pk[i,j] = 0 otherwise In other words, P0[i,j]=1 if there is an edge from vi to vj P1[i,j]=1 if there is a simple path from vi to vj which does not use any other nodes except possibly v1 P2[i,j]=1 if there is a simple path from vi to vj which does not use any other nodes except possibly v1 and v2. Here we observe that the matrix P0= A the adjacency matrix of G. and since G has m nodes, the last matrix Pm=P, the path matrix of G. Warshall observe that Pk[i,j] =1 can occur only if one of the following two cases occurs:
5 Write any example. 5. Describe insertion in heap tree with example. Ans A heap is defined as an almost complete binary tree of n nodes such that the value of each node is less than or equal to the value of the father. It can be sequentially represented as A[ j] <= A[( j 1)/2] for 0 <= [( j 1)/2] < j <= n 1 The root of the binary tree (i.e., the first array element) holds the largest key in the heap. This type of heap is usually called descending heap or mere heap, as the path from the root node to a terminal node forms an ordered list of elements arranged in descending order. Following fig shows a heap
6 We can also define an ascending heap as an almost complete binary tree in which the value of each node is greater than or equal to the value of its father. This root node has the smallest element of the heap. This type of heap is also called min heap. A heap H can be created from the following list of numbers 33, 42, 67, 23, 44, 49, 74 as illustrated below : Step 1: Create a node to insert the first number (i.e., 33) as shown Fig below Step 2: Read the second element and add as the left child of 33 as shown Fig Then restructure the heap if necessary Compare the 42 with its parent 33, since newly added node (i.e., 42) is greater than 33 interchange node information as shown Fig Step 3: Read the 3rd element and add as the right child of 42 as shown Fig Then restructure the heap if necessary Compare the 67 with its parent 42, since newly added node (i.e., 67) is greater than 42 interchange node information as shown Fig. Step 4: Read the 4th element and add as the left child of 33 as shown below. Then restructure the heap if necessary.
7 Since newly added node (i.e., 23) is less than its parent 33, no interchange. Step 5: Read the 5th element and add as the right child of 33 as shown below. Then restructure the heap if necessary Compare the 44 with its parent 33, since newly added node (i.e., 44) is greater than 33 interchange node information as shown Step 6: Read the 6th element and add as the left child of 42 as shown below. Then restructure the heap if necessary. Compare the (newly added node) 49 with its parent 42, since newly added node (i.e.49) is greater than 42 interchange node information as shown Fig Step 7: Read the 7th element and add as the left child of 49 as shown below. Then restructure the heap if necessary.
8 Compare the (newly added node) 74 with its parent 49, since newly added node (i.e. 74) is greater than 49 interchange node information as shown below. Compare the recently changed node 74 with its parent 67, since it is greater than 67 interchange node information as shown below ALGORITHM Let H be a heap with n elements stored in the array HA. This procedure will insert a new element data in H. LOC is the present location of the newly added node. And PAR denotes the location of the parent of the newly added node. 1. Input n elements in the heap H. 2. Add new node by incrementing the size of the heap H: n = n + 1 and LOC = n 3. Repeat step 4 to 7 while (LOC < 1) 4. PAR = LOC/2 5. If (data <= HA[PAR]) (a) HA[LOC] = data (b) Exit 6. HA[LOC] = HA[PAR] 7. LOC = PAR 8. HA[1] = data 9. Exit 6. Describe deletion operation in AVL tree with example. Ans. This algorithm was developed in 1962 by two Russian Mathematicians, G.M. Adel son Vel sky and E.M. Landis; here the tree is called AVL Tree. An AVL tree is a binary search tree in which the left and right sub tree of any node may differ in height by at most 1, and in which both the sub trees are themselves AVL Trees. Each node in the AVL Tree possesses any one of the following properties: (a) A node is called left heavy, if the largest path in its left sub tree is one level larger than the largest path of its right sub tree. (b) A node is called right heavy, if the largest path in its right sub tree is one level larger than the largest path of its left sub tree. (c) The node is called balanced, if the largest paths in both the right and left sub trees are may differ in height by at most 1. Example of AVL tree
9 This section gives an algorithm to delete a DATA of information from a binary search tree. First search and locate the node to be deleted. Then any one of the following conditions arises: 1. The node to be deleted has no children 2. The node has exactly one child (or sub tress, left or right sub tree) 3. The node has two children (or two sub tress, left and right sub tree) Suppose the node to be deleted is N. If N has no children then simply delete the node and place its parent node by the NULL pointer. If N has one child, check whether it is a right or left child. If it is a right child, then find the smallest element from the corresponding right sub tree. Then replace the smallest node information with the deleted node. If N has a left child, find the largest element from the corresponding left sub tree. Then replace the largest node information with the deleted node. The same process is repeated if N has two children, i.e., left and right child. Randomly select a child and find the small/large node and replace it with deleted node. NOTE that the tree that we get after deleting a node should also be a binary search tree. Deleting a node can be illustrated with an example. Consider a binary search tree in Fig. 1. If we want to delete 75 from the tree, following steps are obtained: Step 1: Assign the data to be deleted in DATA and NODE = ROOT. Step 2: Compare the DATA with ROOT node, i.e., NODE, information of the tree. Since (50 < 75) NODE = NODE RChild Step 3: Compare DATA with NODE. Since (75 = 75) searching successful. Now we have located the data to be deleted, and delete the DATA. (See following fig 2) Fig. 1
10 Fig. 2 Step 4: Since NODE (i.e., node where value was 75) has both left and right child choose one. (Say Right Sub Tree)  If right sub tree is opted then we have to find the smallest node. But if left sub tree is opted then we have to find the largest node. Step 5: Find the smallest element from the right sub tree (i.e., 80) and replace the node with deleted node. (See Fig. 3) Fig. 3 Step 6: Again the (Node> Rchild is not equal to NULL) find the smallest element from the right subtree which is 85 and replace it with emty nodes fig 4 Fig 4 Step 7 : Since (Node> Rchild= Node>Lchild=Null) delete the NODE and place NULL in the parent node. Fig. 5
11 Step 8: Exit Fig 5 ALGORITHM NODE is the current position of the tree, which is in under consideration. LOC is the place where node is to be replaced. DATA is the information of node to be deleted. 1. Find the location NODE of the DATA to be deleted. 2. If (NODE = NULL) (a) Display DATA is not in tree (b) Exit 3. If(NODE Lchild = NULL) (a) LOC = NODE (b) NODE = NODE RChild 4. If(NODE RChild= =NULL) (a) LOC = NODE (b) NODE = NODE LChild 5. If((NODE Lchild not equal to NULL) && (NODE Rchild not equal to NULL)) (a) LOC = NODE RChild 6. While(LOC Lchild not equal to NULL) (a) LOC = LOC Lchild 7. LOC Lchild = NODE Lchild 8. LOC RChild= NODE RChild 9. Exit 7. Write the algorithm of deletion at rear end in dequeue with example. Ans. A deque is a homogeneous list in which elements can be added or inserted (called push operation) and deleted or removed from both the ends (which is called pop operation). ie; we can add a new element at the rear or front end and also we can remove an element from both front and rear end. Hence it is called Double Ended Queue. There are two types of deque depending upon the restriction to perform insertion or deletion operations at the two ends. They are 1. Input restricted deque 2. Output restricted deque An input restricted deque is a deque, which allows insertion at only 1 end, rear end, but allows deletion at both ends, rear and front end of the lists. An outputrestricted deque is a deque, which allows deletion at only one end, front end, but allows insertion at both ends, rear and front ends, of the lists.
12 The possible operation performed on deque is 1. Add an element at the rear end 2. Add an element at the front end 3. Delete an element from the front end 4. Delete an element from the rear end Let Q be the array of MAX elements. front (or left) and rear (or right) are two array index (pointers), where the addition and deletion of elements occurred. DATA will contain the element just deleted. DELETE AN ELEMENT FROM THE RIGHT SIDE or REAR END or RIGHT MOST OF THE DEQUEUE 1. If (left == 1) (a) Display Queue Underflow (b) Exit 2. DATA = Q [right] 3. If (left == right) (a) left = 1 (b) right = 1 4. Else (a) if(right == 0) (i) right = MAX1 (b) else (i) right = right1 5. Exit Example User can take any list of element in de queue and show with the help of algorithm that how the elements are deleted from the rear end 8. Write the algorithm of prefix evaluation with example. Ans. Following algorithm finds the RESULT of an arithmetic expression P written in prefix notation. The following algorithm, which uses a STACK to hold operands, evaluates P. Algorithm 1. Scan P from right to left and repeat Steps 2 and 3 for each element of P until the P is finished. 2. If an operand is encountered, put it on STACK. 3. If an operator is encountered, then: (a) Remove the two top elements of STACK, where A is the top element and B is the nexttotop element. (b) Evaluate A operator B. (c) Place the result on to the STACK. 4. Result equal to the top element on STACK. 5. Exit. Example * Scan from right to left 2. Scanned symbol is 2 (an operand), push onto stack 3. Next scanned symbol is 3 (an operand), push onto stack 4. Next scanned symbol is * (an operator), pop two topmost element from stack and evaluate with *, i.e. 3*2= Prefix expression is finished, so result is 6
TREE BASIC TERMINOLOGIES
TREE Trees are very flexible, versatile and powerful nonliner data structure that can be used to represent data items possessing hierarchical relationship between the grand father and his children and
More informationGraph. Consider a graph, G in Fig Then the vertex V and edge E can be represented as:
Graph A graph G consist of 1. Set of vertices V (called nodes), (V = {v1, v2, v3, v4...}) and 2. Set of edges E (i.e., E {e1, e2, e3...cm} A graph can be represents as G = (V, E), where V is a finite and
More information12 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).
More informationModule 2 Stacks and Queues: Abstract Data Types
Module 2 Stacks and Queues: Abstract Data Types A stack is one of the most important and useful nonprimitive linear data structure in computer science. It is an ordered collection of items into which
More informationBinary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *
Binary Heaps A binary heap is another data structure. It implements a priority queue. Priority Queue has the following operations: isempty add (with priority) remove (highest priority) peek (at highest
More informationCOURSE: B.TECHECE. IV Sem. Data structure Using C. b) Deletion of element in an array
COURSE: B.TECHECE. IV Sem Data structure Using C 1. Determine the formula to find the address location of an element in three dimensions array, suppose each element takes four bytes of space & elements
More information5. 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
More information1) 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
More informationAlgorithms and Data Structures
Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. RalfPeter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2
More informationPES Institute of TechnologyBSC QUESTION BANK
PES Institute of TechnologyBSC 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
More informationPrevious Lectures. BTrees. External storage. Two types of memory. Btrees. Main principles
BTrees Algorithms and data structures for external memory as opposed to the main memory BTrees Previous Lectures Height balanced binary search trees: AVL trees, redblack trees. Multiway search trees:
More informationQuestions 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
More information1. 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
More informationDATA 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
More informationData Structures. Topic #9
Data Structures Topic #9 Today s Agenda Continue Discussing Trees Examine the algorithm to insert Examine the algorithm to remove Begin discussing efficiency of tree Are there any alternatives? 23 234
More informationKrishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA213 : 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
More informationBalanced Binary Search Tree
AVL Trees / Slide 1 Balanced Binary Search Tree Worst case height of binary search tree: N1 Insertion, deletion can be O(N) in the worst case We want a tree with small height Height of a binary tree with
More informationTrees and Binary Relations. Debdeep Mukhopadhyay IIT Madras
Trees and Binary Relations Debdeep Mukhopadhyay IIT Madras Outline Tree : definition and its relation with binary relations Properties Expressions: Balancedness Infix, Postfix and Prefix Expression Trees
More informationFrom Last Time: Remove (Delete) Operation
CSE 32 Lecture : More on Search Trees Today s Topics: Lazy Operations Run Time Analysis of Binary Search Tree Operations Balanced Search Trees AVL Trees and Rotations Covered in Chapter of the text From
More informationBTrees. Algorithms and data structures for external memory as opposed to the main memory BTrees. B trees
BTrees Algorithms and data structures for external memory as opposed to the main memory BTrees Previous Lectures Height balanced binary search trees: AVL trees, redblack trees. Multiway search trees:
More informationInternational 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): 22790063 ISSN (Online): 22790071 International
More informationHome Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit
Data Structures Page 1 of 24 A.1. Arrays (Vectors) nelement vector start address + ielementsize 0 +1 +2 +3 +4... +n1 start address continuous memory block static, if size is known at compile time dynamic,
More information1 23 Trees: The Basics
CS10: Data Structures and ObjectOriented Design (Fall 2013) November 1, 2013: 23 Trees: Inserting and Deleting Scribes: CS 10 Teaching Team Lecture Summary In this class, we investigated 23 Trees in
More informationData Structures 2014
Unit1 Introduction Short Questions:1. Define data structure. 2. Define algorithm. 3. List out areas in which data structures are applied. 4. List out structure of algorithm. 5. List out properties of
More informationData 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:
More informationData Structures UNIT III. Model Question Answer
Data Structures UNIT III Model Question Answer Q.1. Define Stack? What are the different primitive operations on Stack? Ans: Stack: A stack is a linear structure in which items may be added or removed
More informationBinary Heaps. CSE 373 Data Structures
Binary Heaps CSE Data Structures Readings Chapter Section. Binary Heaps BST implementation of a Priority Queue Worst case (degenerate tree) FindMin, DeleteMin and Insert (k) are all O(n) Best case (completely
More informationCSE 5311 Homework 2 Solution
CSE 5311 Homework 2 Solution Problem 6.26 Show that the worstcase running time of MAXHEAPIFY on a heap of size n is Ω(lg n). (Hint: For a heap with n nodes, give node values that cause MAX HEAPIFY
More informationOrdered 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 60:
More information10CS35: Data Structures Using C
CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions  a conventional tool for handling a
More information7.1 Introduction. CSci 335 Software Design and Analysis III Chapter 7 Sorting. Prof. Stewart Weiss
Chapter 7 Sorting 7.1 Introduction Insertion sort is the sorting algorithm that splits an array into a sorted and an unsorted region, and repeatedly picks the lowest index element of the unsorted region
More informationComparison Sort.  In Merge Sort, the merge procedure chooses an item from one of two arrays after comparing the top items from both arrays.
Comparison Sort A Comparison Sort is a sorting algorithm where the final order is determined only by comparisons between the input elements.  In Insertion Sort, the proper position to insert the current
More informationBinary 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
More informationNearly Complete Binary Trees and Heaps
Nearly Complete Binary Trees and Heaps DEFINITIONS: i) The depth of a node p in a binary tree is the length (number of edges) of the path from the root to p. ii) The height (or depth) of a binary tree
More informationBinary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( BST) are of the form. P parent. Key. Satellite data L R
Binary Search Trees A Generic Tree Nodes in a binary search tree ( BST) are of the form P parent Key A Satellite data L R B C D E F G H I J The BST has a root node which is the only node whose parent
More informationSorting algorithms. CS 127 Fall A brief diversion: What's on the midterm. Heaps: what to know. Binary trees: What to know
CS 127 Fall 2003 Sorting algorithms A brief diversion: What's on the midterm Same format as last time 5 questions, 20 points each, 100 points total 15% of your grade 2 topics: trees, trees, and more trees
More informationCS2 Final Study Guide
CS2 Final Study Guide  Know how to write an assignment operator, copy constructor and destructor for a simple class that has dynamically allocated memory. Trees 1. Define the following terms o binary
More informationBinary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child
Binary Search Trees Data in each node Larger than the data in its left child Smaller than the data in its right child FIGURE 116 Arbitrary binary tree FIGURE 117 Binary search tree Data Structures Using
More informationTrees & Binary Search Trees
CMSC 132: ObjectOriented Programming II Trees & Binary Search Trees Department of Computer Science University of Maryland, College Park Trees Trees are hierarchical data structures Onetomany relationship
More informationConverting 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
More informationCS0213 DATA STRUCTURES AND ALGORITHM LAB USING C & C++ LABORATORY MANUAL II  CSE III  SEMESTER ACADEMIC YEAR:
CS0213 DATA STRUCTURES AND ALGORITHM LAB USING C & C++ LABORATORY MANUAL II  CSE III  SEMESTER ACADEMIC YEAR: 20122013 SCHOOL OF COMPUTER SCIENCE & ENGINEERING SRM UNIVERSITY, SRM NAGAR, KATTANKULATHUR603203.
More informationMAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) 
=============================================================================================================================== DATA STRUCTURE PSEUDOCODE EXAMPLES (c) Mubashir N. Mir  www.mubashirnabi.com
More informationWhy? A central concept in Computer Science. Algorithms are ubiquitous.
Analysis of Algorithms: A Brief Introduction Why? A central concept in Computer Science. Algorithms are ubiquitous. Using the Internet (sending email, transferring files, use of search engines, online
More informationMultiWay Search Trees (B Trees)
MultiWay Search Trees (B Trees) Multiway Search Trees An mway search tree is a tree in which, for some integer m called the order of the tree, each node has at most m children. If n
More informationIf we want to measure the amount of storage that an algorithm uses as a function of the size of the instances, there is a natural unit available Bit.
(1) Explain why analysis of algorithms is important. When we have a problem to solve, there may be several suitable algorithms available. We would obviously like to choose the best. Analyzing an algorithm
More informationBinary Trees and Binary Search Trees C++ Implementations
Binary Trees and Binary Search Trees C++ Implementations Learning Goals: Apply basic tree definitions to classification problems. Describe the properties of binary trees, binary search trees, and more
More informationCSE 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
More informationAtmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : 572365, 576681 1
Data Structure By Ajay Raiyani Yogidham, Kalawad Road, Rajkot. Ph : 572365, 576681 1 Linked List 4 Singly Linked List...4 Doubly Linked List...7 Explain Doubly Linked list: ...7 Circular Singly Linked
More informationTrees. Tree Definitions: Let T = (V, E, r) be a tree. The size of a tree denotes the number of nodes of the tree.
Trees After lists (including stacks and queues) and hash tables, trees represent one of the most widely used data structures. On one hand trees can be used to represent objects that are recursive in nature
More informationExam 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
More informationAnalysis 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
More informationBinary Search Trees > = Binary Search Trees 1. 2004 Goodrich, Tamassia
Binary Search Trees < 6 2 > = 1 4 8 9 Binary Search Trees 1 Binary Search Trees A binary search tree is a binary tree storing keyvalue entries at its internal nodes and satisfying the following property:
More informationAnalysis of Binary Search algorithm and Selection Sort algorithm
Analysis of Binary Search algorithm and Selection Sort algorithm In this section we shall take up two representative problems in computer science, work out the algorithms based on the best strategy to
More informationAny 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
More informationMultiway Search Tree (MST)
Multiway Search Tree (MST) Generalization of BSTs Suitable for disk MST of order n: Each node has n or fewer subtrees S1 S2. Sm, m n Each node has n1 or fewer keys K1 Κ2 Κm1 : m1 keys in ascending
More informationCSCI Trees. Mark Redekopp David Kempe
1 CSCI 104 23 Trees Mark Redekopp David Kempe 2 Properties, Insertion and Removal BINARY SEARCH TREES 3 Binary Search Tree Binary search tree = binary tree where all nodes meet the property that: All
More informationEE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27
EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27 The Problem Given a set of N objects, do any two intersect? Objects could be lines, rectangles, circles, polygons, or other geometric objects Simple to
More informationData 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:
More informationSize = ub lb + 1. Note that the size of the array = ub if lb=1.
M21: INTRODUCTION: An array is a collection of homogenous data elements (ie elements of same type) described by a single name Each element of an array is referenced by a subscripted variable enclosed in
More information, 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
More informationData Structures Using C++ 2E. Chapter 11 Binary Trees and BTrees
Data Structures Using C++ 2E Chapter 11 Binary Trees and BTrees Binary Trees Definition: a binary tree, T, is either empty or such that T has a special node called the root node T has two sets of nodes,
More informationData Structures and Algorithms
Data Structures and Algorithms CS2452016S06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 060: Ordered List ADT Operations: Insert an element in the list
More informationSymbol Tables. Introduction
Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The
More informationS. Muthusundari. Research Scholar, Dept of CSE, Sathyabama University Chennai, India email: nellailath@yahoo.co.in. Dr. R. M.
A Sorting based Algorithm for the Construction of Balanced Search Tree Automatically for smaller elements and with minimum of one Rotation for Greater Elements from BST S. Muthusundari Research Scholar,
More informationAVL Trees. CSE 373 Data Structures
AVL Trees CSE 373 Data Structures Readings Reading Chapter 1 Section 1.2 AVL Trees 2 Binary Search Tree  Best Time All BST operations are O(d), where d is tree depth minimum d is = log N for a binary
More informationCOT5405 Analysis of Algorithms Homework 3 Solutions
COT0 Analysis of Algorithms Homework 3 Solutions. Prove or give a counter example: (a) In the textbook, we have two routines for graph traversal  DFS(G) and BFS(G,s)  where G is a graph and s is any
More informationUNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK PSD2023 ALGORITHM & DATA STRUCTURE
STUDENT IDENTIFICATION NO UNIVERSITI MALAYSIA SARAWAK 94300 KOTA SAMARAHAN SARAWAK FAKULTI SAINS KOMPUTER & TEKNOLOGI MAKLUMAT (Faculty of Computer Science & Information Technology) Diploma in Multimedia
More informationLecture 3. Reading: Weiss Ch 4, sections 14 CSE 100, UCSD: LEC 3. Page 1 of 22
Lecture 3 Binary search trees Toward a binary search tree implementation using C++ templates C++ iterators and the binary search tree successor function Reading: Weiss Ch 4, sections 14 Page 1 of 22 Binary
More informationIntroduction to Algorithms. Lecture 4
6.006 Introduction to Algorithms Lecture 4 Menu Priority Queues Heaps Heapsort Priority Queue A data structure implementing a set S of elements, each associated with a key, supporting the following operations:
More informationRotation Operation for Binary Search Trees Idea:
Rotation Operation for Binary Search Trees Idea: Change a few pointers at a particular place in the tree so that one subtree becomes less deep in exchange for another one becoming deeper. A sequence of
More informationData Structure with C
Subject: Data Structure with C Topic : Tree Tree A tree is a set of nodes that either:is empty or has a designated node, called the root, from which hierarchically descend zero or more subtrees, which
More informationData Structures, Sample Test Questions for the Material after Test 2, with Answers
Data Structures, Sample Test Questions for the Material after Test 2, with Answers 1. Recall the public interfaces of classes List and ListIterator: typedef int ListItemType; class ListIterator{ public:
More informationProblem. Indexing with Btrees. Indexing. Primary Key Indexing. Btrees. Btrees: Example. primary key indexing
Problem Given a large collection of records, Indexing with Btrees find similar/interesting things, i.e., allow fast, approximate queries Anastassia Ailamaki http://www.cs.cmu.edu/~natassa 2 Indexing Primary
More informationCPSC 211 Data Structures & Implementations (c) Texas A&M University [ 221] edge. parent
CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 221] Trees Important terminology: edge root node parent Some uses of trees: child leaf model arithmetic expressions and other expressions
More informationCMPS 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
More informationQuick Sort with Three Partitions
Ashish Sharma Rengakrishnan Subramanian November 8, 2001 Quick Sort with Three Partitions This paper is concerned with finding a lineartime algorithm for implementing a function pivotbis, which is used
More informationData Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015
Data Structures Jaehyun Park CS 97SI Stanford University June 29, 2015 Typical Quarter at Stanford void quarter() { while(true) { // no break :( task x = GetNextTask(tasks); process(x); // new tasks may
More informationJava Software Structures
INTERNATIONAL EDITION Java Software Structures Designing and Using Data Structures FOURTH EDITION John Lewis Joseph Chase This page is intentionally left blank. Java Software Structures,International Edition
More informationAlgorithms Chapter 6 Heapsort
Algorithms Chapter 6 Heapsort Assistant Professor: Ching Chi Lin 林清池助理教授 chingchi.lin@gmail.com Department of Computer Science and Engineering National Taiwan Ocean University Outline Heaps Maintaining
More informationAlgorithm Efficiency and Sorting
Algorithm Efficiency and Sorting How to Compare Different Problems and Solutions Two different problems Which is harder/more complex? Two different solutions to the same problem Which is better? Questions:
More informationB+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers
B+ Tree and Hashing B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers B+ Tree Properties Balanced Tree Same height for paths
More informationINTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY
INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY A PATH FOR HORIZING YOUR INNOVATIVE WORK A REVIEW ON THE USAGE OF OLD AND NEW DATA STRUCTURE ARRAYS, LINKED LIST, STACK,
More informationAnnouncements. CSE332: Data Abstractions. Lecture 9: B Trees. Today. Our goal. Mary Search Tree. Mary Search Tree. Ruth Anderson Winter 2011
Announcements CSE2: Data Abstractions Project 2 posted! Partner selection due by 11pm Tues 1/25 at the latest. Homework due Friday Jan 28 st at the BEGINNING of lecture Lecture 9: B Trees Ruth Anderson
More information6 March 2007 1. Array Implementation of Binary Trees
Heaps CSE 0 Winter 00 March 00 1 Array Implementation of Binary Trees Each node v is stored at index i defined as follows: If v is the root, i = 1 The left child of v is in position i The right child of
More informationPractice Problems (Midterm)
ECE250 Algorithms and Data Structures (Winter 2012) Practice Problems (Midterm) Disclaimer: Please do keep in mind that this problem set does not reflect the exact topics or the fractions of each of the
More informationroot node level: internal node edge leaf node CS@VT Data Structures & Algorithms 20002009 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
More informationWhy Use Binary Trees?
Binary Search Trees Why Use Binary Trees? Searches are an important application. What other searches have we considered? brute force search (with array or linked list) O(N) binarysearch with a presorted
More informationA binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:
Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)
More informationCMSC 451: Graph Properties, DFS, BFS, etc.
CMSC 451: Graph Properties, DFS, BFS, etc. Slides By: Carl Kingsford Department of Computer Science University of Maryland, College Park Based on Chapter 3 of Algorithm Design by Kleinberg & Tardos. Graphs
More informationdata structures and algorithms exercise class 2: some answers
data structures and algorithms 20162017 exercise class 2: some answers 1. Show step by step how the array A = [22, 15, 36, 20, 3, 9, 29] is sorted using selection sort, bubble sort, and merge sort. First
More informationData Structures. Topic #8
Data Structures Topic #8 Today s Agenda Continue Discussing Table Abstractions But, this time, let s talk about them in terms of new nonlinear data structures trees which require that our data be organized
More informationBinary Heap Algorithms
CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn G. Chappell
More information2) Write in detail the issues in the design of code generator.
COMPUTER SCIENCE AND ENGINEERING VI SEM CSE Principles of Compiler Design UnitIV Question and answers UNIT IV CODE GENERATION 9 Issues in the design of code generator The target machine Runtime Storage
More informationLecture 6: Binary Search Trees CSCI Algorithms I
Lecture 6: Binary Search Trees CSCI 700  Algorithms I Andrew Rosenberg September 24, 2009 Last Time Linear Time Sorting Counting Sort Radix Sort Bucket Sort Today Some C++ review Binary Search Trees Homework
More informationData Structures and Data Manipulation
Data Structures and Data Manipulation What the Specification Says: Explain how static data structures may be used to implement dynamic data structures; Describe algorithms for the insertion, retrieval
More informationLecture 6: Binary Search Trees CSCI 700  Algorithms I. Andrew Rosenberg
Lecture 6: Binary Search Trees CSCI 700  Algorithms I Andrew Rosenberg Last Time Linear Time Sorting Counting Sort Radix Sort Bucket Sort Today Binary Search Trees Data Structures Data structure is a
More informationHeap. Binary Search Tree. Heaps VS BSTs. < el el. Difference between a heap and a BST:
Heaps VS BSTs Difference between a heap and a BST: Heap el Binary Search Tree el el el < el el Perfectly balanced at all times Immediate access to maximal element Easy to code Does not provide efficient
More informationO(n) linear time This means that the algorithm requires a number of steps proportional to the size of the task.
Time complexity : Big O notation f(n) = O(g(n)) means There are positive constants c and k such that: 0
More informationIntro. to the DivideandConquer Strategy via Merge Sort CMPSC 465 CLRS Sections 2.3, Intro. to and various parts of Chapter 4
Intro. to the DivideandConquer Strategy via Merge Sort CMPSC 465 CLRS Sections 2.3, Intro. to and various parts of Chapter 4 I. Algorithm Design and DivideandConquer There are various strategies we
More informationChapter 14 The Binary Search Tree
Chapter 14 The Binary Search Tree In Chapter 5 we discussed the binary search algorithm, which depends on a sorted vector. Although the binary search, being in O(lg(n)), is very efficient, inserting a
More information