Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

PART A

1. Like Binary Search, Jump Search is a searching algorithm for sorted arrays. The basic
idea is to check fewer elements (than linear search) by jumping ahead by fixed steps or
skipping some elements in place of searching all elements.
For example, suppose we have an array arr[] of size n and a block (to be jumped) of size m.
Then we search in the indexes arr[0], arr[m], arr[2m]…..arr[km] and so on. Once we find
the interval (arr[km] < x <arr[(k+1)m]), we perform a linear search operation from the
index km to find the element x.
Design and implement the jump search algorithm.
INPUT : 2, 5, 7, 8, 10, 12
Key = 10
2. Given the following sequence of letters and asterisks: EAS*Y*QUE***ST***IO*N***
(a) Consider the stack data structure, supporting two operations push and pop, Suppose that
for the above sequence, each letter (such as E) corresponds to a push of that letter onto the
stack and each asterisk (*) corresponds a pop operation on the stack. Show the sequence of
values returned by the pop operations.
(b) Consider the queue data structure, supporting two operations Enqueue and Dequeue.
Suppose that for the above sequence, each letter (such as E) corresponds to an Enqueue that
letter into the queue and each asterisk (*) corresponds a Dequeue operation on the queue.
Show the sequence of values returned by the Dequeue operations.
3. a. For the given set of data construct a Binary Search tree and Height Balanced Binary
Search Tree.
b. Design an algorithm to calculate the number of search required to construct the BST.
c. Design an algorithm to calculate the number of rotation required to construct the height
balanced BST.
J, R, D, G, T, E, M, H, P, A, F, Q
4. Consider the graph G on six vertices {A, B, C, D, E, F} given by the following adjacency
list:
A : B( 4), F(2) ( i.e.A is connected to B with weight 4 and F with weight 2)
B : A(l), C(3), D( 4)
C : A(6), B(3), D(7)
D : A(6), E(2)
E : D(5)
F : D(2), E(3)
a) Design an algorithm to print the reverse order of the vertices encountered on a breadth-first
search (BFS) of G starting from vertex A.
b) ) Design an algorithm to print the reverse order of the vertices encountered on a depth-first
search (DFS) of G starting from vertex A.
PART B
1. Design an algorithm and implement the following functions.
a. Take array input from user in ascending order. Taking pivot element as Starting index and
perform quick sort.
b. Taking pivot element as Last index and perform quick sort
c. Taking pivot element as random index and perform quick sort
d. Taking pivot element as median and perform quick sort
e. Differentiate between merge sort and quick sort.
2. a. Problem Statement:
Construct a Binary Tree using the given array. If a node has an index i, its children (if any)
are found at indices 2i+1 and 2i+2, while its parent (if any) is found at index floor((i-1)/2).
Index 0 contains the root node and value -1 indicates null here. Design an algorithm to
construct the binary tree and print the Post Order traversal of the tree. Calculate the time
complexity.
Input Format:
First line contains the number of elements in the given tree.
Second line contains the array of elements of the tree.
Output Format:
Print the post order traversal of the tree.
Sample Input:
15
1 2 3 4 5 6 7 -1 -1 -1 8 -1 -1 -1 9
Sample Output: 4 5 2 8 6 9 7 3 1
Explanation:
Constructed BT will be

/ \ 
2 3 
/ \ / \ 
4 5 6 7 
\ \ 
8 9

b. Problem Statement:
Construct a Binary Tree using the given array. If a node has an index i, its children (if any)
are found at indices 2i+1 and 2i+2, while its parent (if any) is found at index floor((i-1)/2).
Index 0 contains the root node and value -1 indicates null here. Design an algorithm to
construct the binary tree and print the level order traversal of the tree. Calculate the time
complexity.
Input Format:
First line contains the number of elements in the given tree.
Second line contains the array of elements of the tree.
Output Format:
Print the level order traversal of the tree.
Sample Input:
15
1 2 3 4 5 6 7 -1 -1 -1 8 -1 -1 -1 9
Sample Output:
123456789
Explanation: Constructed BT will be

/ \ 
2 3 
/ \ / \ 
4 5 6 7 
\ \ 
8 9

c. Problem Statement:
Construct a Binary Tree using the given array. If a node has an index i, its children (if any)
are found at indices 2i+1 and 2i+2, while its parent (if any) is found at index floor((i-1)/2).
Index 0 contains the root node and value -1 indicates null here. Design an algorithm to
construct the binary tree and print the right and left view of the tree. Calculate the time
complexity.
Input Format: First line contains the number of elements in the given tree. Second line
contains the array of elements of the tree.
Output Format: First line contains the Right view of the tree. Second line contains the Left
view of the tree.
Sample Input:
15
1 2 3 4 5 6 7 -1 -1 -1 8 -1 -1 -1 9
Sample Output:
1379
124
Explanation:
Constructed BT will be

/ \ 
2 3 
/ \ / \ 
4 5 6 7 
\ \ 
8 9

You might also like