You are on page 1of 47

YEAR 2014

Q 1. What is data structure? Also define structures and operations.

Definition: Data structure is a specialized format for organizing and storing
data. i.e. data structure is a particular way of organizing data in a computer so that it
can be used efficiently.
Types of data Structure:
There are two types of data structure.
1. Linear data structure.
2. Non-linear data structure.

1. Linear data Structure: In linear data structures, values are arranged in
linear fashion. i.e. data is processes sequentially.
Example of linear data Structure:
1. Stack: In Stack data is arranges in LIFO fashion. i.e. Last In First Out.

Push is putting data into stack and POP is removing data from Stack.
2. Queue: In Queue data is arranged in FIFO fashion. i.e. First In First Out.

3. Linked List: A linked list is a finite sequence of nodes each of which contains
a pointer field pointing to the next node.

4. Array: Array is a collection of elements, each identified by at least one
index key.

2.Non-linear data Structure: A non-linear data structure is a data structure
in which a data item is connected to several other data items. So that a given
data item has the possibility to reach one-or-more data items. These are not
arranged sequentially.
Examples of Non-linear data Structure:
1. Tree: A connected, undirected, acyclic graph. It is rooted and ordered
unless otherwise specified.

2.Graph: A set of items connected by edges. Each item is called a vertex
or node.

Operations in data Structure:
There are 6 Major operations that can be performed in data structures:
1. Traversing
2. Searching
3. Inserting

4. Deleting
5. Sorting
6. Merging
1. Traversing- It is used to access each data item exactly once so that it can be
2. Searching- It is used to find out the location of the data item if it exists in the
given collection of data items.
3. Inserting- It is used to add a new data item in the given collection of data
4. Deleting- It is used to delete an existing data item from the given collection
of data items.
5. Sorting- It is used to arrange the data items in some order i.e. in ascending
or descending order in case of numerical data and in dictionary order in case of
alphanumeric data.
6. Merging- It is used to combine the data items of two sorted files into single
file in the sorted form.

Q2.Compare between array and linked list. Also define types of linked list.


Array is a collection of
elements having same
data type with common


In array, elements can be
accessed using
In linked list, elements can’t be accessed
index/subscript value, i.e.
randomly but can be accessed
elements can be randomly
only sequentially and accessing element
accessed like arr[0], arr[3],
takes 0(n) time.
etc. So array provides fast
and random access.


Insertion &

Linked list is an ordered collection of
elements which are connected by

In array, elements are
In linked list, elements can be stored at
any available place as address of node is
in consecutive manner in
stored in previous node.
Insertion & deletion takes Insertion & deletion are fast & easy in

Linear Linked List or One Way List or Singly Linked List 2. The second part contains the address of the next node and is called ‘LINK Field’ or ‘NEXT Pointer Field’. In linked list. 3. The first part contains the information of the element and is called ‘INFO Field’. Allocation. no pointers are used like linked list so no need of extra space in memory for pointer. Linked list can be singly. Static Memory time i. location or address of elements is stored in the link part of previous element/node. Doubly Linked List or Two-Way Linked List.Deletion Memory Allocation Types more time in array as elements are stored in consecutive memory locations. Linear Linked List or One Way List or Singly Linked List It is linear collection of data elements which are called ‘Nodes’. Types of linked lists: There are three types of Linked lists: 1. memory is allocated at run i. In array. . In array. In array. so pointers are used and for that extra memory space is needed. Extra Space linked list as only value of pointer is needed to change. adjacency between the elements are maintained using pointers or links. Dynamic Memory Allocation. two dimension or multidimensional.e. The START contains the starting address of the linked list. no Dependency connection with previous element or with its location. Array can be single dimensional. memory is allocated at compile time In linked list. Circular Linked List 1. doubly or circular linked list.e. each element is independent. Each node is divided into two parts. In Linked list.

The second part is the INFO part. It contains the address of the node which is after the current node. Instead the last node contains a pointer that has the address of first node and thus points back to the first node. 2.2. 3. It is previous pointer field. 3. It contains the address of the node which is before the current node. It contains the information of the element. The third part is NEXT part. The first part is PREV part. It is next pointer field. . Doubly Linked List: In it each node is divided into three parts: 1. Circular Linked List: In it the last node does not contain NULL pointer.

What is recursion? Explain the applications of recursion. int function(int value) { if(value < 1) return. function(value .Q3. the control returns to the calling function. } Applications of recursion:  To navigate through disk directory trees  Parse binary trees .1).value). Example of recursion − a function that calls another function which in turn calls it again. Definition: Recursion is an approach in which a function calls itself with an argument. printf("%d ". Upon reaching a termination condition.

Stack is said to be in Overflow state when it is completely full and is said to be in Underflow state if it is completely empty. Here. What is stack? Explain push and pop operations of the stack. 3. Basic features of Stack 1. 2. . is accessed first. (Last in First out). insertion operation is called PUSH operation and removal operation is called POP operation. increment top to point next empty space.  Step 3 − If stack is not full. PUSH OPERATION: The process of putting a new data element onto stack is known as PUSH Operation. In Stack data is arranges in LIFO fashion. LIFO stands for Last-in-first-out. produce error and exit.  Step 5 − return success. the element which is placed (inserted or added) last. 4. push() function is used to insert new elements into the Stack and pop() is used to delete an element from the stack. In sorting algorithms  Fibonacci Series Q3.  Step 2 − If stack is full. where top is pointing. Push operation involves series of steps −  Step 1 − Check if stack is full. In stack. Stack is a LIFO structure.  Step 4 − Add data element to the stack location. Stack is an ordered list of similar data type. Both insertion and deletion are allowed at only one end of Stack called Top.

data if stack is full begin procedure push: stack. data return null endif top ← top + 1 stack[top] ← data end procedure if stack is full return null endif top ← top + 1 stack[top] ← data end procedure .Algorithm for PUSH operation A simple algorithm for Push operation can be derived as follows − begin procedure push: stack.

pop() actually removes data element and deallocates memory space. is known as pop operation.  Step 2 − If stack is empty.  Step 3 − If stack is not empty. In array implementation of pop() operation.  Step 5 − return success.  Step 4 − Decrease the value of top by 1. instead top is decremented to a lower position in stack to point to next value.Pop Operation Accessing the content while removing it from stack. access the data element at which top is pointing. data element is not actually removed. But in linked-list implementation. A POP operation may involve the following steps −  Step 1 − Check if stack is empty. . produce error and exit.

In these two examples we can see that here A and B are two operands and + is an operator which is written before operands. Example of polish notation or prefix notation is +AB or /CD. What is polish notation? Define conversion of infix notation into postfix notation.Algorithm for POP operation A simple algorithm for Pop operation can be derived as follows − begin procedure pop: stack if stack is empty return null endif data ← stack[top] top ← top .1 return data end procedure Q5. Definition: Polish notation also known as prefix notation is defined as: In this notation system operator is written before the operands. Conversion of infix notation into postfix notation: .

Example : Let us see how the above algorithm will be implemented using an example. Infix to Postfix Conversion: In normal algebra we use the infix notation like a+b*c. Postfix String Stack . it is pushed to the stack. If topStack has higher precedence over the scanned character Popthe stack else Push the scanned character to stack. 'a' is added to the Postfix string. add it to the Postfix string. If the scanned character is an operator and if the stack is empty Push the character to stack. It being an operator.  Initialize an empty stack. Now. Repeat this step as long as stack is not empty. Repeat this step till all the characters are scanned.  If the scanned character is an Operand and the stack is not empty.  Return the Postfix string. Repeat this step as long as stack is not empty and topStack has precedence over the character.  (After all characters are scanned. Infix String : a+b*c-d Initially the Stack is empty and our Postfix string has no characters. we have to add any character that the stackmay have to the Postfix string. compare the precedence of the character with the element on top of the stack(topStack). The algorithm for the conversion is as follows:  Scan the Infix string from left to right.) If stack is not empty add topStack to Postfix string andPop the stack.  If the scanned character is an operand. The corresponding postfix notation is abc*+.Infix Expression : Any expression in the standard form like "2*3-4/5" is an Infix(Inorder) expression. the first character scanned is 'a'. Postfix Expression : The Postfix(Postorder) form of the above expression is "23*45/-". The next character scanned is '+'.

Next character scanned is 'b' which will be placed in the Postfix string. Postfix String Stack Next character is 'd' which is added to Postfix string. this is how the stack and Postfix string will be : Postfix String Stack End result : Infix String : a+b*c-d Postfix String : abc*+d- . So. Next character is '*' which is an operator. the top element of the stack is '+' which has lower precedence than '*'. Now. It is popped out and added to the Postfix string. Thus '*' will be popped out from the stack and added to the Postfix string. The '-' will be pushed to the stack. At this stage we have only a '-' in the stack. So pop the '+' from the stack and add it to the Postfix string. after all characters are scanned. Now the topmost element of the stack is '+' which has equal priority to '-'. Next character scanned is '-'. The topmost character in the stack is '*' which has a higher precedence than '-'. so '*' will be pushed to the stack. Even now the stack is not empty. Now all characters have been scanned so we must pop the remaining elements from the stack and add it to the Postfix string. Postfix String Stack The next character is 'c' which is placed in the Postfix string.

This is often referred to as FIFO (first in. all the elements inserted before the new element in the queue must be removed. a queue is a data structure in which elements are removed in the same order they were entered.Q6.What is a queue? Write Algorithms for the insertion and deletion operations performed on circular queue. first out). to remove the new element. Algorithm for Insertion in a circular queue 1. DEFINITION: In programming. Once a new element is inserted into the Queue. If (FRONT == 1 and REAR == N) or (FRONT == REAR + 1) Then .

Else If (REAR == N) Then [If REAR reaches end if QUEUE] 6. If (REAR == 0) Then [Check if QUEUE is empty] (a) Set FRONT = 1 (b) Set REAR = 1 5. Set REAR = 1 7. Else 4. Print: Overflow 3.2. Set REAR = REAR + 1 [Increment REAR by 1] [End of Step 4 If] 9. Set QUEUE[REAR] = ITEM 10. Else 8. Print: ITEM inserted [End of Step 1 If] .

Exit Algorithm for Deletion in a circular queue: 1.The output statements should follow input. ITEM = QUEUE[FRONT] 5.Should have an end point .Should provide the correct solutions . Set FRONT = FRONT + 1 [Increment FRONT by 1] [End of Step 5 If] 10. Properties of an algorithm: . Set FRONT = 1 8. Also define the time complexity of merge sort. Print: ITEM deleted [End of Step 1 If] 11. If (FRONT == 0) Then [Check for Underflow] 2. precise and lucid . Else 4. Exit Q7.11. Print: Underflow 3.Should be unambiguous.Should be written in simple English . If (FRONT == REAR) Then [If only element is left] (a) Set FRONT = 0 (b) Set REAR = 0 6. Definition of algorithm: Algorithm is a step by step process to get the solution for a well-defined problem.What is algorithm? Define the complexity of algorithms. Else If (FRONT == N) Then [If FRONT reaches end if QUEUE] 7. process instructions . Else 9.

the function mergesort calls itself recursively. return (merge (mergesort (L1. Then.Every statement should be definitive Complexity of Algorithms: The complexity of an algorithm is a function describing the efficiency of the algorithm in terms of the amount of data the algorithm must process. )) } } Let T(n) be the running time of Mergesort on an input list of size n. list mergesort (list L.The initial statements should be of input statements . { if (n = = 1) return (L) else { Split L into two halves L1 and L2 . (mergesort (L2. as outlined below. ). int n).Should have finite number of steps . Time complexity of merge-sort: Merge sort is a divide and conquer algorithm. T(n) C1 (if n = 1) (C1 is a constant) + (if n > 1) ..

Q8. T(n) is O(nlog n).What is binary tree? Define the terminologies of binary tree. Definition: Binary Tree is a special data structure used for data storage purposes. A binary tree have benefits of both an ordered array and a linked list as search is as quick as in sorted array and insertion or deletion operation are as fast as in linked list. it can be shown that T(n) 2kT(1) + C2k2k That is. . A binary tree has a special condition that each node can have two children at maximum.If n = 2k for some k.

Terminologies of binary tree: Following are important terms with respect to tree.  Levels − Level of a node represents the generation of a node.  Subtree − Subtree represents descendents of a node.  Root − Node at the top of the tree is called root. .  Parent − Any node except root node has one edge upward to a node called parent.  Child − Node below a given node connected by its edge downward is called its child node.  Leaf − Node which does not have any child node is called leaf node. then its next child node is at level 1. If root node is at level 0.  Visiting − Visiting refers to checking value of a node when control is on the node.  Traversing − Traversing means passing through nodes in a specific order. There is only one root per tree and one path from root node to any node.  Path − Path refers to sequence of nodes along the edges of a tree. its grandchild is at level 2 and so on.  keys − Key represents a value of a node based on which a search operation is to be carried out for a node.

We start from A. Step 2 − Visit root node. Step 3 − Recursively traverse right subtree. we move to its left subtree B. Inorder traversal: In this traversal method. the root node is visited first. all nodes are connected via edges (links) we always start from the root (head) node. The output of in-order traversal of this tree will be − D→B→E→A→F→C→G Algorithm: Until all nodes are traversed − Step 1 − Recursively traverse left subtree. and following in-order traversal. Pre-order Traversal: In this traversal method. the left left-subtree is visited first. then left subtree and finally right sub-tree.If a binary tree is traversed inorder. And the process goes on until all the nodes are visited. the output will produce sorted key values in ascending order. Explain the pre-order. Because. in-order and post-order traversal of binary tree. Traversal is a process to visit all the nodes of a tree and may print their values too.Q8. We should always remember that every node may represent a subtree itself. then root and then the right subtree.B is also traversed in-ordered. .

then right subtree and finally root. . and following pre-order traversal. And the process goes on until all the nodes are visited.We start from A. B is also traversed pre-ordered. PostOrder Traversal: In this traversal method. The output of pre-order traversal of this tree will be − A→B→D→E→C→F→G Algorithm Until all nodes are traversed − Step 1 − Visit root node. the root node is visited last. Step 3 − Recursively traverse right subtree. First we traverse left subtree. we first visit A itself and then move to its left subtree B. Step 2 − Recursively traverse left subtree.

the tree is balanced using some rotation techniques. and following pre-order traversal. Step 2 − Recursively traverse right subtree. AVL tree checks the height of left and right sub-trees and assures that the difference is not more than 1.We start from A. There are four kinds of rotations −  Left rotation . BalanceFactor = height(left-sutree) − height(right-sutree) If the difference in the height of left and right sub-trees is more than 1. AVL tree is named after their inventor Adelson. Q. This difference is called Balance Factor.B is also traversed post-ordered. Step 3 − Visit root node. AVL trees are height balancing binary search tree. Velski & Landis. The output of post-order traversal of this tree will be − D→E→B→F→G→C→A Algorithm Until all nodes are traversed − Step 1 − Recursively traverse left subtree. What is AVL tree? Explain with suitable example. And the process goes on until all the nodes are visited. we first visit left subtree B.

insertions. 6. the unbalanced node becomes right child of its left child by performing a right rotation. KEY. it is optimized for systems that read and write large blocks of data. NODE_RRN. Algorithm for Searching a B-tree: function Search (ROOT_RRN. 2. Definition: A B-tree is a tree data structure that keeps data sorted and allows searches. 4. Important properties of a B-tree:  B-tree nodes have many more than two children. It is most commonly used in database and file systems. What is B-tree? Explain algorithm of b-tree in order. NODE_POS) (* In this algorithm Found : a flag to indicate if the record has been found . 3.  A B-tree node may contain more than just a single element. 5. All but two insertions require re-balancing: As depicted. and deletions in logarithmic amortized time. Unlike selfbalancing binary search trees. Q. Right rotation  Left-Right rotation  Right-Left rotation example of AVL trees is the behavior on a worst-case add sequence for regular binary trees: 1. 7 All insertions are right-right and so rotations are all single rotate from the right.

K : key of record being searched for P : holds a pointer to a node Ri : record i in current node *) Found = false read root at location ROOT_RRN P = ROOT_RRN repeat N = number of records in current node case KEY = key of record in current node (set i): found = true KEY < key(R1) KEY > key(RN) Otherwise < KEY < key(Ri)) endcase if P not null then read node pointed to by P endif until Found or P is null if Found then NODE_POS = i NODE_RRN = P endif Search = Found : P = P0 : P = PN : P = Pi–1 (for some i where key(Ri–1) .

do following . . change x to point to y. So simply insert k to x. If k is smaller than mid key in y. .c) If y is full.. Out-rec) (* In this algorithm Finished : TWOBNODE : normal node A-sibling Out-rec a flag that indicates if deletion has finished an oversize node that is about 50% larger than a : an adjacent sibling node : the record to be deleted from the tree *) (* Search tree for In-rec forming stack of node addresses *) Found = false read root at ROOT_RRN repeat N = number of records in current node .return Insertion 1) Initialize x as root. split it and change x to point to one of the two parts of y.b) If y is not full. When we split y. we move a key from y to its parent x. Else second part of y. 3) The loop in step 2 stops when x is leaf. 2) While x is not leaf... x must have space for 1 extra key as we have been splitting all nodes in advance. Let the child be y. then set x as first part of y. Deletion function delete(ROOT_RRN.a) Find the child of x that is going to to be traversed next.

case key(Out-rec) = key of record in current node: found = true key(Out-rec) < key(R1) : P = P0 key(Out-rec) > key(RN) : P = PN Otherwise 1) < KEY < key(Ri)) : P = Pi–1 (for some i where key(Ri– endcase if P not null then push onto stack address of current node read node pointed to by P endif until Found or P is null if not Found then delete = false return endif if Out-rec is not in terminal node then Search for successor record of Out-rec at terminal level (stacking node addresses) Copy successor over Out-rec Terminal node successor now becomes the Out-rec endif (* remove record and adjust tree *) .

. parent. and current (too-small) node into TWOBNODE copy records and pointers from TWOBNODE to “best” A-sibling. intermediate parent record. and current node so A-sibling and current node are roughly equal size Finished = true else (* concatenate with appropriate A-sibling *) Choose best A-sibling to concatenate with Put in the leftmost of the current node and A-sibling the contents of both nodes and the intermediate record from the parent Discard rightmost of the two nodes Intermediate record in parent now becomes Out-rec until Finished if no records in root then (* tree shrinks *) new root is the node pointed to by the current root discard old root endif delete = true return Q.Finished = false repeat Remove Out-rec (record Ri) and pointer Pi if current node is root or is not too small then Finished = true else if redistribution possible then (* an A-sibling > minimum *) (* redistribute *) copy “best” A-sibling. What is graph? Explain types and terminologies of graph.

labeled circle represents vertices. a graph is a pair of sets (V. Take a look at the following graph − In the above graph. de} Graph Data Structure Mathematical graphs can be represented in data-structure. ac. Formally. d. B can be identified using index 1 and so on. bd. and the links that connect the vertices are called edges. keeping other combinations as 0. where V is the set of vertices and E is the set of edges.  Edge − Edge represents a path between two vertices or a line between two vertices. Here AB can be represented as 1 at row 0. Terminologies of graph: Vertex − each node of the graph is represented as a vertex. In example given below. B is adjacent to A. ABCD represents a path from A to D. cd.Ggraph is a pictorial representation of a set of objects where some pairs of objects are connected by links. BC as 1 at row 1.  Path − Path represents a sequence of edges between two vertices. c. We can use a two dimensional array to represent array as shown in image below. E). b. C is adjacent to B and so on. connecting the pairs of vertices. Here A can be identified by index 0. In example given below. . V = {a. lines from A to B. B to C and so on represents edges. column 2 and so on. We can represent them using an array as shown in image below. In example given below. So A to G are vertices.  Adjacency − Two node or vertices are adjacent if they are connected to each other through an edge. column 1. e} E = {ab. The interconnected objects are represented by points termed as vertices. In example given below.

1.  Add Vertex − add a vertex to a graph.Following are basic primary operations of a Graph which are following. First. Hash Table 4.  Add Edge − add an edge between two vertices of a graph. This search algorithm works on the principle of divide and conquer. Dynamic memory allocation. Collision resolution technique. 5. Q. The below given is our sorted array and assume that we need to search location of value 31 using binary search. Insertion and Selection sorting 3. Binary Search 2. write short notes on the following. BINARY SEARCH: Binary search is a fast search algorithm with run-time complexity of Ο(log n). we shall determine the half of the array by using this formula − . For this algorithm to work properly the data collection should be in sorted form.  Display Vertex − display a vertex of a graph.

The value stored at location 7 is not a match. This time it is 5. 31. So 4 is the mid of array. rather it is less that what we are looking for. 0 + (9 . We find that value at location 4 is 27. Now we compare the value stored at location 4. We compare the value stored at location 7 with our target value 31. So the value must be in lower part from this location.low) / 2 Our new mid is 7 now. So we calculate the mid again. low = mid + 1 mid = low + (high . We change our low to mid + 1 and find the new mid value again. which is not a match. We find that it is a match. We compare the value stored ad location 5 with our target value. with the value being searched i. Because value is greater than 27 and we have a sorted array so we also know that target value must be in upper portion of the array.5). .low) / 2 Here it is.mid = low + (high .e.0 ) / 2 = 4 (integer value of 4.

14 is in sorted sub-list. . For now. Insertion sort compares the first two elements. Hence sorted sub-list remain sorted after swapping. INSERTION AND SELECTION SORTING: Insertion sort: Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It swaps 33 with 27.We conclude that the target value 31 is stored at location 5. Also it checks with all the elements of sorted sublist. And finds that 33 is not in correct position. Binary search halves the searchable items and thus reduces the count of comparisons to be made to very less numbers. take an unsorted array for our example. It finds that both 14 and 33 are already in ascending order. Insertion sort moves ahead and compares 33 with 27. Here we see that sorted sub-list has only one element 14 and 27 is greater than 14.

By now we have 14 and 27 in the sorted sublist. And we swap them. By the end of third iteration we have a sorted sublist of 4 items. Algorithm Step 1 − If it is the first element. But swapping makes 27 and 10 unsorted.. Next it compares 33 with 10. . This process goes until all the unsorted values are covered in sorted sublist. These values are not in sorted order. Again we find 14 and 10 in unsorted order. And now we shall see some programming aspects of insertion sort. it is already sorted. return 1. So we swap them too. So we swap them.

which happens to be the minimum value in the list. For the first position in the sorted list.Step 2 − Pick next element Step 3 − Compare with all elements in the sorted sub-list Step 4 − Shift all the elements in the sorted sub-list that is greater than the value to be sorted Step 5 − Insert the value Step 6 − Repeat until list is sorted Selection sort: The selection sort is a combination of searching and sorting. After two iterations. For the second position. During each pass. two least values are positioned at the the beginning in the sorted manner. We find that 14 is the second lowest value in the list and it should appear at the second place. We swap these values. appears in the first position of sorted list. we search the whole list and find that 10 is the lowest value. The number of times the sort passes through the array is one less than the number of items in the array. the unsorted element with the smallest (or largest) value is moved to its proper position in the array. The first position where 14 is stored presently. where 33 is residing. take the below depicted array for our example. we start scanning the rest of the list in linear manner. the whole list is scanned sequentially. So we replace 14 with 10. . After one iteration 10.

// read from book please COLLISION RESOLUTION TECHNIQUE: Read from book. In hash table.  Search − search an element in a hashtable.  Insert − insert an element in a hashtable. DYNAMIC MEMORY ALLOCATION: Read from book. No proper data available on this topic. .The same process is applied on the rest of the items in the array Algorithm Step 1 − Set MIN to location 0 Step 2 − Search the minimum element in the list Step 3 − Swap with value at location MIN Step 4 − Increment MIN to point to next element Step 5 − Repeat until list is sorted Hash table: Hash Table is a data structure which store data in associative manner. What do you mean by abstract data structure. Basic Operations Following are basic primary operations of a hashtable which are following.  delete − delete an element from a hashtable. YEAR 2010 Q. data is stored in array format where each data values has its own unique index value.

and its implementation is hidden. ‘C’ also provides the programmer with the ability to define his/her own types. 2. Since. The representation. 2. or definition. Q3. . PUSH AND POP also primitive operations. A structure is an aggregate of different parts. struct abc {int x. Structure is one such example. float and double. but hides the representation of these variables. An Abstract Data Type is a data type that satisfies the following two conditions: 1. where each part is of some existing type. char.Definition: A data type can be considered abstract when it is defined in terms of operations on it. The representation of objects of the type is hidden from the program units that use the type. relations to other abstract data types whether a program implements the data type etc. to push values onto a stack and to pop values from a stack. rather than as an implementation in a computer language. the data values and operations are defined with mathematical precision. in ADT. float y. What is queue? Discuss circular queue and priority queue in data structure. Already answered.An Abstract Data Type is an organized collection of information and a set of operations used to manage that information. A type definition that allows program units to declare variables of the type. A user defined Abstract Data Type should provide: 1. The set of operations defines the interface of the ADT. Q2 What is stack? Explain primitive operation which can be performed on stack. A set of operations for manipulating objects of the type. we may reason about effects of the operations. An example of a user defined abstract data type is structure. it doesn’t really matter how the ADT is implemented. However. so only direct operations possible on those objects are those provided in the type’s definition. As long as the ADT fulfills the conditions of the interface. of the type and the operations are contained in a single syntactic unit. ’C’ provides four basic types: int. }. One of the simplest abstract data type is the stack data type for which functions might be provided to create an empty stack.

It follows FIFO principle. Like ordinary queue. higher the priority. In Priority queue items are ordered by key value so that item with the lowest value of key is at front and item with the highest value of key is at rear or vice versa. It is also called as “Ring buffer”. In circular linked list Instead of storing a Null value in the last node of a single linked list.  In circular queue the last node is connected back to the first node to make a circle. The following figure shows circular single linked list: Using double linked list In double linked list the right side pointer points to the next node address or the address of first node and left side pointer points to the previous node address or the address of last node of a list.  Circular linked list fallow the First In First Out principle  Elements are added at the rear end and the elements are deleted at front end of the queue  Both the front and the rear pointers points to the beginning of the array. Lower the value. So we're assigned priority to item based on its key value. Circular Queue can be created in three ways they are  Using single linked list  Using double linked list  Using arrays Using single linked list: It is an extension for the basic single linked list. priority queue has same method but with a major difference. .Circular queue: Circular queue is a linear data structure. store the address of the 1st node (root) forms a circular linked list. The following figure shows Circular Double linked list :- Priority Queue is more specialized data structure than Queue.

Here we're assuming that data with high value has low priority. Item count is reduced by one. priority queue inserts the item according to its order. Linked-List Implementation of Stacks a stack uses a linked list. which is a data structure that links together individual data objects as if they were ``links'' in a ``chain'' of data.Basic Operations  insert / enqueue − add an item to the rear of the queue. What do you mean by linked list of stack and linked list pf queue. Here is a sketch of a linked-list-based ``stack'' that holds 1.  remove / dequeue − remove an item from the front of the queue. Insert / Enqueue Operation  Whenever an element is inserted into queue. and then 20 at the bottom: --top ---> | 1 | . Q. then 5. Once element is removed.  Remove / Dequeue Operation Whenever an element is to be removed from queue. queue get the element using item count.? ‘explain doubly and circular linked list.

a cell is constructed. A variable. null.|---| --- | o-|---> | 5 | --- |---| ---- | o-|---> | 20 | --- |----| |null| ---- The list consists of three ``cells. and the cell is linked to the front of the chain of cells. we obtain the picture first seen. top. the object is inserted into the cell.) Each time an object is pushed. Say that we pop an object from the stack.'' each of which holds a data object and a ``link'' to another cell. variable top holds value. pushing 20onto the empty stack gives us ---top ---> | 20 | |--.| |null| ---After 5 and then 1 are pushed. holds the address of the first cell in the list. the picture changes to this: --top ---> | 5 | |---| ---- | o-|---> | 20 | --- |----| |null| ---- . An empty stack looks like this: top ---> null (That is. For example.

 Display forward − displaying complete list in forward manner.  Next − Each Link of a linked list contain a link to next link called Next.  Delete − delete an element from the list using key.  Insert Last − add an element in the end of the list. Doubly Linked List Representation As per above shown illustration.  Delete Last − delete an element from the end of the list.  LinkedList − A LinkedList contains the connection link to the first Link called First and to the last link called Last.  Insert After − add an element after an item of the list.  Each Link is linked with its previous link using its prev link.  Each Link carries a data field(s) and a Link Field called next. following are the important points to be considered.  Prev − Each Link of a linked list contain a link to previous link called Prev.  Each Link is linked with its next link using its next link. .  Last Link carries a Link as null to mark the end of the list. Following are important terms to understand the concepts of doubly Linked List  Link − Each Link of a linked list can store a data called an element. Basic Operations Following are the basic operations supported by an list.  Doubly LinkedList contains an link element called first and last.  Deletion − delete an element at the beginning of the list.  Insertion − add an element at the beginning of the list.Doubly Linked List: Doubly Linked List is a variation of Linked list in which navigation is possible in both ways either forward and backward easily as compared to Single Linked List.

Used in many search applications where data is constantly entering/leaving. Q. Since these index values are ordered.  Treap . binary search.  Binary Tries . .Constructed by compilers and (implicitly) calculators to parse expressions. including robotics and video games). which in turn are used for scheduling processes in many operating systems. each data item is stored in a position relative to the others. Also used in heap-sort. Circular linked is explained already.used in compression algorithms.  Heaps .Used in almost every high-bandwidth router for storing routertables. such as the map and set objects in many languages' libraries.Used in cryptographic applications to generate a tree of pseudorandom numbers. This process gives rise searching technique.Though most databases use some form of B-tree to store data on the drive.  T-tree .Randomized data structure used in wireless networking and memory allocation. and A* (path-finding algorithm used in AI applications. databases which keep all (most) their data in memory often use T-trees to do so. Display backward − displaying complete list in backward manner.  Hash Trees . Applications of binary trees  Binary Search Tree .jpeg and .  Syntax Tree .  GGM Trees . Explain sequential seaarch.mp3 file-formats.used in p2p programs and specialized image-signatures in which a hash needs to be verified. Quality-of-Service in routers.  Binary Space Partition . insertion sort and quick sort. it is possible for us to visit them in sequence. the sequential search.Used in implementing efficient priority-queues. but the whole file is not available.Used in almost every 3D video game to determine what objects need to be rendered. Application of binary-tree and threaded binary tree. such as those used by the . SEQUENTIAL SEARCH: When data items are stored in a collection such as a list.  Huffman Coding Tree (Chip Uni) . Q.

6 8 17 14 25 63 37 52 Hence after the first pass. Elements less than the Pivot element 2. . This algorithm divides the list into three main parts : 1. the list will be changed like this. and same logic is applied on them. Pivot element 3. It is based on the rule of Divide and Conquer(also called partition-exchange sort). with all the elements smaller to it on its left and all the elements larger than it on the right. we have taken 25 as pivot. Elements greater than the pivot element In the list of elements. Now 6 8 17 14 and 63 37 52 are considered as two separate lists. So after the first pass.Algorithm: Sequential Search ( Array A. pivot will be set at its position. Value x) Step 1: Set i to 1 Step 2: if i > n then go to step 7 Step 3: if A[i] = x then go to step 6 Step 4: Set i to i + 1 Step 5: Go to Step 2 Step 6: Print Element x Found at index i and go to step 8 Step 7: Print element not found Step 8: Exit QUICK SORT: Quick sort is not stable search. mentioned in below example. but it is very fast and requires very less additional space. and we keep doing this until the complete list is sorted.

In an undirected graph. For directed graphs we usually use arrows for the arcs between vertices. The adjacency relation is symetric in an undirected graph.B).2).v) is in the Edge set.(D.(3. Thus. In a directed graph the order of the vertices in the pairs in the edge set matters. Directed Graphs.5)}.(4. Weighted Graphs.(D.B) are in the Edge set. The directed graph below Has the following parts.C). o The underlying set for the Verticies set is capital letters.2)).v) is in the Edge set.(1. (2. the order of the vertices in the pairs in the Edge set doesn't matter. A weighted graph is an edge labeled graph where the labels can be operated on by the usual arithmetic operators.E)} Note that both (B.(B. including comparisons like using less than and greater than.(1.5)).  Undirected Graphs. so the arc between B and D is an arrow in both directions. o The Vertices set = {A.E} o The Edge set = {(A.D).(B.D) and (D.5).C). if we view the sample graph above we could have written the Edge set as {(4. . the weights are drawn adjacent to the edges and appear in dark purple. Also discuss representation of graphs.Q What do you mean by directed and undirected and weighted graph.D). Undirected graphs usually are drawn with straight lines between the vertices.(B. Thus u is adjacent to v only if the pair (u.C.6).(E.(3.B.B).4).D. An arrow from u to v is drawn only if (u.

5. We take an unsorted array for our example.2.14) .  The underlying set for the weights is Integer.(2.(3.34) .2.4. Analysis of algorithm.58) .(3. comparing them to check which one is greater.5) .4.5.5) .  The underlying set for the the Vertices set is Integer. Comparison of sorting method.3.(2.Here we have the following parts.2)} Representation of graphs is already answered. Bubble sort take Ο(n2) time so we're keeping short and precise.4) . BUBBLE SORT: Bubble sort is a simple sorting algorithm.  The Vertices set = {1.4.5}  The Edge set = {(1.(1. Q. Bubble sort 2. Bubble sort starts with very first two elements.2. Representation of graph. Write sort notes on: 1.(4.5. This sorting algorithm is comparison based algorithm in which each pair of adjacent elements is compared and elements are swapped if they are not in order. 4. 3. .

we are now showing that how array should look like after each iteration. so it is already in sorted locations. We find that 27 is smaller than 33 and these two values must be swapped. . at least one value moves at the end. The new array should look like this − Next we compare 33 and 35. After one iteration the array should look like this − To be precise. 35 and 10. We find that both are in already sorted positions. We know than 10 is smaller 35. Hence they are not sorted. we compare 33 with 27. it should look like this − Notice that after each iteration. After second iteration. We find that we reach at the end of the array. Next. Then we move to next two values.In this case. We swap these values. value 33 is greater than 14.

In question number 7 in 2014. Now we should look into some practical aspects of bubble sort. YEAR 2011 Write Sort notes on: Redix sort: Radix Sort is a clever and intuitive little sorting algorithm.And when there's no swap required. list[i+1]) end if end for return list end BubbleSort Comparison of sorting algorithms: Use your book. Radix Sort puts the elements in order by comparing the digits of the numbers. bubble sorts learns that array is completely sorted. . Analysis of algorithm: Already answered. ALGORITHM: begin BubbleSort(list) for all elements of list if list[i] > list[i+1] swap(list[i].

170. 75. 45.] 802. 2. 75. 24. 24. 90. 66 Sorting by next digit (10s place) gives: [*Notice that 802 again comes before 2 as 802 comes before 2 in the previous list. 170. 2. 66.Example: let this is original. 75. 24. 24. 2. 45. 75. 802. 66 Sorting by least significant digit (1s place) gives: 170. 45. 802 . 90. unsorted list: 170. 66. 90 Sorting by most significant digit (100s place) gives: 2. 45. 802. 90.