22TP201 1
22TP201 1
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 in the string stored in an array:
EAS*Y*QUE***ST***IO*N***.
(a) Construct a stack by performing the following operations for the string given
above and show the sequence of characters returned by the pop operations after reading
the complete string stored in the array.
(i) Perform the push operations when you come across any letter (for example
‘E’, ‘A’,…,etc.)
(ii) Perform the pop operation when you come across the character
asterisks (‘*’).
(b) Construct a queue by performing the following operations for the string given
and show the sequence of characters returned by the dequeue operations after reading
above the complete string stored in the array.
(i) Perform the enqueue operations when you come across any letter (for
example ‘E’, ‘A’,…,. )
(ii) Perform the dequeue operation when you come across the character
asterisks (‘*’).
1 of 2
Regulation: R22 Code: 22TP201/1
3. a) For the given set of data, construct a Binary Search tree and Height Balanced Binary
Search Tree.
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. Design an algorithm to print the reverse order of the vertices encountered on a
breadth- first search (BFS) of G starting from vertex A.
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)
SECTION-B
Answer all Two questions 2×20M=40M
5. Design an algorithm and implement the following functions by taking an array as input from
user in ascending order. Input: 1 2 3 4 5 6 7 8 9 10
a) 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 median and perform quick sort.
d) Differentiate between merge sort and quick sort.
6. Construct a Binary Tree by using the array given below. Where index 0 represents the root
node and value -1 indicates null. Design an algorithm to construct the binary tree and
perform the following operations:
a) Print the Post Order traversal of the tree.
b) Print the level order traversal of the tree.
c) Print the right and left view of the tree.
Input:
Total number of keys: 15
1 2 3 4 5 6 7 -1 -1 -1 8 -1 -1 -1 9
2 of 2