SlideShare a Scribd company logo
1 of 28
CS8391
DATA
STRUCTURES
ANNA UNIVERSITY QUESTIONS AND ANSWERS
TWO MARK
FROM
REGULATION 2008 &2013 QUESTION PAPERS
COMPILED BY:
DR. P. SUBATHRA. M.E., Ph.D.,
PROFESSOR IN INFORMATION TECHNOLOGY
KAMARAJ COLLEGE OF ENGINEERING AND TECHNOLOGY
MADURAI DISTRICT, NEAR VIRUDHUNAGAR, TAMIL NADU, INDIA
UNIT I - LINEAR DATA STRUCTURES
1
1. What is an ADT? Give an example. (OR) Define an abstract type. List out few. (OR) What
are abstract data types? (R 2013 NOV/DEC-2016), (R 2008/2010 MAY/JUN - 2013), (R 2008
MAY/JUN- 2012), (R 2008 NOV/DEC - 2010), (R 2008/2010 NOV/DEC - 2013) (R 2013
NOV/DEC 2014)(R 2013 DEC 15/ JAN 2016) (R 2013 MAY/ JUN 2016)(R2013 NOV/DEC
2016) (R 2013 APR/MAY 2017)
An Abstract Data Type (ADT) is a mathematical model for data types, which gives a set of
operations available to the user but never states the details of its implementation.
Abstract Data Type:
1. Declaration of data
2. Declaration of operations.
Eg. Objects such as list, stack, queue, graphs along with their operations can be viewed as ADTs
2. What is the purpose of using ADTs in programs? (OR) What is advantage of an ADT? (R
2008 APR/MAY- 2012) (R 2013 May/JUN 2014)
The main purpose of using ADTs is use utilize the following advantages of them:
1. Easy to debug small routines than large ones.
2. Easy for several people to work on a modular program simultaneously.
3. A modular program places certain dependencies in only one routine, making changes
easier.
3. What are all not concerned in an ADT? (R 2008 NOV/DEC - 2010)
The definition of ADT only mentions what operations are to be performed but not how these
operations will be implemented. It does not specify:
• How data will be organized in memory?
• What algorithms will be used for implementing the operations?
4. What is Data Structures? How is it classified? (R 2013 NOV/DEC-2016)
Data Structures represents the logical relationship that exists between individual elements of
data to carry out certain tasks. It defines a way of organizing all data items that consider not only
the elements stored, but also the relationship between the elements. Data Structures is basically
classified into two namely:
(i) Primary Data Structures (integers, floats, characters)
(ii) Secondary Data Structures (List, Stack, Queue, Graph)
Secondary Data Structures is classified into:
(i) Linear Data Structures (Lists)
(ii) Non-Linear Data Structures (Trees, Graphs)
5. Is linked list better than an arrayed list? Give at least two reasons for your answer. (OR)
What are the advantages of linked lists over arrays? (OR) What are the advantages and
disadvantages of linked lists over arrays? (R 2008 APR/MAY- 2013) (R 2013 Dec 15/ Jan
2016) (R 2013 APR/MAY 2017)
2
Linked list have few advantages than the arrays, but there are also some drawbacks with respect
to the arrays. Some of the advantages of lists are:
1. Dynamic size
2. Easy insertion and deletion
Some of the drawbacks of lists are:
1. Random access is not allowed. We have to access elements sequentially starting from the
first node. So we cannot do binary search with linked lists.
2. Extra memory space for a pointer is required with each element of the list.
3. Arrays have better cache locality that can make a pretty big difference in performance.
6. What is the Data Structure used to perform recursion? (R 2008 MAY/JUN- 2012)
Stack is the Data Structure that is used to perform recursion. The recursive calls return to the
latest called location which demands a Last in First Out structure which is guaranteed by a
STACK Data Structure.
7. Explain why binary search cannot be performed on a linked list. (R 2008 NOV/DEC - 2010)
Binary search can be done only on a sorted list and also the list needs to be accessed in the middle
at a random position. One of the limitations of Linked list is that, random access is not allowed.
We have to access elements sequentially starting from the first node. So we cannot do binary
search with linked lists.
8. Define List Abstract Data Type with example. (R 2008 APR/MAY - 2010)
A list or sequence is an abstract data type that represents a countable number of ordered values,
where the same value may occur more than once. List ADT is a sequential storage structure.
General list of the form a1, a2, a3.…., an and the size of the list is 'n'. Any element in the list at the
position i is defined to be ai, ai+1 the successor of ai and ai-1 is the predecessor of ai. e.g. Singly
Linked list, Doubly linked list.
9. Write algorithms to insert and delete an element from a linked list. (R 2008 NOV/DEC-
2014)
There are a number of choices to insert an element into a list and to delete an element from a list.
Here insertion and deletion at the first position is considered:
Inserting At Beginning of the list
• Step 1: Create a newNode with given value.
• Step 2: Check whether list is Empty (head == NULL)
• Step 3: If it is Empty then, set newNode→next = NULL and head = newNode.
• Step 4: If it is Not Empty then, set newNode→next = head and head = newNode.
3
Deleting from Beginning of the list
• Step 1: Check whether list is Empty (head == NULL)
• Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate
the function.
• Step 3: If it is Not Empty then, define a Node pointer 'temp' and initialize with head.
• Step 4: Check whether list is having only one node (temp → next == NULL)
• Step 5: If it is TRUE then set head = NULL and delete temp (Setting Empty list
conditions)
• Step 6: If it is FALSE then set head = temp → next, and delete temp.
10. Clearly distinguish between linked lists and arrays. Mention their relative advantages and
disadvantages. (R 2008 MAY/JUN- 2012)
Arrays Linked List
Size of any array is fixed Size of list is variable
It is necessary to specify the number of
elements during declaration
It is not necessary to specify the
number of elements during declaration
Insertion and deletions are difficult and
costly
Insertions and deletions are done in
less time
It occupies less memory than a linked
list It occupies more memory
Coding is easy
Careful coding is needed to avoid memory
errors.
11. Provide the asymptotic complexity for calculating the Sum of n number in an array. (R
2012 NOV/DEC-2013)
The algorithm to find the sum of n number in an array is given below:
Sum_num()
{
temp_sum = 0
for i in 1 ...array.length
temp_sum = temp_sum + array[i]
}
If ‘ n’ is the size of array and all we have to do is iterate from beginning to the end of the array
once and so the Big O notation is O(n).
12. List the four major operations in linear data structures. (R 2008/2010 APR/ MAY - 2015)
Some of the major operations in a linear data structure are listed below:
4
1. Insertion
2. Deletion
3. Search
4. Print
5. Find the Kth
Element
6. Make Empty
13. What is circular linked list? (R 2013 NOV/DEC 2014) (R 2013 May/ Jun 2016)
Circular Linked List is a variation of Linked list in which the first element points to the last
element and the last element points to the first element. Both Singly Linked List and Doubly
Linked List can be made into a circular linked list.
SinglyLinkedListasCircular –The next pointer of the last node points to the first node.
DoublyLinkedListas Circular-The next pointer of the last node points to the first node and the
previous pointer of the first node points to the last node making the circular in both directions.
14. Define a linear and non-linear data structure. Give an example for each. (R 2008/2010
NOV/DEC - 2013)
Linear data structures:
Linear data structures are data structures having a linear relationship between its adjacent
elements. Eg) Linked lists, Doubly Linked Lists, Stacks, Queues
Non-linear data structures:
Non-linear data structures are data structures that don’t have a linear relationship between its
5
adjacent elements but have a hierarchical relationship between the elements. Eg) Trees and
Graphs
Unit II - LINEAR DATA STRUCTURES - STACKS, QUEUE
1. Write an ADT for insertion in a stack. (R 2008/2010 MAY/JUN – 2014)
Insertion operation in a stack is called as PUSH. This operation inserts an element at one end of
the stack called the Top. Algorithm is given below:
push: stack, data
{
if stack is full
return null
endif
top ← top + 1
stack[top] ← data
end procedure
}
2. Define stack. List some of the applications of stack. (R 2013 APR/MAY 2017)
Stack is a linear data structure, where the operations like insertion and deletion are restricted to
one end called the TOP. The insertion operation is called PUSH and the delete operation is called
as the POP. It is also called as a LIFO data structure because, the element that enters the stack last
will be accessed first.
Some of the applications of Stack are:
i. Parsing
ii. Expression evaluation
iii. Backtracking (game playing, finding paths, exhaustive searching)
iv. Memory management, run-time environment for nested language features
3. Mention the Applications of stack. (OR) Give the applications of stack. (OR) Give any two
applications of stack. (R 2008 APR/MAY - 2010), (R 2013 NOV/DEC-2016), (R 2008/2010
MAY/JUN – 2013). (R 2013 NOV/DEC 2014) (R2013 NOV/DEC 2016)
Some of the applications of Stack are:
i. Parsing
6
ii. Expression evaluation
iii. Backtracking (game playing, finding paths, exhaustive searching)
iv. Memory management, run-time environment for nested language features.
4. List the applications of stack and queue. (R 2008/2010 MAY/JUN – 2014) (R 2013 May/JUN
2014)
Some of the applications of Stack are:
i. Parsing
ii. Expression evaluation
iii. Backtracking (game playing, finding paths, exhaustive searching)
iv. Memory management, run-time environment for nested language features.
Some of the applications of Queue are:
i. When a resource is shared among multiple consumers. E.g. CPU scheduling, Disk
Scheduling.
ii. When data is transferred asynchronously (data not necessarily received at same rate as
sent) between two processes. E.g. IO Buffers, pipes, file IO, etc.
iii. Operating systems often maintain a queue of processes that are ready to execute or that
are waiting for a particular event to occur.
5. Convert the following infix expression into postfix: (A+B)*(C+B)*(E/F). (R 2008 NOV/DEC-
2014)
(A+B)*(C+B)*(E/F)
= (AB+)*(CB+)*(EF/)
= AB+CB+*EF/*
6. Convert the expression ((A+B)*C-(D-E)^(F+G)) into its equivalent Postfix notation. (R
2008/2010 NOV/DEC – 2013)
((A+B)*C-(D-E)^(F+G))
= ((AB+)*C-(DE-)^(FG+))
= ((AB+)*C-(DE-FG+^))
=AB+C*DE-FG+^-
7. Given the infix for an expression, write its prefix a*b/c+d. (R 2013 May/ Jun 2016)
a*b/c+d
= *a b / c + d
= /*a b c + d
7
= + / + a b c d
8. Give the postfix notation of the expression: a^((b*c+d)/(e-f*g)). (R 2008 APR/MAY- 2013)
a^((b*c+d)/(e-f*g))
= a^ ((b*c+d)/(e-f*g))
= a^ ((bc*d+)/(efg*-))
= a^ (bc*d+efg*-/)
= abc*d+efg*-/^
9. Evaluate the following postfix expression using stack: 7 6 2 + * 4 5 1 - / + (R 2012
APR/MAY- 2013)
7 6 2
7,6,2  push,
+  two pops 6+2=8push
7 8
*two pops  7*8=56push
56 4 5 1
4,5,1  push,  two pops  5-1=4push
56 4 4
/two pops 4/4=1push
56 1
+ 
57
Answer : 57
10. Define Queue (R 2013 NOV/DEC-2016) (R 2013 Dec 15/ Jan 2016) (R2013 NOV/DEC 2016)
Queue is a linear data structure in which the insertion and deletion operations are performed at
two different ends. The insertion is performed at one end called the “REAR” and deletion is
performed at other end called the “FRONT”. Queue is also called as FIFO (First In First Out)
8
data structure, since the element that gets inside the queue first, is deleted first from the queue.
The insert operation is called as “enQueue” and deletion is called as deQueue”.
11. What is a Queue? List its advantages. (R 2008/2010 APR/ MAY – 2015)
Queue is a linear data structure in which the insertion and deletion operations are performed at
two different ends. The insertion is performed at one end called the “REAR” and deletion is
performed at other end called the “FRONT”. Queue is also called as FIFO (First In First Out)
data structure, since the element that gets inside the queue first, is deleted first from the queue.
The insert operation is called as “enQueue” and deletion is called as deQueue”.
The main advantages of Queue are:
i. They can be accesses at both the ends unlike the stack
ii. They are used to implement highly beneficial data structure called priority
queues and circular queues.
12. What are the necessary conditions to check for performing insertion and deletion
operations on a Queue? (R 2008 APR/MAY- 2012)
The necessary conditions to check for performing insertion and deletion operations in an array
implementation of queue are:
1. Before insertion, check if the queue is already filled. If so, further insertions cannot be done.
2. Before deleting an element from a queue, it should be checked if the queue is empty. If so, no
more deletions can be made.
13. What is a dequeue? (R 2012 APR/MAY- 2013)
The deletion operation in a Queue is also called as dequeue. Deletion is performed at one of the
queue called the “Front” end of the queue. Dequeue will delete the first element that entered the
queue.
9
14. What are double ended queues? (OR) Define double ended queue. (R 2013 APR/MAY 2017)
(R 2013 May/JUN 2014) (R 2013 NOV/DEC 2014) (R 2013 Dec 15/ Jan 2016) (R 2013 May/
Jun 2016)
Double ended queue or Deque is also a Queue data structure in which insertion and deletion
operations can be performed at both the ends (Front and Rear)
There are two types of Deque, they are:
1. Input Restricted Double Ended Queue (Insertion at only one end)
2. Output Restricted Double Ended Queue (Deletion at only one end)
Input Restricted Double Ended Queue
Output Restricted Double Ended Queue
10
Unit III NON LINEAR DATA STRUCTURES – TREES
1. What is the need for tree representation? (R 2008 NOV/DEC- 2014)
There are scenarios in real world that have a hierarchical relationship. In order to reflect the same
and solve problems relating to it, we are in need of tree representation.
2. Write an algorithm to declare nodes of a tree structure. (R 2008 APR/MAY – 2010)
A tree structure has a data field and two pointer fields to point to its left child and right child. A
tree node's declaration is given below:
struct node
{
int data;
node* left_child;
node* right_child;
};
3. Define depth and height of a tree. (OR) How do you find depth and height of the tree? Give
example. (R 2008 MAY/JUN- 2012) (R 2012 APR/MAY- 2013)
Height of tree : The height of a node in a tree is the number of edges on the longest path
between that node and a leaf. The height of a tree is the height of its root node.
Depth : In a tree, the total number of edges from root node to a leaf node in the longest path is
said to be Depth of the tree.
4. Define a full binary tree. Give an example. (R 2008/2010 NOV/DEC – 2013)
11
A full binary tree (sometimes proper binary tree or 2-tree) is a tree in which every node other than
the leaves has two children.
5. What are binary search trees? Give example. (R 2008 APR/MAY- 2013), (R 2008/2010
MAY/JUN – 2013)
Binary Search Tree, is a node-based binary tree data structure which has the following properties:
• The left subtree of a node contains only nodes with keys lesser than the node’s key.
• The right subtree of a node contains only nodes with keys greater than the node’s key.
• The left and right subtree each must also be a binary search tree. There must be no
duplicate nodes.
6. Write the algorithm for pre-order traversal? (OR) Write code to perform post order
traversal in a binary search tree. (OR) Number the following binary tree (Fig. 1) to traverse
it in. (a) Preorder (b) Inorder (R 2008/2010 APR/ MAY – 2015) (R 2012 NOV/DEC-2013) (R
2008 NOV/DEC - 2010)
Trees can be traversed in different ways due to their non-linear structure. Following are the
generally used ways for traversing trees.
12
Depth First Traversals:
(a) Inorder (Left, Root, Right) : 4 2 5 1 3
(b) Preorder (Root, Left, Right) : 1 2 4 5 3
(c) Postorder (Left, Right, Root) : 4 5 2 3 1
Breadth First or Level Order Traversal : 1 2 3 4 5
Inorder Traversal:
Algorithm Inorder (tree)
{
Until all nodes are traversed −
Step 1 − Recursively traverse left subtree.
Step 2 − Visit root node.
Step 3 − Recursively traverse right subtree.
}
Preorder Traversal:
Algorithm Preorder(tree)
{
Until all nodes are traversed −
Step 1 − Visit root node.
Step 2 − Recursively traverse left subtree.
Step 3 − Recursively traverse right subtree.
}
Postorder Traversal:
Algorithm Postorder(tree)
{
Until all nodes are traversed −
Step 1 − Recursively traverse left subtree.
Step 2 − Recursively traverse right subtree.
Step 3 − Visit root node.
}
7. Give an example for Expression Trees. (R 2008 APR/MAY – 2010)
Expression tree is a binary tree in which each internal node corresponds to operator and each leaf
node corresponds to operand. Example Arithmetic Expression: 3 + (5 + 9) * 2
13
8. Convert the following into an expression tree: (a+b)*(c/d)-e/f. (R 2008 APR/MAY- 2012)
9. Give the expression tree for the following: (a+b)*(( c+ d^ e)* f). (R 2008/2010 MAY/JUN –
2014)
10. Define the height balanced tree: AVL (OR) Define Balance Factor of AVL Tree. (R 2008
NOV/DEC- 2014) (R 2013, APR/ MAY 2017)
AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of
left and right subtrees cannot be more than one for all nodes. In an AVL tree, balance factor of
every node is either -1, 0 or +1.
Balance factor = heightOfLeftSubtree – heightOfRightSubtree
14
11. What is the minimum
number of nodes in AVL tree
of height 12? (R 2012
NOV/DEC-2013)
Minimum number of nodes
in a tree with height h can be
represented as:
N(h) = N(h-1) + N(h-2) + 1 for n>2 where N(0) = 1 and N(1) = 2.
Height 0 1 2 3 4 5 6 7 8 9 10 11 12
No. of
Nodes
1 2 4 7 12 20 33 54 88 143 232 376 609
Note:
If height of AVL tree is h, maximum number of nodes can be 2h+1
– 1.
Maximum number of nodes = 2 (12+1)
-1=8192-1=8191
12. Draw and explain the structure of a node in threaded binary tree. (OR) How to convert
binary tree into threaded binary tree. Give example. (R 2008/2010 MAY/JUN – 2014)
Threaded Binary Tree is also a binary tree in which all left child pointers that are NULL (in
Linked list representation) points to its in-order predecessor, and all right child pointers that are
NULL (in Linked list representation) points to its in-order successor.
Inorder Traversal of the Binary tree is : H - D - I
- B - E - A - F - J - C - G
13. What are threaded binary trees? Give its advantages. (OR) What are the advantages of
threaded binary trees over ordinary binary tree? (R 2008 NOV/DEC - 2010). (R 2008/2010
APR/ MAY – 2015) (R 2008/2010 MAY/JUN - 2013) , (R 2008 NOV/DEC- 2014)
15
Threaded Binary Tree is also a binary tree in which all left child pointers that are NULL (in
Linked list representation) points to its in-order predecessor, and all right child pointers that are
NULL (in Linked list representation) points to its in-order successor.
Advantages:
i. The non recursive traversal made in the threaded binary tree makes it faster than the
recursive traversal on an equivalent Binary tree.
ii. We can efficiently determine the predecessor and successor nodes starting from any node
without the use of an external stack.
iii. Any node can be accessible from any other node. Threads are usually more to upward
whereas links are downward. Thus in a threaded tree, one can move in either directions.
14. Define a heap. How can it be used to represent a priority queue? (OR) What is a heap?
(OR) What is heap order property? (OR) What are min-heap and max heap? (R 2008
NOV/DEC – 2010) (R 2008/2010 MAY/JUN – 2014) (R 2008 APR/MAY- 2013)
Heap is a special case of balanced binary tree data structure where the root-node key is compared
with its children and arranged accordingly. If α has child node β then : key(α) ≥ key(β). If the
value of parent is greater than that of child, this property generates Max Heap and if it is less
than that of its child, it is called as Min Heap. For Input → 35 33 42 10 14 19 27 44 26 31
Max Heap Min Heap
16
15. Give any two applications of binary heaps. (R 2008 NOV/DEC – 2010)
Binary heaps can be used in:
1. Finding the maximum (or minimum) value in a set of values.
2. Finding the kth smallest (or largest) element in an given set of values
3. Dijkstra's algorithm (shortest path)
4. Prim's algorithm (minimum spanning tree)
5. Huffman encoding (data compression)
16. What is B- tree. Give example. (R 2008/2010 MAY/JUN - 2013) , (R 2008/2010 MAY/JUN –
2014)
A B-tree is a self-balancing tree data structure that maintains sorted data and allows searches,
sequential access, insertions, and deletions in logarithmic time. The B-tree is a generalization of
a binary search tree in that a node can have more than two children. Unlike self-balancing binary
search trees, the B-tree is well suited for storage systems that read and write relatively large
blocks of data, such as discs. It is commonly used in databases and file systems.
17. List out the structural properties of B-Trees. (R 2008 APR/MAY – 2010)
B-Tree of Order m has the following properties:
• Property 1 - All the leaf nodes must be at same level.
• Property 2 - All nodes except root must have at least [m/2]-1 keys and maximum of m-1 keys.
• Property 3 - All non leaf nodes except root (i.e. all internal nodes) must have at least m/2
children.
• Property 4 - If the root node is a non leaf node, then it must have at least 2 children.
• Property 5 - A non leaf node with n-1 keys must have n number of children.
• Property 6 - All the key values within a node must be in Ascending Order.
• Property 7 - B-Tree grows and shrinks from the root which is unlike Binary Search Tree. Binary
Search Trees grow downward and also shrink from downward.
• Property 8 - Like other balanced Binary Search Trees, time complexity to search, insert and
delete is O(Logn).
17
18. What are the various operations that can be performed on a B tree. (OR) List out the various
operations that can be performed on B trees. (R 2013, NOV/ DEC 2015) (R 2013, MAY/JUN
2016)
A B-tree is a self-balancing tree data structure that maintains sorted data and allows the following
operations in logarithmic time:
i. Searches
ii. Sequential access
iii. Insertions
iv. Deletions
Unit IV NON LINEAR DATA STRUCTURES – GRAPH
1. With a simple example, demonstrate the ways of representing a Graph. What are the
different ways of representing a graph? Explain each of them. (R 2013, APR/ MAY 2015) (R
2008 APR/MAY- 2012)
Graph is a data structure that consists of following two components:
1. A finite set of vertices also called as nodes.
2. A finite set of ordered pair of the form (u, v) called as edge.
Graph data structure is represented using following representations:
1. Adjacency Matrix
2. Adjacency List
1. Graph (b) Adjacency List (c) Adjacency Matrix
2. Define in degree of graph. (R 2008/2010 APR/ MAY – 2015)
Degree of a Graph : Total number of edges connected to a vertex is said to be degree of that
vertex.
18
In degree : Total number of incoming edges connected to a vertex is said to be indegree of that
vertex.
Out degree : Total number of outgoing edges connected to a vertex is said to be outdegree of that
vertex.
3. What is an undirected graph? (R 2008/2010 APR/ MAY – 2015)
In an unweighted graph, the edge (u,v) is an aordered pair and it is the same as (v,u). traversal can
be done in both the directions. It is a bidirectional graph.
4. What is breadth-first traversal? (R 2008 NOV/DEC - 2010)
Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data
structures. It starts at the tree root or some arbitrary node in a graph and explores all of the
neighbor nodes at the present depth prior to moving on to the nodes at the next depth level. . BFS
traversal produces a spanning tree (without loops) of the graph as a final result.
BFS Traversal Result: 1,2,3,4,5
5. Write procedure for Depth First Search Algorithm. (R 2013, APR/ MAY 2017)
The purpose of the algorithm is to mark each vertex as visited while avoiding cycles. A standard
DFS implementation puts each vertex of the graph into one of two categories:
1. Visited
2. Not Visited
The DFS algorithm works as follows:
19
1. Start by putting any one of the graph's vertices on top of a stack.
2. Take the top item of the stack and add it to the visited list.
3. Create a list of that vertex's adjacent nodes. Add the ones which aren't in the visited list to
the top of stack.
4. Keep repeating steps 2 and 3 until the stack is empty.
Note: Definition of DFS
Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures.
The algorithm starts at the root node or an arbitrary node and explores as far as possible along
each branch before backtracking.
DFS Traversal: 1,2,4,5,3
6. Define spanning tree of a graph.(OR) What is a spanning tree? (R 2008 NOV/DEC - 2010),
(R 2008/2010 NOV/DEC - 2013)
A spanning tree is a subset of Graph G, which has all the vertices covered with minimum possible
number of edges. Hence, a spanning tree does not have cycles and it cannot be disconnected
7. Define minimum spanning tree for a graph. (R 2013, NOV/ DEC 2016)
A spanning tree is a subset of Graph G, which has all the vertices covered with minimum possible
number of edges. Hence, a spanning tree does not have cycles and it cannot be disconnected
In a weighted graph, a minimum spanning tree is a spanning tree that has minimum weight than
all other spanning trees of the same graph
20
8. Give the adjacency list and matrix representation for the following graph. (R 2012
APR/MAY- 2013) (R 2008/2010 MAY/JUN - 2014)
(a) Given Graph (b) Adjacency List (c) Adjacency Matrix
9. Write at least two applications of graphs. (R 2008 NOV/DEC- 2014)
Graphs are used in various fields to represent a scenario and to find a solution to it. Few of them
are: Social network graphs, Transportation networks, Utility graphs like power Grid and Internet,
Protein-protein interactions graphs, Network packet traffic graphs, Neural networks, etc.
10. What is biconnected graph? Give example. (OR) What is biconnectivity? Give example. (R
2008 APR/MAY – 2010) (R 2008/2010 MAY/JUN - 2014)
A biconnected graph is a connected and "non-separable" graph, meaning that if any
one vertex were to be removed, the graph will remain connected. This property possessed by a
graph is called Biconnectivity.
.
11. What are articulation points? (R 2008/2010 MAY/JUN - 2013)
21
A vertex in an undirected connected graph is an articulation point (or cut vertex) if and only if,
removing it disconnects the graph. Articulation points represent vulnerabilities in a connected
network i.e., single points whose failure which would split the network into 2 or more
disconnected components. They are useful for designing reliable networks.
12. What are Euler Circuits? (R 2008/2010 NOV/DEC - 2013)
Eulerian Path is a path in graph that visits every edge exactly once. Eulerian Circuit is an Eulerian
Path which starts and ends on the same vertex.
13. What is topological sort? Give algorithm. (OR) What is topological sorting? (OR) ) State
the principle of topological Sorting. (R 2008 APR/MAY - 2010), (R 2008 NOV/DEC- 2014) (R
2013, NOV/ DEC 2015 (R 2013, APR/ MAY 2017)
Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that
for every directed edge uv, vertex u comes before v in the ordering. Topological Sorting for a
graph is not possible if the graph is not a DAG.
One of the Topological sorts of this graph is: 1,2,3,4,5.
14. What is greedy algorithm? Mention any one problem that use this algorithm design
technique. (R 2008 APR/MAY- 2012)
22
A greedy algorithm is an algorithmic paradigm that solves a problem in stages by making the
locally optimal choice at each stage in order to find a global optimum. In many problems, a
greedy strategy does not usually produce an optimal solution, but may yield locally optimal
solutions that approximate a globally optimal solution in a reasonable amount of time. Dijkstra’s
algorithm to find the shortest path in a graph is a greedy algorithm.
15. What is the minimum number of spanning trees possible for a complete binary graph tree
with n vertices? (R 2013, NOV/ DEC 2015)
Type of Graph Total Number Spanning Trees
G itself is a tree 1
G is a cyclic graph with n vertices. n
G is a complete graph with n vertices nn − 2
G is a complete bipartite graph with p vertices
and q edges
p(q-1)
q(p-1)
Unit V SEARCHING, SORTING AND HASHING TECHNIQUES
1. What is the difference between linear search and binary search? Compare linear and
binary search algorithm techniques. What is the difference between linear search and
binary search? What is the time complexity of binary search? (R 2013 NOV/DEC-2016)
(R 2013 May/JUN 2014) (R 2012 NOV/DEC-2013) (R2013 NOV/DEC 2016)
Linear Search Binary Search
Input can be random Input must be sorted
Elements are accessed sequentially
(Iterative algorithm)
Sequential access is not done
(Divide and Conquer
Algorithm)
Performs equality comparison Performs Ordering Comparison
Can be implemented on Arrays or
Linked Lists
Can be implemented only on an
Array and not on a linked list.
Time Complexity is O(n) Time Complexity is O(log n)
23
2. Should arrays or linked lists be used for the following types of applications? Justify your
answer. (R 2013 May/JUN 2014)
(a) Many search operations in sorted list
(b) Many search operations in unsorted list
a. Binary search yields faster results on sorted list. Since binary search performs random
access, it can be done only on an array. Linked list cannot be used for Binary search
operation.
b. If the list of elements is unsorted, then the only possible searching will be to scan the
elements in a sequential fashion. This is done using the Linear search algorithm and it can
be done on an Array or a Linked List.
3. List sorting algorithm which uses logarithmic time complexity. What is the time complexity
of the insertion sort? (R 2013 May/JUN 2014) (R 2013 May/ Jun 2016)
Algorithm Time Complexity (Worst Case)
Selection Sort O(n2
)
Bubble Sort O(n2
)
Insertion Sort O(n2
)
Heap Sort O(n log(n))
Quick Sort O(n2
)
Merge Sort O(n log(n))
Shell Sort O(n log (n))
Radix Sort O(nk)
Linear Search O(n)
Binary Search O(log n)
24
4. Differentiate internal and external sorting. Differentiate between the internal and external
sorting techniques. (R 2013 NOV/DEC 2014) (R 2012 NOV/DEC-2013)
Internal Sorting External Sorting
All the data to sort is stored in memory
at all times while sorting is in progress
Data is stored outside memory (like on
disk) and only loaded into memory in
small chunks.
Arrays can be used to hold the elements
for sorting.
Linked representation should be used
for external sorting.
Eg. Shell Sort Eg. Merge Sort
5. Sort the following numbers using bubble sort 10, 5, 7, 11, 4, 1 (R 2013 Dec 15/ Jan 2016)
Pass I
10 5 5 5 5 5
5 10 7 7 7 7
7 7 10 10 10 10
11 11 11 11 4 4
4 4 4 4 11 1
1 1 1 1 1 11
Pass II
5 5 5
7 7 7
10 4 4
4 10 1
1 1 10
11 11 11
25
Pass III
5 5 5
7 4 4
4 7 1
1 1 7
10 10 10
11 11 11
Pass IV
5 4 4
4 5 1
1 1 5
7 7 7
10 10 10
11 11 11
Pass V
4 1
1 4
5 5
7 7
10 10
11 11
Sorted List
1
4
5
7
10
11
6. Show the result of sorting the following numbers using insertion sort (step by step o/p): 4 7
3 2 5 1 6 . Sort the following numbers using insertion sort. 3, 1, 4, 1, 5, 9, 2, 6, 5. Sort the
following numbers using insertion sort: 9 5 2 3 26 1 4 53 46 8 17. (R 2008 APR/MAY-
2013) (R 2012 APR/MAY- 2013) (R 2013 APR/MAY 2017).
Stages of Insertion Sort: (4 7 3 2 5 1 6)
4 4 3 2 2 1 1
7 7 4 3 3 2 2
3 3 7 4 4 3 3
2 2 2 7 5 4 4
5 5 5 5 7 5 5
1 1 1 1 1 7 6
26
6 6 6 6 6 6 7
7. Name the sorting techniques which use the divide and conquer stratergy. Name the sorting
techniques which use the divide and conquer strategy. (R2013 NOV/DEC 2016) (R 2013
NOV/DEC-2016)
Merge sort and Quick sort are some of the divide and conquer techniques. The worst case time
complexities are: Merge sort - O(n log n), Quick sort – O(n2
)
8. What is hashing? Define Hash function. Define hashing. What is hashing? (R 2013 May/ Jun
2016) (R 2008 NOV/DEC - 2010) (R 2008 NOV/DEC- 2014) (R 2013 Dec 15/ Jan 2016)
Hashing is a process of indexing and retrieving elements (data) in a data structure called the hash
table to provide faster way of finding the element using the hash key.
Hash table is just an array which maps a key (data) into the data structure with the help of hash
function such that insertion, deletion and search operations can be performed with constant time
complexity (i.e. O(1).
Hash function is a function which takes a piece of data (i.e. key) as input and outputs an integer
(i.e. hash value) which maps the data to a particular index in the hash table.
9. What is primary clustering? (R 2008/2010 MAY/JUN - 2013)
Primary Clustering is the tendency for a collision resolution scheme such as linear probing
to create long runs of filled slots near the hash position of keys.
In Linear probing method of open address hashing, the item which are hashed to the same
location are placed in the next available position. This will create blocks of data whenever there is
collision. If the primary hash index is x, subsequent probes to search or to place an element in the
table goes thorough indexes x+1, x+2, x+3and so on, this is called Primary Clustering.
For example, insert the nodes 89, 18, 49, 58, and 69 into a hash table that holds 10 items using the
division method
27
Numbers 49 and 69 are held inside the primary cluster.
10. What is rehashing? (OR) Define rehashing. How are collisions handled while hashing? (R
2008 MAY/JUN- 2012) (R 2008/2010 MAY/JUN - 2013), (R 2008 APR/MAY- 2013), (R
2008/2010 NOV/DEC - 2013), (R 2008/2010 MAY/JUN - 2014)
Rehashing is done in Open addressing modes of hashing. Hash tables offer exceptional
performance when not overly full. Load factor is maintained λ < 0.5 for better performance.
When the load factor goes above 0.5 (i.e., Table is more than half filled), we go for rehashing.
Here, the table size is doubled and the new Hash function = Key % (new table size) is used
and the values from the previous hash table are mapped to this new table using the new hash
function. Rehashing reduces the load factor well below 0.5. Now the table is ready for further
entries.
11. Give the significance of extendible hashing. (R 2013 APR/MAY 2017)
Extendible hashing is a type of hash system which treats a hash as a bit string, and uses a trie for
bucket lookup. Because of the hierarchical nature of the system, re-hashing is an incremental
operation (done one bucket at a time, as needed). This means that time-sensitive applications are
less affected by table growth than by standard full-table rehashes. It is a dynamic hashing
approach.
12. Mention the difference between Hashing & Extendible Hashing with example.. Write how
extensible hashing is better than rehashing. Define extendible hashing. (R 2013 NOV/DEC
2014) (R 2008 APR/MAY - 2010) (R 2008 APR/MAY- 2012)
Unlike the rehashing operation in open addressing scheme, the rehashing in extendible hashing is
only an incremental process of increasing one bucket at a time and hence the approach is
dynamic. This also helps in maintaining the performance even after a number of additions and
deletions.
28

More Related Content

What's hot

STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTUREArchie Jamwal
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applicationsJsaddam Hussain
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applicationssomendra kumar
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna universitysangeethajames07
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queueRojan Pariyar
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)Huba Akhtar
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESSowmya Jyothi
 
Data Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptxData Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptxEllenGrace9
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxShreyasLawand
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked ListNinad Mankar
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 

What's hot (20)

Queue ppt
Queue pptQueue ppt
Queue ppt
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna university
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Data Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptxData Structures and Algorithm - Module 1.pptx
Data Structures and Algorithm - Module 1.pptx
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptx
 
Stacks
StacksStacks
Stacks
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 

Similar to CS8391 Data Structures Anna University Questions and Answers

Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testspriyanshukumar97908
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfraji175286
 
2 marks- DS using python
2 marks- DS using python2 marks- DS using python
2 marks- DS using pythonLavanyaJ28
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptxSaralaT3
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptxsarala9
 
Data Structure
Data Structure Data Structure
Data Structure Ibrahim MH
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data StructureJazz Jinia Bhowmik
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdfSulabhPawaia
 
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCEARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCEVenugopalavarma Raja
 
data structure programing language in c.ppt
data structure programing language in c.pptdata structure programing language in c.ppt
data structure programing language in c.pptLavkushGupta12
 
data structures module I & II.pptx
data structures module I & II.pptxdata structures module I & II.pptx
data structures module I & II.pptxrani marri
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .pptpoonamsngr
 
Data-Structure-original-QuantumSupply.pdf
Data-Structure-original-QuantumSupply.pdfData-Structure-original-QuantumSupply.pdf
Data-Structure-original-QuantumSupply.pdflehal93146
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptxssuserd2f031
 

Similar to CS8391 Data Structures Anna University Questions and Answers (20)

Data structure
 Data structure Data structure
Data structure
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and tests
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdf
 
2 marks- DS using python
2 marks- DS using python2 marks- DS using python
2 marks- DS using python
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
Data Structure
Data Structure Data Structure
Data Structure
 
UNITIII LDS.pdf
UNITIII LDS.pdfUNITIII LDS.pdf
UNITIII LDS.pdf
 
Intro ds
Intro dsIntro ds
Intro ds
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data Structure
 
General Data structures
General Data structuresGeneral Data structures
General Data structures
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf
 
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCEARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
 
data structure programing language in c.ppt
data structure programing language in c.pptdata structure programing language in c.ppt
data structure programing language in c.ppt
 
DS_PPT.pptx
DS_PPT.pptxDS_PPT.pptx
DS_PPT.pptx
 
data structures module I & II.pptx
data structures module I & II.pptxdata structures module I & II.pptx
data structures module I & II.pptx
 
DS_PPT.ppt
DS_PPT.pptDS_PPT.ppt
DS_PPT.ppt
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .ppt
 
Data-Structure-original-QuantumSupply.pdf
Data-Structure-original-QuantumSupply.pdfData-Structure-original-QuantumSupply.pdf
Data-Structure-original-QuantumSupply.pdf
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 

More from P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai

More from P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai (20)

TestFile
TestFileTestFile
TestFile
 
3.1 Trees ( Introduction, Binary Trees & Binary Search Trees)
3.1 Trees ( Introduction, Binary Trees & Binary Search Trees)3.1 Trees ( Introduction, Binary Trees & Binary Search Trees)
3.1 Trees ( Introduction, Binary Trees & Binary Search Trees)
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
2.2 stack applications Infix to Postfix & Evaluation of Post Fix2.2 stack applications Infix to Postfix & Evaluation of Post Fix
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
 
1. 6 doubly linked list
1. 6 doubly linked list1. 6 doubly linked list
1. 6 doubly linked list
 
1. 5 Circular singly linked list
1. 5 Circular singly linked list1. 5 Circular singly linked list
1. 5 Circular singly linked list
 
1. 4 Singly linked list deletion
1. 4 Singly linked list deletion1. 4 Singly linked list deletion
1. 4 Singly linked list deletion
 
1. 3 singly linked list insertion 2
1. 3 singly linked list   insertion 21. 3 singly linked list   insertion 2
1. 3 singly linked list insertion 2
 
1. 2 Singly Linked List
1. 2 Singly Linked List1. 2 Singly Linked List
1. 2 Singly Linked List
 
1. C Basics for Data Structures Bridge Course
1. C Basics for Data Structures   Bridge Course1. C Basics for Data Structures   Bridge Course
1. C Basics for Data Structures Bridge Course
 
Approximation Algorithms TSP
Approximation Algorithms   TSPApproximation Algorithms   TSP
Approximation Algorithms TSP
 
Optimal binary search tree dynamic programming
Optimal binary search tree   dynamic programmingOptimal binary search tree   dynamic programming
Optimal binary search tree dynamic programming
 
The stable marriage problem iterative improvement method
The stable marriage problem iterative improvement methodThe stable marriage problem iterative improvement method
The stable marriage problem iterative improvement method
 
Maximum matching in bipartite graphs iterative improvement method
Maximum matching in bipartite graphs   iterative improvement methodMaximum matching in bipartite graphs   iterative improvement method
Maximum matching in bipartite graphs iterative improvement method
 
Knapsack dynamic programming formula top down (1)
Knapsack dynamic programming formula top down (1)Knapsack dynamic programming formula top down (1)
Knapsack dynamic programming formula top down (1)
 
Knapsack dynamic programming formula bottom up
Knapsack dynamic programming formula bottom upKnapsack dynamic programming formula bottom up
Knapsack dynamic programming formula bottom up
 
Huffman tree coding greedy approach
Huffman tree coding  greedy approachHuffman tree coding  greedy approach
Huffman tree coding greedy approach
 
Simplex method
Simplex methodSimplex method
Simplex method
 
Simplex method
Simplex methodSimplex method
Simplex method
 
Multiplication of integers &amp; strassens matrix multiplication subi notes
Multiplication of integers &amp; strassens matrix multiplication   subi notesMultiplication of integers &amp; strassens matrix multiplication   subi notes
Multiplication of integers &amp; strassens matrix multiplication subi notes
 

Recently uploaded

The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 

Recently uploaded (20)

(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 

CS8391 Data Structures Anna University Questions and Answers

  • 1. CS8391 DATA STRUCTURES ANNA UNIVERSITY QUESTIONS AND ANSWERS TWO MARK FROM REGULATION 2008 &2013 QUESTION PAPERS COMPILED BY: DR. P. SUBATHRA. M.E., Ph.D., PROFESSOR IN INFORMATION TECHNOLOGY KAMARAJ COLLEGE OF ENGINEERING AND TECHNOLOGY MADURAI DISTRICT, NEAR VIRUDHUNAGAR, TAMIL NADU, INDIA UNIT I - LINEAR DATA STRUCTURES 1
  • 2. 1. What is an ADT? Give an example. (OR) Define an abstract type. List out few. (OR) What are abstract data types? (R 2013 NOV/DEC-2016), (R 2008/2010 MAY/JUN - 2013), (R 2008 MAY/JUN- 2012), (R 2008 NOV/DEC - 2010), (R 2008/2010 NOV/DEC - 2013) (R 2013 NOV/DEC 2014)(R 2013 DEC 15/ JAN 2016) (R 2013 MAY/ JUN 2016)(R2013 NOV/DEC 2016) (R 2013 APR/MAY 2017) An Abstract Data Type (ADT) is a mathematical model for data types, which gives a set of operations available to the user but never states the details of its implementation. Abstract Data Type: 1. Declaration of data 2. Declaration of operations. Eg. Objects such as list, stack, queue, graphs along with their operations can be viewed as ADTs 2. What is the purpose of using ADTs in programs? (OR) What is advantage of an ADT? (R 2008 APR/MAY- 2012) (R 2013 May/JUN 2014) The main purpose of using ADTs is use utilize the following advantages of them: 1. Easy to debug small routines than large ones. 2. Easy for several people to work on a modular program simultaneously. 3. A modular program places certain dependencies in only one routine, making changes easier. 3. What are all not concerned in an ADT? (R 2008 NOV/DEC - 2010) The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented. It does not specify: • How data will be organized in memory? • What algorithms will be used for implementing the operations? 4. What is Data Structures? How is it classified? (R 2013 NOV/DEC-2016) Data Structures represents the logical relationship that exists between individual elements of data to carry out certain tasks. It defines a way of organizing all data items that consider not only the elements stored, but also the relationship between the elements. Data Structures is basically classified into two namely: (i) Primary Data Structures (integers, floats, characters) (ii) Secondary Data Structures (List, Stack, Queue, Graph) Secondary Data Structures is classified into: (i) Linear Data Structures (Lists) (ii) Non-Linear Data Structures (Trees, Graphs) 5. Is linked list better than an arrayed list? Give at least two reasons for your answer. (OR) What are the advantages of linked lists over arrays? (OR) What are the advantages and disadvantages of linked lists over arrays? (R 2008 APR/MAY- 2013) (R 2013 Dec 15/ Jan 2016) (R 2013 APR/MAY 2017) 2
  • 3. Linked list have few advantages than the arrays, but there are also some drawbacks with respect to the arrays. Some of the advantages of lists are: 1. Dynamic size 2. Easy insertion and deletion Some of the drawbacks of lists are: 1. Random access is not allowed. We have to access elements sequentially starting from the first node. So we cannot do binary search with linked lists. 2. Extra memory space for a pointer is required with each element of the list. 3. Arrays have better cache locality that can make a pretty big difference in performance. 6. What is the Data Structure used to perform recursion? (R 2008 MAY/JUN- 2012) Stack is the Data Structure that is used to perform recursion. The recursive calls return to the latest called location which demands a Last in First Out structure which is guaranteed by a STACK Data Structure. 7. Explain why binary search cannot be performed on a linked list. (R 2008 NOV/DEC - 2010) Binary search can be done only on a sorted list and also the list needs to be accessed in the middle at a random position. One of the limitations of Linked list is that, random access is not allowed. We have to access elements sequentially starting from the first node. So we cannot do binary search with linked lists. 8. Define List Abstract Data Type with example. (R 2008 APR/MAY - 2010) A list or sequence is an abstract data type that represents a countable number of ordered values, where the same value may occur more than once. List ADT is a sequential storage structure. General list of the form a1, a2, a3.…., an and the size of the list is 'n'. Any element in the list at the position i is defined to be ai, ai+1 the successor of ai and ai-1 is the predecessor of ai. e.g. Singly Linked list, Doubly linked list. 9. Write algorithms to insert and delete an element from a linked list. (R 2008 NOV/DEC- 2014) There are a number of choices to insert an element into a list and to delete an element from a list. Here insertion and deletion at the first position is considered: Inserting At Beginning of the list • Step 1: Create a newNode with given value. • Step 2: Check whether list is Empty (head == NULL) • Step 3: If it is Empty then, set newNode→next = NULL and head = newNode. • Step 4: If it is Not Empty then, set newNode→next = head and head = newNode. 3
  • 4. Deleting from Beginning of the list • Step 1: Check whether list is Empty (head == NULL) • Step 2: If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function. • Step 3: If it is Not Empty then, define a Node pointer 'temp' and initialize with head. • Step 4: Check whether list is having only one node (temp → next == NULL) • Step 5: If it is TRUE then set head = NULL and delete temp (Setting Empty list conditions) • Step 6: If it is FALSE then set head = temp → next, and delete temp. 10. Clearly distinguish between linked lists and arrays. Mention their relative advantages and disadvantages. (R 2008 MAY/JUN- 2012) Arrays Linked List Size of any array is fixed Size of list is variable It is necessary to specify the number of elements during declaration It is not necessary to specify the number of elements during declaration Insertion and deletions are difficult and costly Insertions and deletions are done in less time It occupies less memory than a linked list It occupies more memory Coding is easy Careful coding is needed to avoid memory errors. 11. Provide the asymptotic complexity for calculating the Sum of n number in an array. (R 2012 NOV/DEC-2013) The algorithm to find the sum of n number in an array is given below: Sum_num() { temp_sum = 0 for i in 1 ...array.length temp_sum = temp_sum + array[i] } If ‘ n’ is the size of array and all we have to do is iterate from beginning to the end of the array once and so the Big O notation is O(n). 12. List the four major operations in linear data structures. (R 2008/2010 APR/ MAY - 2015) Some of the major operations in a linear data structure are listed below: 4
  • 5. 1. Insertion 2. Deletion 3. Search 4. Print 5. Find the Kth Element 6. Make Empty 13. What is circular linked list? (R 2013 NOV/DEC 2014) (R 2013 May/ Jun 2016) Circular Linked List is a variation of Linked list in which the first element points to the last element and the last element points to the first element. Both Singly Linked List and Doubly Linked List can be made into a circular linked list. SinglyLinkedListasCircular –The next pointer of the last node points to the first node. DoublyLinkedListas Circular-The next pointer of the last node points to the first node and the previous pointer of the first node points to the last node making the circular in both directions. 14. Define a linear and non-linear data structure. Give an example for each. (R 2008/2010 NOV/DEC - 2013) Linear data structures: Linear data structures are data structures having a linear relationship between its adjacent elements. Eg) Linked lists, Doubly Linked Lists, Stacks, Queues Non-linear data structures: Non-linear data structures are data structures that don’t have a linear relationship between its 5
  • 6. adjacent elements but have a hierarchical relationship between the elements. Eg) Trees and Graphs Unit II - LINEAR DATA STRUCTURES - STACKS, QUEUE 1. Write an ADT for insertion in a stack. (R 2008/2010 MAY/JUN – 2014) Insertion operation in a stack is called as PUSH. This operation inserts an element at one end of the stack called the Top. Algorithm is given below: push: stack, data { if stack is full return null endif top ← top + 1 stack[top] ← data end procedure } 2. Define stack. List some of the applications of stack. (R 2013 APR/MAY 2017) Stack is a linear data structure, where the operations like insertion and deletion are restricted to one end called the TOP. The insertion operation is called PUSH and the delete operation is called as the POP. It is also called as a LIFO data structure because, the element that enters the stack last will be accessed first. Some of the applications of Stack are: i. Parsing ii. Expression evaluation iii. Backtracking (game playing, finding paths, exhaustive searching) iv. Memory management, run-time environment for nested language features 3. Mention the Applications of stack. (OR) Give the applications of stack. (OR) Give any two applications of stack. (R 2008 APR/MAY - 2010), (R 2013 NOV/DEC-2016), (R 2008/2010 MAY/JUN – 2013). (R 2013 NOV/DEC 2014) (R2013 NOV/DEC 2016) Some of the applications of Stack are: i. Parsing 6
  • 7. ii. Expression evaluation iii. Backtracking (game playing, finding paths, exhaustive searching) iv. Memory management, run-time environment for nested language features. 4. List the applications of stack and queue. (R 2008/2010 MAY/JUN – 2014) (R 2013 May/JUN 2014) Some of the applications of Stack are: i. Parsing ii. Expression evaluation iii. Backtracking (game playing, finding paths, exhaustive searching) iv. Memory management, run-time environment for nested language features. Some of the applications of Queue are: i. When a resource is shared among multiple consumers. E.g. CPU scheduling, Disk Scheduling. ii. When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes. E.g. IO Buffers, pipes, file IO, etc. iii. Operating systems often maintain a queue of processes that are ready to execute or that are waiting for a particular event to occur. 5. Convert the following infix expression into postfix: (A+B)*(C+B)*(E/F). (R 2008 NOV/DEC- 2014) (A+B)*(C+B)*(E/F) = (AB+)*(CB+)*(EF/) = AB+CB+*EF/* 6. Convert the expression ((A+B)*C-(D-E)^(F+G)) into its equivalent Postfix notation. (R 2008/2010 NOV/DEC – 2013) ((A+B)*C-(D-E)^(F+G)) = ((AB+)*C-(DE-)^(FG+)) = ((AB+)*C-(DE-FG+^)) =AB+C*DE-FG+^- 7. Given the infix for an expression, write its prefix a*b/c+d. (R 2013 May/ Jun 2016) a*b/c+d = *a b / c + d = /*a b c + d 7
  • 8. = + / + a b c d 8. Give the postfix notation of the expression: a^((b*c+d)/(e-f*g)). (R 2008 APR/MAY- 2013) a^((b*c+d)/(e-f*g)) = a^ ((b*c+d)/(e-f*g)) = a^ ((bc*d+)/(efg*-)) = a^ (bc*d+efg*-/) = abc*d+efg*-/^ 9. Evaluate the following postfix expression using stack: 7 6 2 + * 4 5 1 - / + (R 2012 APR/MAY- 2013) 7 6 2 7,6,2  push, +  two pops 6+2=8push 7 8 *two pops  7*8=56push 56 4 5 1 4,5,1  push,  two pops  5-1=4push 56 4 4 /two pops 4/4=1push 56 1 +  57 Answer : 57 10. Define Queue (R 2013 NOV/DEC-2016) (R 2013 Dec 15/ Jan 2016) (R2013 NOV/DEC 2016) Queue is a linear data structure in which the insertion and deletion operations are performed at two different ends. The insertion is performed at one end called the “REAR” and deletion is performed at other end called the “FRONT”. Queue is also called as FIFO (First In First Out) 8
  • 9. data structure, since the element that gets inside the queue first, is deleted first from the queue. The insert operation is called as “enQueue” and deletion is called as deQueue”. 11. What is a Queue? List its advantages. (R 2008/2010 APR/ MAY – 2015) Queue is a linear data structure in which the insertion and deletion operations are performed at two different ends. The insertion is performed at one end called the “REAR” and deletion is performed at other end called the “FRONT”. Queue is also called as FIFO (First In First Out) data structure, since the element that gets inside the queue first, is deleted first from the queue. The insert operation is called as “enQueue” and deletion is called as deQueue”. The main advantages of Queue are: i. They can be accesses at both the ends unlike the stack ii. They are used to implement highly beneficial data structure called priority queues and circular queues. 12. What are the necessary conditions to check for performing insertion and deletion operations on a Queue? (R 2008 APR/MAY- 2012) The necessary conditions to check for performing insertion and deletion operations in an array implementation of queue are: 1. Before insertion, check if the queue is already filled. If so, further insertions cannot be done. 2. Before deleting an element from a queue, it should be checked if the queue is empty. If so, no more deletions can be made. 13. What is a dequeue? (R 2012 APR/MAY- 2013) The deletion operation in a Queue is also called as dequeue. Deletion is performed at one of the queue called the “Front” end of the queue. Dequeue will delete the first element that entered the queue. 9
  • 10. 14. What are double ended queues? (OR) Define double ended queue. (R 2013 APR/MAY 2017) (R 2013 May/JUN 2014) (R 2013 NOV/DEC 2014) (R 2013 Dec 15/ Jan 2016) (R 2013 May/ Jun 2016) Double ended queue or Deque is also a Queue data structure in which insertion and deletion operations can be performed at both the ends (Front and Rear) There are two types of Deque, they are: 1. Input Restricted Double Ended Queue (Insertion at only one end) 2. Output Restricted Double Ended Queue (Deletion at only one end) Input Restricted Double Ended Queue Output Restricted Double Ended Queue 10
  • 11. Unit III NON LINEAR DATA STRUCTURES – TREES 1. What is the need for tree representation? (R 2008 NOV/DEC- 2014) There are scenarios in real world that have a hierarchical relationship. In order to reflect the same and solve problems relating to it, we are in need of tree representation. 2. Write an algorithm to declare nodes of a tree structure. (R 2008 APR/MAY – 2010) A tree structure has a data field and two pointer fields to point to its left child and right child. A tree node's declaration is given below: struct node { int data; node* left_child; node* right_child; }; 3. Define depth and height of a tree. (OR) How do you find depth and height of the tree? Give example. (R 2008 MAY/JUN- 2012) (R 2012 APR/MAY- 2013) Height of tree : The height of a node in a tree is the number of edges on the longest path between that node and a leaf. The height of a tree is the height of its root node. Depth : In a tree, the total number of edges from root node to a leaf node in the longest path is said to be Depth of the tree. 4. Define a full binary tree. Give an example. (R 2008/2010 NOV/DEC – 2013) 11
  • 12. A full binary tree (sometimes proper binary tree or 2-tree) is a tree in which every node other than the leaves has two children. 5. What are binary search trees? Give example. (R 2008 APR/MAY- 2013), (R 2008/2010 MAY/JUN – 2013) Binary Search Tree, is a node-based binary tree data structure which has the following properties: • The left subtree of a node contains only nodes with keys lesser than the node’s key. • The right subtree of a node contains only nodes with keys greater than the node’s key. • The left and right subtree each must also be a binary search tree. There must be no duplicate nodes. 6. Write the algorithm for pre-order traversal? (OR) Write code to perform post order traversal in a binary search tree. (OR) Number the following binary tree (Fig. 1) to traverse it in. (a) Preorder (b) Inorder (R 2008/2010 APR/ MAY – 2015) (R 2012 NOV/DEC-2013) (R 2008 NOV/DEC - 2010) Trees can be traversed in different ways due to their non-linear structure. Following are the generally used ways for traversing trees. 12
  • 13. Depth First Traversals: (a) Inorder (Left, Root, Right) : 4 2 5 1 3 (b) Preorder (Root, Left, Right) : 1 2 4 5 3 (c) Postorder (Left, Right, Root) : 4 5 2 3 1 Breadth First or Level Order Traversal : 1 2 3 4 5 Inorder Traversal: Algorithm Inorder (tree) { Until all nodes are traversed − Step 1 − Recursively traverse left subtree. Step 2 − Visit root node. Step 3 − Recursively traverse right subtree. } Preorder Traversal: Algorithm Preorder(tree) { Until all nodes are traversed − Step 1 − Visit root node. Step 2 − Recursively traverse left subtree. Step 3 − Recursively traverse right subtree. } Postorder Traversal: Algorithm Postorder(tree) { Until all nodes are traversed − Step 1 − Recursively traverse left subtree. Step 2 − Recursively traverse right subtree. Step 3 − Visit root node. } 7. Give an example for Expression Trees. (R 2008 APR/MAY – 2010) Expression tree is a binary tree in which each internal node corresponds to operator and each leaf node corresponds to operand. Example Arithmetic Expression: 3 + (5 + 9) * 2 13
  • 14. 8. Convert the following into an expression tree: (a+b)*(c/d)-e/f. (R 2008 APR/MAY- 2012) 9. Give the expression tree for the following: (a+b)*(( c+ d^ e)* f). (R 2008/2010 MAY/JUN – 2014) 10. Define the height balanced tree: AVL (OR) Define Balance Factor of AVL Tree. (R 2008 NOV/DEC- 2014) (R 2013, APR/ MAY 2017) AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than one for all nodes. In an AVL tree, balance factor of every node is either -1, 0 or +1. Balance factor = heightOfLeftSubtree – heightOfRightSubtree 14
  • 15. 11. What is the minimum number of nodes in AVL tree of height 12? (R 2012 NOV/DEC-2013) Minimum number of nodes in a tree with height h can be represented as: N(h) = N(h-1) + N(h-2) + 1 for n>2 where N(0) = 1 and N(1) = 2. Height 0 1 2 3 4 5 6 7 8 9 10 11 12 No. of Nodes 1 2 4 7 12 20 33 54 88 143 232 376 609 Note: If height of AVL tree is h, maximum number of nodes can be 2h+1 – 1. Maximum number of nodes = 2 (12+1) -1=8192-1=8191 12. Draw and explain the structure of a node in threaded binary tree. (OR) How to convert binary tree into threaded binary tree. Give example. (R 2008/2010 MAY/JUN – 2014) Threaded Binary Tree is also a binary tree in which all left child pointers that are NULL (in Linked list representation) points to its in-order predecessor, and all right child pointers that are NULL (in Linked list representation) points to its in-order successor. Inorder Traversal of the Binary tree is : H - D - I - B - E - A - F - J - C - G 13. What are threaded binary trees? Give its advantages. (OR) What are the advantages of threaded binary trees over ordinary binary tree? (R 2008 NOV/DEC - 2010). (R 2008/2010 APR/ MAY – 2015) (R 2008/2010 MAY/JUN - 2013) , (R 2008 NOV/DEC- 2014) 15
  • 16. Threaded Binary Tree is also a binary tree in which all left child pointers that are NULL (in Linked list representation) points to its in-order predecessor, and all right child pointers that are NULL (in Linked list representation) points to its in-order successor. Advantages: i. The non recursive traversal made in the threaded binary tree makes it faster than the recursive traversal on an equivalent Binary tree. ii. We can efficiently determine the predecessor and successor nodes starting from any node without the use of an external stack. iii. Any node can be accessible from any other node. Threads are usually more to upward whereas links are downward. Thus in a threaded tree, one can move in either directions. 14. Define a heap. How can it be used to represent a priority queue? (OR) What is a heap? (OR) What is heap order property? (OR) What are min-heap and max heap? (R 2008 NOV/DEC – 2010) (R 2008/2010 MAY/JUN – 2014) (R 2008 APR/MAY- 2013) Heap is a special case of balanced binary tree data structure where the root-node key is compared with its children and arranged accordingly. If α has child node β then : key(α) ≥ key(β). If the value of parent is greater than that of child, this property generates Max Heap and if it is less than that of its child, it is called as Min Heap. For Input → 35 33 42 10 14 19 27 44 26 31 Max Heap Min Heap 16
  • 17. 15. Give any two applications of binary heaps. (R 2008 NOV/DEC – 2010) Binary heaps can be used in: 1. Finding the maximum (or minimum) value in a set of values. 2. Finding the kth smallest (or largest) element in an given set of values 3. Dijkstra's algorithm (shortest path) 4. Prim's algorithm (minimum spanning tree) 5. Huffman encoding (data compression) 16. What is B- tree. Give example. (R 2008/2010 MAY/JUN - 2013) , (R 2008/2010 MAY/JUN – 2014) A B-tree is a self-balancing tree data structure that maintains sorted data and allows searches, sequential access, insertions, and deletions in logarithmic time. The B-tree is a generalization of a binary search tree in that a node can have more than two children. Unlike self-balancing binary search trees, the B-tree is well suited for storage systems that read and write relatively large blocks of data, such as discs. It is commonly used in databases and file systems. 17. List out the structural properties of B-Trees. (R 2008 APR/MAY – 2010) B-Tree of Order m has the following properties: • Property 1 - All the leaf nodes must be at same level. • Property 2 - All nodes except root must have at least [m/2]-1 keys and maximum of m-1 keys. • Property 3 - All non leaf nodes except root (i.e. all internal nodes) must have at least m/2 children. • Property 4 - If the root node is a non leaf node, then it must have at least 2 children. • Property 5 - A non leaf node with n-1 keys must have n number of children. • Property 6 - All the key values within a node must be in Ascending Order. • Property 7 - B-Tree grows and shrinks from the root which is unlike Binary Search Tree. Binary Search Trees grow downward and also shrink from downward. • Property 8 - Like other balanced Binary Search Trees, time complexity to search, insert and delete is O(Logn). 17
  • 18. 18. What are the various operations that can be performed on a B tree. (OR) List out the various operations that can be performed on B trees. (R 2013, NOV/ DEC 2015) (R 2013, MAY/JUN 2016) A B-tree is a self-balancing tree data structure that maintains sorted data and allows the following operations in logarithmic time: i. Searches ii. Sequential access iii. Insertions iv. Deletions Unit IV NON LINEAR DATA STRUCTURES – GRAPH 1. With a simple example, demonstrate the ways of representing a Graph. What are the different ways of representing a graph? Explain each of them. (R 2013, APR/ MAY 2015) (R 2008 APR/MAY- 2012) Graph is a data structure that consists of following two components: 1. A finite set of vertices also called as nodes. 2. A finite set of ordered pair of the form (u, v) called as edge. Graph data structure is represented using following representations: 1. Adjacency Matrix 2. Adjacency List 1. Graph (b) Adjacency List (c) Adjacency Matrix 2. Define in degree of graph. (R 2008/2010 APR/ MAY – 2015) Degree of a Graph : Total number of edges connected to a vertex is said to be degree of that vertex. 18
  • 19. In degree : Total number of incoming edges connected to a vertex is said to be indegree of that vertex. Out degree : Total number of outgoing edges connected to a vertex is said to be outdegree of that vertex. 3. What is an undirected graph? (R 2008/2010 APR/ MAY – 2015) In an unweighted graph, the edge (u,v) is an aordered pair and it is the same as (v,u). traversal can be done in both the directions. It is a bidirectional graph. 4. What is breadth-first traversal? (R 2008 NOV/DEC - 2010) Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root or some arbitrary node in a graph and explores all of the neighbor nodes at the present depth prior to moving on to the nodes at the next depth level. . BFS traversal produces a spanning tree (without loops) of the graph as a final result. BFS Traversal Result: 1,2,3,4,5 5. Write procedure for Depth First Search Algorithm. (R 2013, APR/ MAY 2017) The purpose of the algorithm is to mark each vertex as visited while avoiding cycles. A standard DFS implementation puts each vertex of the graph into one of two categories: 1. Visited 2. Not Visited The DFS algorithm works as follows: 19
  • 20. 1. Start by putting any one of the graph's vertices on top of a stack. 2. Take the top item of the stack and add it to the visited list. 3. Create a list of that vertex's adjacent nodes. Add the ones which aren't in the visited list to the top of stack. 4. Keep repeating steps 2 and 3 until the stack is empty. Note: Definition of DFS Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node or an arbitrary node and explores as far as possible along each branch before backtracking. DFS Traversal: 1,2,4,5,3 6. Define spanning tree of a graph.(OR) What is a spanning tree? (R 2008 NOV/DEC - 2010), (R 2008/2010 NOV/DEC - 2013) A spanning tree is a subset of Graph G, which has all the vertices covered with minimum possible number of edges. Hence, a spanning tree does not have cycles and it cannot be disconnected 7. Define minimum spanning tree for a graph. (R 2013, NOV/ DEC 2016) A spanning tree is a subset of Graph G, which has all the vertices covered with minimum possible number of edges. Hence, a spanning tree does not have cycles and it cannot be disconnected In a weighted graph, a minimum spanning tree is a spanning tree that has minimum weight than all other spanning trees of the same graph 20
  • 21. 8. Give the adjacency list and matrix representation for the following graph. (R 2012 APR/MAY- 2013) (R 2008/2010 MAY/JUN - 2014) (a) Given Graph (b) Adjacency List (c) Adjacency Matrix 9. Write at least two applications of graphs. (R 2008 NOV/DEC- 2014) Graphs are used in various fields to represent a scenario and to find a solution to it. Few of them are: Social network graphs, Transportation networks, Utility graphs like power Grid and Internet, Protein-protein interactions graphs, Network packet traffic graphs, Neural networks, etc. 10. What is biconnected graph? Give example. (OR) What is biconnectivity? Give example. (R 2008 APR/MAY – 2010) (R 2008/2010 MAY/JUN - 2014) A biconnected graph is a connected and "non-separable" graph, meaning that if any one vertex were to be removed, the graph will remain connected. This property possessed by a graph is called Biconnectivity. . 11. What are articulation points? (R 2008/2010 MAY/JUN - 2013) 21
  • 22. A vertex in an undirected connected graph is an articulation point (or cut vertex) if and only if, removing it disconnects the graph. Articulation points represent vulnerabilities in a connected network i.e., single points whose failure which would split the network into 2 or more disconnected components. They are useful for designing reliable networks. 12. What are Euler Circuits? (R 2008/2010 NOV/DEC - 2013) Eulerian Path is a path in graph that visits every edge exactly once. Eulerian Circuit is an Eulerian Path which starts and ends on the same vertex. 13. What is topological sort? Give algorithm. (OR) What is topological sorting? (OR) ) State the principle of topological Sorting. (R 2008 APR/MAY - 2010), (R 2008 NOV/DEC- 2014) (R 2013, NOV/ DEC 2015 (R 2013, APR/ MAY 2017) Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering. Topological Sorting for a graph is not possible if the graph is not a DAG. One of the Topological sorts of this graph is: 1,2,3,4,5. 14. What is greedy algorithm? Mention any one problem that use this algorithm design technique. (R 2008 APR/MAY- 2012) 22
  • 23. A greedy algorithm is an algorithmic paradigm that solves a problem in stages by making the locally optimal choice at each stage in order to find a global optimum. In many problems, a greedy strategy does not usually produce an optimal solution, but may yield locally optimal solutions that approximate a globally optimal solution in a reasonable amount of time. Dijkstra’s algorithm to find the shortest path in a graph is a greedy algorithm. 15. What is the minimum number of spanning trees possible for a complete binary graph tree with n vertices? (R 2013, NOV/ DEC 2015) Type of Graph Total Number Spanning Trees G itself is a tree 1 G is a cyclic graph with n vertices. n G is a complete graph with n vertices nn − 2 G is a complete bipartite graph with p vertices and q edges p(q-1) q(p-1) Unit V SEARCHING, SORTING AND HASHING TECHNIQUES 1. What is the difference between linear search and binary search? Compare linear and binary search algorithm techniques. What is the difference between linear search and binary search? What is the time complexity of binary search? (R 2013 NOV/DEC-2016) (R 2013 May/JUN 2014) (R 2012 NOV/DEC-2013) (R2013 NOV/DEC 2016) Linear Search Binary Search Input can be random Input must be sorted Elements are accessed sequentially (Iterative algorithm) Sequential access is not done (Divide and Conquer Algorithm) Performs equality comparison Performs Ordering Comparison Can be implemented on Arrays or Linked Lists Can be implemented only on an Array and not on a linked list. Time Complexity is O(n) Time Complexity is O(log n) 23
  • 24. 2. Should arrays or linked lists be used for the following types of applications? Justify your answer. (R 2013 May/JUN 2014) (a) Many search operations in sorted list (b) Many search operations in unsorted list a. Binary search yields faster results on sorted list. Since binary search performs random access, it can be done only on an array. Linked list cannot be used for Binary search operation. b. If the list of elements is unsorted, then the only possible searching will be to scan the elements in a sequential fashion. This is done using the Linear search algorithm and it can be done on an Array or a Linked List. 3. List sorting algorithm which uses logarithmic time complexity. What is the time complexity of the insertion sort? (R 2013 May/JUN 2014) (R 2013 May/ Jun 2016) Algorithm Time Complexity (Worst Case) Selection Sort O(n2 ) Bubble Sort O(n2 ) Insertion Sort O(n2 ) Heap Sort O(n log(n)) Quick Sort O(n2 ) Merge Sort O(n log(n)) Shell Sort O(n log (n)) Radix Sort O(nk) Linear Search O(n) Binary Search O(log n) 24
  • 25. 4. Differentiate internal and external sorting. Differentiate between the internal and external sorting techniques. (R 2013 NOV/DEC 2014) (R 2012 NOV/DEC-2013) Internal Sorting External Sorting All the data to sort is stored in memory at all times while sorting is in progress Data is stored outside memory (like on disk) and only loaded into memory in small chunks. Arrays can be used to hold the elements for sorting. Linked representation should be used for external sorting. Eg. Shell Sort Eg. Merge Sort 5. Sort the following numbers using bubble sort 10, 5, 7, 11, 4, 1 (R 2013 Dec 15/ Jan 2016) Pass I 10 5 5 5 5 5 5 10 7 7 7 7 7 7 10 10 10 10 11 11 11 11 4 4 4 4 4 4 11 1 1 1 1 1 1 11 Pass II 5 5 5 7 7 7 10 4 4 4 10 1 1 1 10 11 11 11 25
  • 26. Pass III 5 5 5 7 4 4 4 7 1 1 1 7 10 10 10 11 11 11 Pass IV 5 4 4 4 5 1 1 1 5 7 7 7 10 10 10 11 11 11 Pass V 4 1 1 4 5 5 7 7 10 10 11 11 Sorted List 1 4 5 7 10 11 6. Show the result of sorting the following numbers using insertion sort (step by step o/p): 4 7 3 2 5 1 6 . Sort the following numbers using insertion sort. 3, 1, 4, 1, 5, 9, 2, 6, 5. Sort the following numbers using insertion sort: 9 5 2 3 26 1 4 53 46 8 17. (R 2008 APR/MAY- 2013) (R 2012 APR/MAY- 2013) (R 2013 APR/MAY 2017). Stages of Insertion Sort: (4 7 3 2 5 1 6) 4 4 3 2 2 1 1 7 7 4 3 3 2 2 3 3 7 4 4 3 3 2 2 2 7 5 4 4 5 5 5 5 7 5 5 1 1 1 1 1 7 6 26
  • 27. 6 6 6 6 6 6 7 7. Name the sorting techniques which use the divide and conquer stratergy. Name the sorting techniques which use the divide and conquer strategy. (R2013 NOV/DEC 2016) (R 2013 NOV/DEC-2016) Merge sort and Quick sort are some of the divide and conquer techniques. The worst case time complexities are: Merge sort - O(n log n), Quick sort – O(n2 ) 8. What is hashing? Define Hash function. Define hashing. What is hashing? (R 2013 May/ Jun 2016) (R 2008 NOV/DEC - 2010) (R 2008 NOV/DEC- 2014) (R 2013 Dec 15/ Jan 2016) Hashing is a process of indexing and retrieving elements (data) in a data structure called the hash table to provide faster way of finding the element using the hash key. Hash table is just an array which maps a key (data) into the data structure with the help of hash function such that insertion, deletion and search operations can be performed with constant time complexity (i.e. O(1). Hash function is a function which takes a piece of data (i.e. key) as input and outputs an integer (i.e. hash value) which maps the data to a particular index in the hash table. 9. What is primary clustering? (R 2008/2010 MAY/JUN - 2013) Primary Clustering is the tendency for a collision resolution scheme such as linear probing to create long runs of filled slots near the hash position of keys. In Linear probing method of open address hashing, the item which are hashed to the same location are placed in the next available position. This will create blocks of data whenever there is collision. If the primary hash index is x, subsequent probes to search or to place an element in the table goes thorough indexes x+1, x+2, x+3and so on, this is called Primary Clustering. For example, insert the nodes 89, 18, 49, 58, and 69 into a hash table that holds 10 items using the division method 27
  • 28. Numbers 49 and 69 are held inside the primary cluster. 10. What is rehashing? (OR) Define rehashing. How are collisions handled while hashing? (R 2008 MAY/JUN- 2012) (R 2008/2010 MAY/JUN - 2013), (R 2008 APR/MAY- 2013), (R 2008/2010 NOV/DEC - 2013), (R 2008/2010 MAY/JUN - 2014) Rehashing is done in Open addressing modes of hashing. Hash tables offer exceptional performance when not overly full. Load factor is maintained λ < 0.5 for better performance. When the load factor goes above 0.5 (i.e., Table is more than half filled), we go for rehashing. Here, the table size is doubled and the new Hash function = Key % (new table size) is used and the values from the previous hash table are mapped to this new table using the new hash function. Rehashing reduces the load factor well below 0.5. Now the table is ready for further entries. 11. Give the significance of extendible hashing. (R 2013 APR/MAY 2017) Extendible hashing is a type of hash system which treats a hash as a bit string, and uses a trie for bucket lookup. Because of the hierarchical nature of the system, re-hashing is an incremental operation (done one bucket at a time, as needed). This means that time-sensitive applications are less affected by table growth than by standard full-table rehashes. It is a dynamic hashing approach. 12. Mention the difference between Hashing & Extendible Hashing with example.. Write how extensible hashing is better than rehashing. Define extendible hashing. (R 2013 NOV/DEC 2014) (R 2008 APR/MAY - 2010) (R 2008 APR/MAY- 2012) Unlike the rehashing operation in open addressing scheme, the rehashing in extendible hashing is only an incremental process of increasing one bucket at a time and hence the approach is dynamic. This also helps in maintaining the performance even after a number of additions and deletions. 28