Key With Question Paper 2
Key With Question Paper 2
Q.NO-1 QUESTIONS
PART-B
Answer any four questions out of six. Each question carries 5 marks: 4*5=20M
Q.NO QUESTIONS
2. construct a Binary tree using the given Preorder and Postoreder?
Preorder:[50,25,12,37,30,40,75,62,60,70,87]
Postorder :[12,30,40,37,25,60,70,62, 87,75, 50]
3. Explain Graph Traversals with an Example?
The graph is one non-linear data structure. That is consists of some nodes and their
connected edges. The edges may be director or undirected. This graph can be represented
as G(V, E). The following graph can be represented as G({A, B, C, D, E}, {(A, B), (B,
D), (D, E), (B, C), (C, A)})
The graph has two types of traversal algorithms. These are called the Breadth First
Search and Depth First Search.
The Breadth First Search (BFS) traversal is an algorithm, which is used to visit all of
the nodes of a given graph. In this traversal algorithm one node is selected and then all of
the adjacent nodes are visited one by one. After completing all of the adjacent vertices, it
moves further to check another vertices and checks its adjacent vertices again.
Algorithm
bfs(vertices, start)
Input: The list of vertices, and the start vertex.
Output: Traverse all of the nodes, if the graph is connected.
Begin
define an empty queue que
at first mark all nodes status as unvisited
add the start vertex into the que
while que is not empty, do
delete item from que and set to u
display the vertex u
for all vertices 1 adjacent with u, do
if vertices[i] is unvisited, then
mark vertices[i] as temporarily visited
add v into the queue
mark
done
mark u as completely visited
done
End
The Depth First Search (DFS) is a graph traversal algorithm. In this algorithm one
starting vertex is given, and when an adjacent vertex is found, it moves to that adjacent
vertex first and try to traverse in the same manner.
Algorithm
dfs(vertices, start)
Input: The list of all vertices, and the start node.
Output: Traverse all nodes in the graph.
Begin
initially make the state to unvisited for all nodes
push start into the stack
while stack is not empty, do
pop element from stack and set to u
display the node u
if u is not visited, then
mark u as visited
for all nodes i connected to u, do
if ith vertex is unvisited, then
push ith vertex into the stack
mark ith vertex as visited
done
done
End
4.
Define AVL tree ? Insert the following list of elements
21,26,30,9,4,14,28,18,15,10,2,3,7.
An AVL tree defined as a self-balancing Binary Search Tree (BST) where the
difference between heights of left and right subtrees for any node cannot be more than
one.
The difference between the heights of the left subtree and the right subtree for any
node is known as the balance factor of the node.
The AVL tree is named after its inventors, Georgy Adelson-Velsky and Evgenii
Landis, who published it in their 1962 paper “An algorithm for the organization of
information”.
5.
Write an algorithm and function for Binary search tree
Deletion?
Deletion
Delete function is used to delete the specified node from a binary search tree. However,
we must delete a node from a binary search tree in such a way, that the property of
binary search tree doesn't violate. There are three situations of deleting a node from
binary search tree.
The node to be deleted is a leaf node
It is the simplest case, in this case, replace the leaf node with the NULL and simple free
the allocated space.
In the following image, we are deleting the node 85, since the node is a leaf node,
therefore the node will be replaced with NULL and allocated space will be freed.
In this case, replace the node with its child and delete the child node, which now
contains the value which is to be deleted. Simply replace it with the NULL and free the
allocated space.
6.
Explain about a)Rehashing B) Extendible hashing?
Rehashing is the process of recalculating the hashcode of previously-stored entries (Key-
Value pairs) in order to shift them to a larger size hashmap when the threshold is
reached/crossed, When the number of elements in a hash map reaches the maximum.
Extendible Hashing is a dynamic hashing method wherein directories, and buckets are
used to hash data. It is an aggressively flexible method in which the hash function also
experiences dynamic changes.
Main features of Extendible Hashing : The main features in this hashing technique are:
7. Explain Quick sort and also perform quick sort for 10,9,8,7,6,5,4,3,2,1