Professional Documents
Culture Documents
Cd3291 Dsa UNIT 3 4 5
Cd3291 Dsa UNIT 3 4 5
PART – A
10.
What is the purpose of quick sort and advantage?
The purpose of the quick sort is to move a data item in the correct direction,
just enough for to reach its final place in the array.
Quick sort reduces unnecessary swaps and moves an item to a greater
distance, in one move.
11. Define quick sort?
The quicksort algorithm is fastest when the median of the array is
chosen as the pivot value. That is because the resulting partitions are of
very similar size.
Each partition splits itself in two and thus the base case is reached
very quickly and it follow the divide and conquer strategy.
12. Advantage of quick sort?
Quick sort reduces unnecessary swaps and moves an item to a greater
distance, in one move.
13. Define hashing.
It is the implementation of hash tables. Hashing is a technique used for
performing insertions, deletions and finds in constant average time. Hashing
is used to index and retrieve items in a database because it is faster to find
the item using the short hashed key than to find it using the original value.
14. Define hash table.
Hash table data structure is merely an array of some fixed size, containing
keys. Each key is mapped into some number in the range 0 to Tablesize-1
15. What is hash function? Give an example
Each key is mapped into some number in the range 0 to Tablesize-1. The
mapping is called a hash function. If the input keys are integers, then the
hash function is KEY MOD TABLESIZE
Example: Tablesize: 10 Keys: 15,12,4
Hash function (15) =15 mod 10=5
Hash function (12) =12 mod 10=2
Hash function (4) =4 mod 10=4
PART - B
edge from r.
3. Define leaf?
In a directed tree any node which has out degree o is called a terminal node or a
leaf.
4. What is meant by directed tree?
Directed tree is an acyclic diagraph which has one node called its root with in
degree o while all other nodes have in degree I.
5. What is an ordered tree?
In a directed tree if the ordering of the nodes at each level is prescribed then
such a tree is called ordered tree.
6. What are the applications of binary tree?
The depth of the tree is the depth of the deepest leaf. The height of the
tree is equal to the height of the root. Always depth of the tree is equal to height
of the tree
14. Define terminal nodes in a tree
A node that has no children is called a terminal node. It is also referred to as leaf
node.
15. Define non-terminal nodes in a tree
All intermediate nodes that traverse the given tree from its root node to the
terminal nodes are referred as non-terminal nodes.
16. Define a full binary tree
A full binary tree is a tree in which all the leaves are on the same level and every
non-leaf node has exactly two children.
17. Define a complete binary tree
A complete binary tree is a tree in which every non-leaf node has exactly two
children not necessarily to be on the same level.
18. Write the routine for node declaration in trees.
A binary tree is a tree in which no node can have more than two children.
22. Perform pre, in and post order traversal for the given tree.
ABDHECFG
DHBEAFCG
HDEBFGCA
23. Define the following.
i) Leaf
Nodes at the bottommost level of the tree are called leaf nodes
ii) Sibling
The nodes with common parent are called Sibling
24. Show that maximum and minimum number of nodes in a binary tree of
height H is 2H-1.
A binary tree is threaded by making all right child pointers that would normally be
null point to the inorder successor of the node, and all left child pointers that
would normally be null point to the inorder predecessor of the node.
26. Define binary search tree ADT with an example.
A binary search tree is a tree in which for every node X, the values of all the keys
in its left sub tree are smaller than the key value in X and the values of all the
keys in its right sub tree are larger than the key value in X.
27. List the uses of binary tree.
Searching.
Compiler design.
28. List the Operations of binary search tree?
Make Empty
Find
Insert
Delete
Search
Display
29. How deletion is performed in a binary search tree.
Deletions in a binary search tree leads to trees which are not equally
likely.
Absence of balanced search tree.
The average depth is not O (log N) in trees which are not equally likely.
31. Define AVL Tree.
An AVL Tree is a binary search tree with a balance condition, for any node in the
tree, the height of the left and right subtrees can differ by at most 1.
32. Define Balance factor.
The balance factor of a node in binary tree is defined to be h R- hL where hL and
hR are heights of left and right subtrees of T. For any node in AVL tree the
balance factor should be 1, 0 or -1.
33. How will you compute the balance factor? Give an example
To determine whether the tree is balanced, the balance factor should be
calculated. BF=HL-HR
HL->height of the left subtree ,HR-> height of the right subtree
34. What do you mean by balanced trees?
Balanced trees have the structure of binary trees and obey binary search tree
properties. Apart from these properties, they have some special constraints,
which differ from one data structure to another. However, these constraints are
aimed only at reducing the height of the tree, because this factor determines the
time complexity.
Eg: AVL trees, Splay trees.
35. When AVL tree property is violated and how to solve it?
After insertion of any node in an AVL tree if the balance factor of any node
becomes other than -1,0, or 1 then it is said that AVL property is violated. So the
node on the path from the inserted node to the root needs to be readjusted.
Check the balance factor for each node in the path from inserted node to the root
node and adjust the affected subtree such that the entire subtree should satisfy
the AVL property.
36. Mention the four cases to rebalance the AVL tree.
A splay tree is a self-balancing binary search tree with the additional property
that recently accessed elements are quick to access again. So , the recently
accessed elements are splayed to the root.
39. List the Operations of Splay tree.
• Splaying
• Insertion
• Deleting
40. List the Operations on B-Trees.
• Search
• Create
• Insert
41. Define B-Tree.
A search tree that is not a binary tree is called B-Tree. That satisfies the
follpwing structural properties
• Root is either a leaf or has between 2 and M children
• All non leaf nodes except the root have between [M/2] and M children.
• All leafs are at the same depth.
42. What do you mean by 2-3 tree?
A B-tree of order 3 is called 2-3 tree. A B-tree of order 3 is a tree that is not
binary with the following structural properties:
A binary heap is a heap data structure created using a binary tree. It can be
seen as a binary tree with two additional constraints:
• The Structural property: the tree is an almost complete binary tree; that is, all
levels of the tree, except possibly the last one (deepest) are fully filled, and, if the
last level of the tree is not complete, the nodes of that level are filled from left to
right.
• The heap property: each parent node is less than or equal to each of its
children if the heap is Max heap, each parent node is greater than or equal to
each of its children if the heap is Max heap.
45. Define binary heap and list its properties
The efficient way of implementing priority queue is binary heap and it should be
a complete binary tree.
Properties: 1. Structural Property 2. Heap order property
46. Write about the types of binary heap
Min Heap: The root/parents value should be minimum when compared to all of
its children.
Max Heap: The root/parents value should be maximum when compared to all of
its children
47. What is the need for Priority queue?
PART - B
15 50
33
44
1) Node 33 is deleted. 2) Node 75 is deleted. 3) Node 25 is deleted.
17. Write a program in C to create an empty binary search tree & search for an
element X in it.
18. How to insert an element into a binary search tree and write down the code for
the insertion routine with examples. Construct the binary search tree for the
following data 1,8,11,32,23,4,3,5,9,11,12,41,63,44,17
19. What is BST? Explain with suitable algorithms for insertion and deletion of nodes
at different instances. Illustrate it with example.
20. (i) Explain the process of finding minimum and maximum element in the
BST.
(ii) Explain the operation of threaded binary tree.
21. Construct an expression tree for the expression (a + b * c) + ((d * e + 1) *
g). Give the outputs when you apply preorder, inorder and postorder traversals.
22. Draw a binary search tree for the following input list {60, 25, 75, 15, 50, 66, 33,
and 44}. Trace the algorithm to delete the nodes {25, 75, 44} from the tree.
23. Write down the algorithm binary search for searching x from an array a[1,n] and
give the stepwise execution for an array (10,12,20,23,27,30,31,39,42,
44,45,49,57,63,70) to search x=44.
24. Construct a binary search tree for the following set of numbers and find the
preorder,inorder and postorder traversal of the tree {1,8,11,32,23,4,3,5,9,11,12,
41,63,44,17}
25. Define AVL tree. Explain the AVL tree rotations.
26. Show the result of inserting 2, 1,4,5,9,3,6,7 into an initially empty AVL tree.
27. Write a routine to perform insertion and deletion in a B-tree.
28. Insert the following keys to a 5-way B-tree: 3, 7, 9, 23, 45, 1, 5, 14, 25, 24, 13,
11, 8, 19, 4, 31, 35, 56.
29. Given 5-way B-tree created by these data
• 3, 7, 9, 23, 45, 1, 5, 14, 25, 24, 13, 11, 8, 19, 4, 31, 35, 56
• Add these further keys: 2, 6,12
• Delete these keys: 4, 5, 7, 3, 14
30. Explain the Basic operations performed in a Binary heap with examples.
31. Construct a Min and MAX heap for the following values. 23,67,1,45,7,89,56,35
32. Explain the routine to perform insert and delete min operation in Binary Heap.
33. Describe the operation increase key, decrease key, delete and build heap.
34. Show the result of inserting 10, 12, 1, 14, 6, 5, 8, 15, 3, 9, 7, 4, 11, 13 and Show
the result of performing three DeleteMin operations in the heap.
35. Add the following list of numbers to an initially empty binary heap: 12, 5, 15,
9,13, 7, 15, 10, 3, 20, 4.
UNIT-V
PART-A
1. Define graph.
A graph G= (V, E) consists of a set of vertices, V, and a set of edges, E. Each
edges is a pair (v, w), where v, w V.
2 3
4
Adjacency Matrix and Adjacency List Representation
16. What are the two traversal strategies used in traversing a graph?
Breadth first search and Depth first search
17. What is a minimum spanning tree?
A minimum spanning tree of an undirected graph G is a tree formed from graph
edges that connects all the vertices of G at the lowest total cost.
18. Name two algorithms two find minimum spanning tree
Kruskal’s algorithm and Prim’s algorithm
19. What do you mean by breadth first search (BFS)?
BFS performs simultaneous explorations starting from a common point and
spreading out independently.
20. Differentiate BFS and DFS.
PART-B
1. What is Topological sort? Write down the pseudo code to perform topological
sort and apply the same to the following graph.
2. Explain Dijistra’s algorithm and find the shortest path from a to all other
vertices in a graph.
3. Explain Prim’s and Kruskal’s algorithm. Find the minimum spanning tree for
the following graph.