Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

DSANotes

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

Data Structures and Algorithms

1. Let A be an array containing integer values. The distance of A is defined as the minimum number of elements
in A that must be replaced with another integer so that the resulting array is sorted in non-decreasing order.
The distance of the array [2,5,3,1,4,2,6] is _____3______.
Given array: [2, 5, 3, 1, 4, 2, 6]

Indices: 0 1 2 3 4 5 6
Values: 2 5 3 1 4 2 6

The array with sorted indices: positions different from given array is 3

Indices: 0 1 2 3 4 5 6
Values: 2 2 3 3 4 4 6

2. What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array
of size n?
A) Θ(sqrt(n))
B) Θ(log(n))
C) Θ(n^2)
D) Θ(n)

3. Let P be an array containing n integers. Let t be the lowest upper bound on the number of comparisons of the
array elements, required to find the minimum and maximum values in an arbitrary array of n elements. Which
one of the following choices is correct?
A) t > 2n−2
B) t > 3⌈n/2⌉ and t ≤ 2n−2
C) t > n and t ≤ 3⌈n/2⌉
D) t > ⌈logn⌉ and t ≤ n
We will use the tournament approach to get the min and max elements. (Array element is analogous to Player)

Considering there are n players in the tournament, the first round will have n/2 matches. A player is considered to be the
winner if he has a higher rank than his opponent. In this stage we did 1 comparison for selecting winner or loser from 1
match, so total n/2 comparison for n/2 matches.

After the first round, we will keep all the losers of first round in one area and all the winners in the second area. Note
how each area will have n/2 players in them.

Now from the losers pool we will find the minimum rank player by doing individual comparison. Since this pool has
only n/2 players we can find the player with lowest rank by doing (n/2)–1 comparisons. This lowest rank player
corresponds to the minimum array in the element.

Similarly we will find the highest rank player from the pool of winners by doing (n/2)–1 comparisons again. The highest
rank player corresponds to the maximum element in the array.

Hence total comparisons needed to find minimum and maximum = t = (n/2) + ((n/2)+1) + ((n/2)-1) = 3n/2 -2

4. If an array A contains the items 10,4,7,23,67,12 and 5 in that order, what will be the resultant array A after
third pass of insertion sort?
A) 67,12,10,5,4,7,23
B) 4,7,10,23,67,12,5
C) 4,5,7,67,10,12,23
D) 10,7,4,67,23,12,5
Pass 1 will be applied on the first 2 elements.  10,4 ∣ ,7,23,67,12,5  Pass 1:4,10 ∣ ,7,23,67,12,5

 Pass 2:4,7,10 ∣ ,23,67,12,5  Pass 3:4,7,10,23 ∣ ,67,12,5


5. An element in an array X is called a leader if it is greater than all elements to the right of it in X. The best
algorithm to find all leaders in an array

A. solves it in linear time using a left to right pass of the array


B. solves it in linear time using a right to left pass of the array
C. solves it using divide and conquer in time Θ(nlogn)
D. solves it in time Θ(n^2)

We can move from right to left, while keeping a note of the maximum element so far (let's call it current_max).

 Starting from the rightmost element, we initialize our current_max with it, since the rightmost element will always be
a leader.
 Moving from right to left, if an element x is greater than our current_max, then x is also a leader. Add this element to
list of leaders (or simply print it). Set current_max to x and carry-on leftward.  O(n) linear Tc.

6. A one-dimensional array A has indices 1....75. Each element is a string and takes up three memory words.
The array is stored at location 1120 decimal. The starting address of A [49] is

A. 1267
B. 1164
C. 1264
D. 1169

Address of array + index *size of element when index starts from 0

In above question index starts from 1

so given Address of array=1120 , index=49 , size of element=3

Address=1120+(49-1)*3 =1120+48*3 =1120+144 =1264

7. Let A(1:8,−5:5,−10:5) be a three dimensional array. How many elements are there in the array A?

A. 1200
B. 1408
C. 33
D. 1050

they have specified the size

So 1:8 mean 8 elements ( both are inclusive )

(-5 : 5 ) mean 11 elements

(-10 : 5 ) mean 16 elements

So no of elements will be ( just like Multidimensional array will be ) 8*11*16=1408

8. In an array of 2N elements that is both 2-ordered and 3-ordered, what is the maximum number of positions
that an element can be from its position if the array were 1-ordered?

A. 1
B. 2
C. n/2
D. 2n−1 An array A [ 1 … n] is said to be k-ordered if
A [i - k] < A [ i ] < A [i + k] for each i such that k < i < n – k.  if the array were 1-ordered
then array will be 1 2 3 4 5 6 7 8

maximum number of positions that an element can be from its position=1


9. Suppose there are 11 items in sorted order in an array. How many searches are required on the average, if
binary search is employed and all searches are successful in finding the item?

A. 3.00
B. 3.46
C. 2.81
D. 3.33

Let us consider an array of 11 element which are sorted.

10 20 30 40 50 60 70 80 90 100 110

Now apply binary search in the given array .For convenience we are using Binary search tree.

For first element (which is root) array will be

(10 20 30 40 50 ) 60 (70 80 90 100 110)

Now binary search continue either in lower or in upper halve for searching .

For lower halve (10 20) 30 (40 50).

For upper halve (70 80) 90 (100 110) and continued in same way.

10. The average number of key comparisons required for a successful search for sequential search on n items is

A. n/2
B. (n−1)/2
C. (n+1)/2
D. None of the above

Expected number of comparisons = 1× Probability of first element being x+2× Probability of second element being x+
…+n× Probability of last element being x
=1/n+2/n+3/n+…+n/n  =(n×(n+1)/2)/n  = (n+1)/2

11. A program P reads in 500 integers in the range [0,100] representing the scores of 500 students. It then prints
the frequency of each score above 50. What would be the best way for P to store the frequencies?

A. An array of 50 numbers

B. An array of 100 numbers

C. An array of 500 numbers

D. A dynamically allocated array of 550 numbers

our area of interest is only the 50 numbers so take An array of 50 numbers where A[0] corresponds
to 51...A[49] corresponds to 100 then after reading an input just increment the counter in correct position
12. An array A consists of n integers in locations A[0],A[1],…A[n−1]. It is required to shift the elements of the
array cyclically to the left by k places, where 1<=k<=(n−1). An incomplete algorithm for doing this in linear
time, without using another array is given bellow. Complete the algorithm by filling in the blanks.

1. min=n; i=0;

2. while(_________) {

3. temp= A[i]; j=i;

4. while(_________) {

5. A[j]= _______;

6. j=(j+k) mod n;

7. if(j<min) then

8. min = j;

9. }

10. A[(n+i-k) mod n]=_______;

11. i=________;

12.

13. }

A) i > min; j! = (n+1) mod n; A[j+k] temp; i+1;

B) i <min; j! = (n+i) mod n; A[j+k] temp; i+1;

C) i >min; j! = (n+i+k) mod n; A[j+k] temp; i+1;

D) i <min; j! = (n+i-k) mod n; A[(j+k)mod n] temp; i+1;

13. Consider the following declaration of a two-dimensional array in C:

char A[100][100];

Assuming that the main memory is byte-addressable and that the array is stored starting from memory
address 0, the address of A[40][50] is:

A. 4040
B. 4050
C. 5040
D. 5050

Now you want to go and meet a friend who lives on 50th building of 40th street means A[40][50]

So, firstly cross 39(0−39) streets each consist of 100 buildings: 40×100=4000

Now cross 49(0−49) buildings in order to reach your destination: 50  4000+ 50 4050 answer

14. Let A be a two-dimensional array declared as follows:


A: array [1 …. 10] [1 ….. 15] of integer;
Assuming that each integer takes one memory location, the array is stored in row-major order and the first
element of the array is stored at location 100, what is the address of the element A[i][j]?

A. 15i+j+84

B. 15j+i+84

C. 10i+j+89

D. 10j+i+89 Address of A[i][j] = base_address of A + [(i-1)*15 + (j-1)]*1  100 + 15i -15 + j – 1


15i + j + 84

The array indices started with 1 and it is in Row major order: Base Address + Size * [ (i-1)*n + (j-1)]
The array indices started with 0 and it is in Row major order : Base Address + Size * [ i*n + j ]

The array indices started with 1 and it is in Column major order: Base Address + Size * [ (j-1)*m + (i-1)]
The array indices started with 0 and it is in Column major order : Base Address + Size * [ j*m + i ]

15. Suppose we want to arrange the n numbers stored in any array such that all negative values occur before all
positive ones. Minimum number of exchanges required in the worst case is

A. n−1
B. n
C. n+1
D. None of the above  answer is n/2 We just require n/2 swaps in the worst case.

The algorithm is as given below:


Find positive number from left side and negative number from right side and do exchange. Since, at least one of
them must be less than or equal to n/2, there cannot be more than n/2 exchanges.

16. An n×n array v is defined as follows:

v[i,j]=i−j for all i ,j , i ≤ n, 1 ≤ j ≤ n

The sum of the elements of the array v is

A. 0
B. n−1
C. n^2 − 3n + 2
D. n^2 (n+1)/2

matrix getting defined is skew symmetric matrix.


Sum of all elements in skew symmetric matrix is 0.

17. Suppose you are given an array A[1....n] and a procedure reverse (s,I,j) which reverses the order of elements
in s between positions i and j (both inclusive). What does the following sequence do, where 1 ⩽ k ⩽ n:

reverse (s, 1, k);


reverse (s, k+1, n);
reverse (s, 1, n);

A. Rotates s left by k positions


B. Leaves s unchanged
C. Reverses all elements of s
D. None of the above

Effect of the above 3 reversals for any K is equivalent to left rotation of the array of size n by k.
Let , S[1…7]=1234567
So, n=7, k=2

reverse (S,1,2) we get [2,1,3,4,5,6,7]

reverse (S,3,7) we get [2,1,7,6,5,4,3]

reverse (S,1,7) we get [3,4,5,6,7,1,2]  rotates S left by k positions

18. Consider the following algorithm for searching for a given number x in an unsorted
array A[1..n] having � distinct values:

1. Choose an i at random from 1..n


2. If A[i]=x, then Stop else Goto 1;

Assuming that x is present in A, what is the expected number of comparisons made by the algorithm before it
terminates?

A. n
B. n−1
C. 2n
D. n/2

19. In a compact single dimensional array representation for lower triangular matrices (i.e all the elements above
the diagonal are zero) of size n×n, non-zero elements, (i.e elements of lower triangle) of each row are stored
one after another, starting from the first row, the index of the (i,j)th element of the lower triangular matrix in
this new representation is:
A) i+j
B) i+j−1
C) (j−1)+i(i−1)/2
D) i+j(j−1)/2
Whole trick to this question is to guess if array start with 1 or zero. As they have not mentioned you have to consider
both the cases and then go by the concept of row major.
First case:

if array start with zero then we have to cross n rows and j number of element in the last column. As each row will be
containing elements in increasing order like 1st row will contain 1 non zero element. 2 will 2 non zero. So total number
of element we have to cross can be represented as the sum of natural numbers.
so if array start with zero you will can get address with i(i+1)/2 + j

similarly if it start with 1 replace i and j with (i-1) and j-1 respectively.

20. In a circular linked list organization, insertion of a record involves modification of


A) One pointer.
B) Two pointers.
C) Multiple pointers.
D) No pointer.

21. Linked lists are not suitable data structures for which one of the following problems?
A) Insertion sort
B) Binary search Because finding mid element itself takes O(n) time.
C) Radix sort
D) Polynomial manipulation
22. For merging two sorted lists of sizes m and n into a sorted list of size m+n, we require comparisons of
A) O(m)
B) O(n)
C) O(m+n)
D) O(logm+logn)
The number of moves are however always m+n so that we can term it as Θ(m+n). But the number of comparisons varies as per
the input. In the best case, the comparisons are min(m,n) and in worst case they are m+n−1.

23. Which of the following statements is true?


A) As the number of entries in a hash table increases, the number of collisions increases.
B) Recursive programs are efficient
C) The worst case complexity for Quicksort is O(n^2)
D) Binary search using a linear linked list is efficient
Binary search using a linked list is not efficient as it will not give O(logn) , because we will not be able to find the mid in
constant time. Finding mid in linked list takes time. Recursive programs are not efficient because they take a lot of space,
Recursive methods will often throw Stack Overflow Exception while processing big sets.

24. The concatenation of two lists is to be performed on O(1) time. Which of the following implementations of a
list should be used?
A) Singly linked list
B) Doubly linked list
C) Circular doubly linked list
D) Array implementation of list

25. In the worst case, the number of comparisons needed to search a single linked list of length n for a given
element is
A) logn
B) n/2
C) logn−1
D) n
Worst case is we do not find the element in list. We might end up searching entire list & comparing with each element

26. Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What is the worst-case
time complexity of the best-known algorithm to delete the node x from the list ?
A) O(n)
B) O((logn)^2)
C) O(logn)
D) O(1)

27. The time required to search an element in a linked list of length n is


A) O(logn)
B) O(n) In the worst case, the element to be searched has to be compared with all elements of linked list.
C) O(1)
D) O(n^2)

28. Which of the following operations is performed more efficiently by doubly linked list than by linear linked
list?

A. Deleting a node whose location is given


B. Searching an unsorted list for a given item
C. Inserting a node after the node with a given location
D. Traversing the list to process each node

29. The minimum number of fields with each node of doubly linked list is
A. 1
B. 2
C. 3 prev data next
D. 4

30. The following steps in a linked list result in which type of operation?

p = getnode() you are allocating a space for a new node that you want to create
info(p) = 10 you are setting the info value to 10
next (p) = list you are updating list Field
list = p

A. Pop operation in stack


B. Removal of a node
C. Inserting a node
D. Modifying an existing node

31. Consider a single linked list where F and L are pointers to the first and last elements respectively of the linked
list. The time for performing which of the given operations depends on the length of the linked list?

A. Delete the first element of the list


B. Interchange the first two elements of the list
C. Delete the last element of the list
D. Add an element at the end of the list

In this we need to get the address of the node just before the last node, because let address of node before the last node
is (1000) then we need to set this address to (1000) −>next=NULL. So calculating this address we need to linear search the
linked list and so it depends on the length of the linked list.

32. An unordered list contains n distinct elements. The number of comparisons to find an element in this list that
is neither maximum nor minimum is

A. Θ(nlogn)
B. Θ(n)
C. Θ(logn)
D. Θ(1) Because all elements are distinct, select any three numbers and output 2nd largest from them.

33. N items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to
be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be
performed.

An algorithm performs the following operations on the list in this order:

Θ(N) delete, O(logN) insert, O(logN) find, and Θ(N) decrease-key.

What is the time complexity of all these operations put together?

A. O((logN)^2)
B. O(N)
C. O(N^2)  correct is O(NlogN)
D. Θ(N^2logn)
Delete - θ(1) time as pointer is directly given
Insert - O(N) time,we may need to insert at the end of the sorted list..
Find - θ(N) time.. list we need to search sequentially..
Decrease key - θ(N) time, pointer is directly given, delete then insert

Now using above..


θ(N) * θ(1) + O(logN) * O(N) + O(logN) * θ(N) + θ(N) * θ(N)
using property of asymptotic notation, and removing lower terms, we get O(N2)..

34. Consider the C code fragment given below.

typedef struct node {


int data;
node* next;
} node;

void join(node* m, node* n) {


node* p = n;
while(p->next != NULL) {
p = p->next;
}
p->next = m;
}

Assuming that m and n point to valid NULL-terminated linked lists, invocation of join will

A. append list m to the end of list n for all inputs.


B. either cause a null pointer dereference or append list m to the end of list n.
C. cause a null pointer dereference for all inputs.
D. append list n to the end of list m for all inputs.

35. Consider a singly linked list of the form where F is a pointer to the first element in the linked list and L is the
pointer to the last element in the list. The time of which of the following operations depends on the length of
the list?

A. Delete the last element of the list


B. Delete the first element of the list
C. Add an element after the last element of the list
D. Interchange the first two elements of the list

36. A doubly linked list is declared as:


struct Node {
int Value;
struct Node *Fwd;
struct Node *Bwd;
};
Where Fwd and Bwd represent forward and backward link to the adjacent elements of the list. Which of the
following segment of code deletes the node pointed to by X from the doubly linked list, if it is assumed
that X points to neither the first nor the last node of the list?

A. X→Bwd→Fwd = X→Fwd; X→Fwd→Bwd = X→Bwd;


B. X→Bwd.Fwd = X→Fwd; X.Fwd→Bwd = X→Bwd;
C. X.Bwd→Fwd = X.Bwd; x→Fwd.Bwd = X.Bwd;
D. X→Bwd→Fwd = X→Bwd; X→Fwd→Bwd = X→Fwd;

37. What is the worst case time complexity of inserting n elements into an empty linked list, if the linked list
needs to be maintained in sorted order?

A. Θ(n)
B. Θ(nlogn)
C. Θ(n)^2
D. Θ(1)

"Inserting n elements into an empty linked list, list needs to be maintained in sorted order".

It is not mentioned if the "n elements" are given initially itself or we must insert one element at a time.

1. For the former case, we can just sort the initial n element array - can be done in O(nlogn) and then we'll insert them one
by one to the linked list where the sorted order is always maintained. This process will take O(n) and so the entire
process can be done in Θ(nlogn) time.
2. For the latter case, where we have to do insertion to the linked list one element at a time, the only way to ensure sorted
order for the linkedlist is to follow insertion sort mechanism. This will take Θ(n^2) time in the worst case.

Since, the question is ambiguous in saying how the elements are presented, both options B and C should be given marks.
Unfortunately official key considered later case only. Option C.

38. Consider the problem of reversing a singly linked list. To take an example, given the linked list below,

the reversed linked list should look like

Which one of the following statements is TRUE about the time complexity of algorithms that solve the above
problem in O(1) space?

A. The best algorithm for the problem takes Θ (n) time in the worst case.
B. The best algorithm for the problem takes Θ (nlogn) time in the worst case.
C. The best algorithm for the problem takes Θ (n^2) time in the worst case.
D. It is not possible to reverse a singly linked list in O(1) space.
Suppose you are given a linkedlist like this –

And you want to convert this to as follows-

Which means, you just want to change pointer of node that is pointed by current.

39. Let SLLdel be a function that deletes a node in a singly-linked list given a pointer to the node and a pointer to
the head of the list. Similarly, let DLLdel be another function that deletes a node in a doubly-linked list given
a pointer to the node and a pointer to the head of the list.
Let n denote the number of nodes in each of the linked lists. Which one of the following choices
is TRUE about the worst-case time complexity of SLLdel and DLLdel?

A. SLLdel is O(1) and DLLdel is O(n)


B. Both SLLdel and DLLdel are O(logn)
C. Both SLLdel and DLLdel are O(1)
D. SLLdel is O(n) and DLLdel is O(1)

40. Consider the operator precedence and associativity rules for the integer arithmetic operators given in the table
below.

Operator Precedence Associativity


+ Highest Left
- High Right
* Medium Right
/ Low Right
The value of the expression 3+1+5∗2/7+2−4−7−6/2 as per the above rules is _____6___.

The given expression is evaluated as follows:

⟹3+1+5∗2/7+2−4−7−6/2 ⟹(3+1)+5∗2/7+2−4−7−6/2

⟹(4+5)∗2/7+2−4−7−6/2 ⟹9∗2/(7+2)−4−7−6/2

⟹9∗2/9−4−7−6/2 ⟹9∗2/9−4−(7−6)/2

⟹9∗2/9−(4−1)/2 ⟹9∗2/(9−3)/2

⟹9∗2/6/2 ⟹(9∗2)/6/2

⟹18/6/2 ⟹18/(6/2) ⟹18/3=6

41. Consider the following sequence of operations on an empty stack.


push(54); push(52); pop(); push(55); push(62); s=pop();
Consider the following sequence of operations on an empty queue.
enqueue(21); enqueue(24); dequeue(); enqueue(28); enqueue(32); q=dequeue();
The value of s+q is ____86_______.
Stack:

 Push 54, push 52, pop (remove top element of stack)


 Now stack 54 (remove 52), push 55, push 62, pop
 Now top element is 62 (remove 62 as S)
 S=62

Queue

 Enqueue 21, Enqueue 24 dequeue (remove first element of queue)


 Now queue 24 (remove 21), Enqueue 28, Enqueue 32, dequeue
 Starting element is 24 (remove 24 as Q)
 Q=24  S+Q=62+24=86

42. A stack is implemented with an array of ′A[0...N−1]′ and a variable ‘pos’. The push and pop operations are
defined by the following code.

1. push (x)

2. A[pos] <- x

3. pos <- pos -1

4. end push

5. pop()

6. pos <- pos+1

7. return A[pos]

8. end pop

Which of the following will initialize an empty stack with capacity N for the above implementation

A. pos←−1
B. pos←0
C. pos←1
D. pos←N−1

Stack is growing downwards, and on pushing an item, the top [pos] is decrementing by one, meaning the on the topmost position
[pos] will be 0, or (N - 1 - (N - 1)], so the initial value of [pos] will be N – 1

43. Convert the pre-fix expression to in-fix −∗+ABC∗–DE+FG

A. (A−B)∗C+(D∗E)−(F+G)
B. (((A+B)∗C)−((D−E)∗(F+G)))
C. (A+B-C)∗(D−E)∗(F+G)
D. (A+B)∗C−(D∗E)−(F+G)

44. Choose the equivalent prefix form of the following expression

(a+(b-c))*((d-e)/(f+g-h))

A. *+a-bc/-de-+fgh
B. *+a-bc-/de-+fgh
C. *+a-bc/-ed-+fgh
D. *+ab-c/-de-+fgh
E. (a+(b−c))∗((d−e)/(f+g−ℎ))  (a+(b−c))∗((−de)/((+fg)−ℎ))  (a+(−bc))∗((−de)/(−+fgℎ))
(+a−bc)∗(/−de−+fgℎ)  ∗+a−bc/−de−+fgℎ
45. The best data structure to check whether an arithmetic expression has balanced parenthesis is a:

A. Queue
B. Stack Balanced Parenthesis is one of the application of Stack.
C. Tree
D. List

46. If the sequence of operations - push (1), push (2), pop, push (1), push (2), pop, pop, pop, push (2), pop are
performed on a stack, the sequence of popped out values

A. 2,2,1,1,2
B. 2,2,1,2,2
C. 2,1,2,2,1
D. 2,1,2,2,2 After pushing some element in stack when we do pop , we get element in LIFO order

47. The result evaluating the postfix expression 10 5+60 6/∗8− is

A. 284
B. 213
C. 142 (10 + 5) * (60 / 6) - 8 = 15 * 10 - 8 = 142
D. 71

48. The five items: A, B, C, D, and E are pushed in a stack, one after other starting from A. The stack is popped four items
and each element is inserted in a queue. The two elements are deleted from the queue and pushed back on the stack.
Now one item is popped from the stack. The popped item is

A. A
B. B
C. C
D. D

Initially A, B, C, D, and E are pushed in a stack, one after other starting from A.

Stack is popped four items.

Four element is inserted in a queue. The two elements are deleted from the queue
Two elements are pushed back on the stack.Now one item is popped from the stack. The popped item is D.

49. Stack A has the entries a, b, c (with a on top). Stack B is empty. An entry popped out of stack A can be printed
immediately or pushed to stack B. An entry popped out of the stack B can be only be printed. In this
arrangement, which of the following permutations of a, b, c are not possible?

A. bac
B. bca
C. cab
D. abc

50. A function f defined on stacks of integers satisfies the following


properties. f(∅)=0 and f(push(S,i))=max(f(S),0)+i for all stacks S and integers i.

If a stack S contains the integers 2,−3,2,−1,2 in order from bottom to top, what is f(S)?

A. 6
B. 4
C. 3
D. 2

51. A single array A[1…MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of
the array. Variables top1 and top2 (top1<top2) point to the location of the topmost element in each of the
stacks. If the space is to be used efficiently, the condition for “stack full” is

A. (top1=MAXSIZE/2) and (top2=MAXSIZE/2+1)

B. top1+top2=MAXSIZE

C. (top1=MAXSIZE/2) or (top2=MAXSIZE)

D. top1=top2−1

Since the stacks are growing from opposite ends, initially top1=1 and top2=MAXSIZE. Now, to make the space usage
most efficient we should allow one stack to use the maximum possible space as long as other stack doesn't need it. So,
either of the stack can grow as long as there is space on the array and hence the condition must be top1=top2−1.

52. To evaluate an expression without any embedded function calls


A. One stack is enough
B. Two stacks are needed
C. As many stacks as the height of the expression tree are needed
D. A Turing machine is needed in the general case

53. Which of the following is essential for converting an infix expression to the postfix form efficiently?

A. An operator stack
B. An operand stack
C. An operand stack and an operator stack
D. A parse tree

When we evaluate a given postfix expression, then we only push the operands into the stack but not any operator. So, the stack used
in postfix evaluation called operand stack.

When we convert an infix notation into postfix notation, then we only push the operators into the stack but not any operand. So,
stack used in the conversion from infix to postfix is called operator stack.

54. Which of the following permutations can be obtained in the output (in the same order) using a stack assuming
that the input is the sequence 1, 2, 3, 4, 5 in that order?

A. 3, 4, 5, 1, 2
B. 3, 4, 5, 2, 1
C. 1, 5, 2, 3, 4
D. 5, 4, 3, 1, 2 1 is the last element of the stack which was popped out in output so check
in given options which option have last pop as 1

55. Which of the following data structure is useful in traversing a given graph by breadth first search?

A. Stack
B. Queue Breadth-first search uses a Queue data structure.
C. List
D. None of the above

56. The queue data structure is to be realized by using stack. The number of stacks needed would be

A. It cannot be implemented
B. 2 stacks A queue can be implemented using two stacks.
C. 4 stacks
D. 1 stack

57. Consider the following statements which are true?

A. First-in-first out types of computations are efficiently supported by STACKS.

B. Implementing LISTS on linked lists is more efficient than implementing LISTS on an array for
almost all the basic LIST operations.

C. Implementing QUEUES on a circular array is more efficient than implementing QUEUES on a


linear array with two indices.

D. Last-in-first-out type of computations are efficiently supported by QUEUES.

58. A circular queue has been implemented using a singly linked list where each node consists of a value and a
single pointer pointing to the next node. We maintain exactly two external pointers FRONT and REAR
pointing to the front node and the rear node of the queue, respectively. Which of the following statements
is/are CORRECT for such a circular queue, so that insertion and deletion operations can be performed
in O(1) time?
I. Next pointer of front node points to the rear node.
II. Next pointer of rear node points to the front node.

A. (I) only.
B. (II) only.
C. Both (I) and (II).
D. Neither (I) nor (II).

59. A priority queue Q is used to implement a stack that stores characters. PUSH (C) is implemented as
INSERT (Q,C,K) where K is an appropriate integer key chosen by the implementation. POP is implemented
as DELETEMIN(Q). For a sequence of operations, the keys chosen are in

A. non-increasing order

B. non-decreasing order

C. strictly increasing order

D. strictly decreasing order

Implementing stack using priority queue require first element inserted in stack will be deleted at last, and to
implement it using deletemin() operation of queue will require first element inserted in queue must have highest
priority.

So the keys must be in strictly decreasing order.

60. Consider a standard Circular Queue implementation (which has the same condition for Queue Full and Queue
Empty) whose size is 11 and the elements of the queue are q[0],q[1],…q[10].

The front and rear pointers are initialized to point at q[2]. In which position will the ninth element be added?

A. q[0]
B. q[1]
C. q[9]
D. q[10]

In Standard Implementation of Circular Queue,

 For enqueue, we increment the REAR pointer and then insert an element
 For dequeue, we increment the FRONT and then remove the element at that position.
 For empty check, when FRONT == REAR, we declare queue as empty

61. A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed
efficiently. Which one of the following statements is CORRECT (n refers to the number of items in the
queue) ?

A. Both operations can be performed in O(1) time.


B. At most one operation can be performed in O(1) time but the worst case time for the operation
will be Ω(n).
C. The worst case time complexity for both operations will be Ω(n).
D. Worst case time complexity for both operations will be Ω(nlogn).
62. A queue is implemented using a non-circular singly linked list. The queue has a head pointer and a tail
pointer, as shown in the figure. Let n denote the number of nodes in the queue. Let 'enqueue' be implemented
by inserting a new node at the head, and 'dequeue' be implemented by deletion of a node from the tail.

Which one of the following is the time complexity of the most time-efficient implementation of 'enqueue' and '
dequeue, respectively, for this data structure?

A. Θ(1),Θ(1)
B. Θ(1),Θ(n)
C. Θ(n),Θ(1)
D. Θ(n),Θ(n)

Time Complexity  O(1) Because only pointer manipulation is involved which takes constant time in insertion

Time Complexity = Time for Traversing list, free the last node and keep track of Tail pointer  O(n)

63. Consider a complete binary tree with 7 nodes. Let A denote the set of first 3 elements obtained by performing
Breadth-First Search (BFS) starting from the root. Let B denote the set of first 3 elements obtained by
performing Depth-First Search (DFS) starting from the root.

The value of ∣A-B∣ is __1_____ A-B= the remaining node from the set of level2 nodes.

64. The postorder traversal of a binary tree is 8, 9, 6, 7, 4, 5, 2, 3, 1. The inorder traversal of the same tree
is 8,6,9,4,7,2,5,1,3. The height of a tree is the length of the longest path from the root to any leaf. The height
of the binary tree above is ___4__

Nodes in longest path from Root to Leaf =(1−2,2−4,4−6,6−8) or (1−2,2−4,4−6,6−9) 4


65.
66.
If the post order traversal gives ab -cd * + then the label of the nodes 1,2,3.. will be
A) + , -, *, a,b,c,d PostOrder Traversal of the given tree gives the output: 4 5 2 6 7 3 1.
B) a, -,b,+,c,*,d
C) a,b,c,d,-,*,+
D) -,a,b,+,*,c,d
66. A complete binary tree with n non-leaf nodes contains

A. logn nodes
B. n+1 nodes
C. 2n nodes
D. 2n+1 nodes

67. Consider a binary tree T that has 200 leaf nodes. Then the number of nodes in T that have exactly two children
are ______. The general formula for a Binary tree having two children with n leaves is=> n-1.
Here n = 200 So answer is 199.

1. A binary tree T has 20 leaves. The number of nodes in T having two children is ___19___. (n-1)
2. How many different trees are there with four nodes A, B, C and D?
A) 30
B) 60
C) 90
D) 120 formula  F(n) = (n+1)!

No of spanning tree of complete graph with n nodes=No of unrooted labeled tree with n nodes=cayley formula=n^n-2

The height of a tree is the length of the longest root-to-leaf path in it. The maximum and minimum number of nodes in a
binary tree of height 5 are
A. 63 and 6, respectively
B. 64 and 5, respectively
C. 32 and 6, respectively
D. 31 and 5, respectively Option A is correct because height 5 means level 6

so maximum node 2level - 1  63for minimum, at each level only single node so total 6

Consider a rooted n node binary tree represented using pointers. The best upper bound on the time required to determine
he number of subtrees having exactly 4 nodes is O(nalogba). Then the value of a+10b is ______1____ We need to
raverse all nodes at least once, and we need only one traversal.  O(n); a=1, b=0

Which of the following number of nodes can form a full binary tree?
A) 8
B) 15  1+2+4+8
C) 14
D) 13

The in-order traversal of a tree resulted in FBGADCE. Then the pre-order traversal of that tree would result in
A. FGBDECA
B. ABFGCDE
C. BFGCDEA
D. AFGBDEC

If we try to generate tree from question, we get following tree.


A
B C
F G D E

n a binary tree with n nodes, every node has an odd number of descendants. Every node is considered to be its own
descendant. What is the number of nodes in the tree that have exactly one child?
A. 0 C. 1
B. (n−1)/2 D. n−1

0 because every node has an odd number of descendants so least odd number 1 and every node is considered to be its own
descendant so all nodes have even number of descendants (0,2,4,6...) so every node has either 0 children or 2 children...

1. A full binary tree with n leaves contains

A. n nodes
B. log2n nodes
C. 2n−1 A Full binary tree with n leaves contains 2−1 nodes.
D. 2n nodes

76. A complete binary tree with the property that the value at each node is at least as large as the values at its
children is known as

A. binary search tree


B. AVL tree
C. completely balanced tree
D. Heap

Heap or (max heap) which is a complete binary tree with every node has value more than or equal to its children

77. The maximum number of binary trees that can be formed with three unlabelled nodes is:

A. 1
B. 5
C. 4
D. 3

No. of unlabelled binary trees for n nodes (2n)! / ( (n+1)! *(n!)) here n=3

78. The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of
nodes in a binary tree of height ℎ is:
A. 2ℎ−1

B. 2ℎ−1−1

C. 2ℎ+1−1 try with hit and trial method

D. 2ℎ+1

79. In a binary tree, the number of internal nodes of degree 1 is 5, and the number of internal nodes of
degree 2 is 10. The number of leaf nodes in the binary tree is

A. 10
B. 11
C. 12
D. 15

We are given no. of 1 degree node =5, no. of 2 degree nodes =10.

Total no. of edges =1∗5+2∗10=25 (In tree degree is for outgoing edges only, and hence each degree corresponds
to an edge)

So, total no. of nodes =25+1=26 (No. of nodes in a tree is 1 more than no. of edges).

Now, no. of leaf nodes (nodes with 0 degree) =26−5−10=11

80. Which one of the following statement is TRUE?

A. Overlaying is used to run a program, which is longer than the address space of the computer.
B. Optimal binary search tree construction can be performed efficiently by using dynamic
programming.
C. Depth first search cannot be used to find connected components of a graph.
D. Given the prefix and postfix walls over a binary tree, the binary tree can be uniquely constructed

81. A binary tree T has n leaf nodes. The number of nodes of degree 2 in T is

A. Log2n
B. n−1
C. n
D. 2n

For the tree, the degree of a node is defined as the number of sub-trees of the node or no of children of a node.

82. Which of the following sequences denotes the post order traversal sequence of the below tree?
A. fegcdba
B. gcbdafe
C. gcdbfea Left → Right → Root.
D. fedgcba

83. Which of the following statements is false?

A. A tree with a n nodes has (n–1) edges


B. A labelled rooted binary tree can be uniquely constructed given its postorder and preorder
traversal results.
C. A complete binary tree with n internal nodes has (n+1) leaves.
D. The maximum number of nodes in a binary tree of height h is 2h+1 -1

84. Let LASTPOST, LASTIN and LASTPRE denote the last vertex visited `in a postorder, inorder and preorder
traversal respectively, of a complete binary tree. Which of the following is always true?

A. LASTIN = LASTPOST
B. LASTIN = LASTPRE
C. LASTPRE = LASTPOST
D. None of the above

Consider a Complete Binary Tree with only 1 node, say A,

Then its PREORDER = POSTORDER = INORDER = A

Therefore, only Option D matches (as Question ask, which always TRUE)

85. Level order traversal of a rooted tree can be done by starting from the root and performing

A. preorder traversal
B. in-order traversal
C. depth first search
D. breadth first search Level order traversal of a tree is breadth first traversal for the tree.

86. Suppose a binary search tree with 1000 distinct elements is also a complete binary tree. The tree is stored using
the array representation of binary heap trees. Assuming that the array indices start with 0, the 3rd largest element of
the tree is stored at index _____509_________

Log21000 +1  9 +1  10 levels  210 – 2  1022  level is not fully completed as 0-999 is made

29= 512 range is 511 to 999 on 10th level level 9 ends on 510  3rd largest node is 510-1 509

87. A binary search tree 𝑇 contains 𝑛 distinct elements. What is the time complexity of picking an element in 𝑇 that
is smaller than the maximum element in 𝑇?

A. Θ(𝑛log𝑛)
B. Θ(𝑛)
C. Θ(log𝑛)
D. Θ(1)

we only need to compare any two elements We don’t need to find the “Second Largest Number”. We need ANY number which is not
the largest. So, take ANY two elements & the smaller in them is your answer.

88. What is the in-order successor of 15 in the given binary search tree?
A. 18
B. 6
C. 17
D. 20

89. The preorder traversal of a binary search tree is 15,10,12,11,20,18,16,19. Which one of the following is the
postorder traversal of the tree?

A. 10,11,12,15,16,18,19,20
B. 11,12,10,16,19,18,20,15 PreOrder  data  left  right
C. 20,19,18,16,15,12,11,10 InOrder  left  data  right
D. 19,16,18,20,11,12,10,15 PostOrder left  right  data

In Pre-order, the first node is ROOT. So root is 15. In Post-order, the last node is ROOT. So in the Post-order
sequence, 15 must be at last. In Pre-order, the second node is the left child of ROOT, if it is less than the root.

90. Let 𝑇 be a binary search tree with 15 nodes. The minimum and maximum possible heights of 𝑇 are:

Note: The height of a tree with a single node is 0.

A. 4 and 15 respectively.
B. 3 and 14 respectively. Minimum log2(n+1) - 1 Maximum  n-1
C. 4 and 14 respectively.
D. 3 and 15 respectively.

91. While inserting the elements 71,65,84,69,67,83 in an empty binary search tree (BST) in the sequence shown,
the element in the lowest level is

A. 65
B. 67
C. 69
D. 83

92. What are the worst-case complexities of insertion and deletion of a key in a binary search tree?

A. Θ(log𝑛) for both insertion and deletion


B. Θ(𝑛) for both insertion and deletion happens when the BST is skewed.
C. Θ(𝑛) for insertion and Θ(log𝑛) for deletion
D. Θ(log𝑛) for insertion and Θ(𝑛) for deletion

93. Which of the following is/are correct in order traversal sequence(s) of binary search tree(s)?

I. 3,5,7,8,15,19,25
II. 5,8,9,12,10,15,25
III. 2,7,10,8,14,16,20
IV. 4,6,7,9,18,20,25 In order traversal of key are always in ascending order.
A. I and IV only
B. II and III only
C. II and IV only
D. II only

94. Consider the following binary search tree T given below: Which node contains the fourth smallest element in T?

A. Q
B. V
C. W In order traversal of key are always in ascending order.  UQXWPVZY
D. X

Time Complexity Analysis of Insertion and deletion :

1. Best 𝐶𝑎𝑠𝑒=𝑂(1) , When it is smallest/greatest element and BST contains only all greater/smaller element than inserting
element respectively.
2. Avg 𝐶𝑎𝑠𝑒=𝑂(log𝑛) , When it belongs between some elements .
3. Worst 𝐶𝑎𝑠𝑒=𝑂(𝑛) , When it is smallest/greatest element and BST contains only all smaller/greater element than inserting
element respectively.

95. How many distinct binary search trees can be created out of 4 distinct keys?

A. 5
B. 14
C. 24
D. 35

No. of BST= 2nCn/(n+1) therefore 8C4/5 =14

96. The following numbers are inserted into an empty binary search tree in the given order: 10,1,3,5,15,12,16. What
is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)?

A. 2
B. 3
C. 4
D. 6

97. Which of the following is TRUE?

A. The cost of searching an AVL tree is Θ(log𝑛) but that of a binary search tree is 𝑂(𝑛)
B. The cost of searching an AVL tree is Θ(log𝑛) but that of a complete binary tree is Θ(𝑛log𝑛)
C. The cost of searching a binary search tree is 𝑂(log𝑛) but that of an AVL tree is Θ(𝑛)
D. The cost of searching an AVL tree is Θ(𝑛log𝑛) but that of a binary search tree is O(n)

AVL tree is a balanced search tree that has time complexity of searching Θ(log𝑛), but in binary search tree, we can have a completely
left/right skewed tree, in which search is 𝑂(𝑛).

98. The numbers 1,2,.…𝑛 are inserted in a binary search tree in some order. In the resulting tree, the right subtree of
the root contains 𝑝 nodes. The first number to be inserted in the tree must be

A. 𝑝
B. 𝑝+1
C. 𝑛−𝑝 from 1,...n elements p elements are on the right. so root or first inserted will be at n-p
D. 𝑛−𝑝+1

99. Let 𝑇(𝑛) be the number of different binary search trees on 𝑛 distinct elements.

Then 𝑇(𝑛)=∑𝑘=1𝑛𝑇(𝑘−1)𝑇(𝑥), where 𝑥 is

A. 𝑛−𝑘+1
B. 𝑛−𝑘
C. 𝑛−𝑘−1
D. 𝑛−𝑘−2 left subtree + root + right subtree = total node  (k-1) + 1 + x = n x = n – k

100. A binary search tree contains the value 1,2,3,4,5,6,7,8. The tree is traversed in pre-order and the values are
printed out. Which of the following sequences is a valid output?

A. 53124786
B. 53126487
C. 53241678
D. 53124768

101. A binary search tree is generated by inserting in order the following integers:

50,15,62,5,20,58,91,3,8,37,60,24

The number of nodes in the left subtree and right subtree of the root respectively is

A. (4,7)
B. (7,4)
C. (8,3)
D. (3,8)

Root will be 50. now insert one by one, greater to 50 in the right sub tree, lesser in left sub tree.

Or you can simply count the number looking at the i/p. less than 50 are 7. more than 50 are 4.

102. The minimum height of an AVL tree with 𝑛 nodes is

A. Ceil (log2(𝑛+1))
B. 1.44 log2𝑛 ======== Max height
C. Floor (log2(𝑛+1)) Min height
D. 1.64 log2𝑛

103. What is the worst case time complexity of inserting 𝑛2 elements into an AVL-tree with 𝑛 elements initially?

A. Θ(𝑛4)
B. Θ(𝑛2)
C. Θ(𝑛2log2𝑛)
D. Θ(𝑛3)

104. Access time of the symbolic table will be logarithmic if it is implemented by

A. Linear list
B. Search tree  O(logn)
C. Hash table
D. Self organization list

105. The number of rotations required to insert a sequence of elements 9,6,5,8,7,10 into an empty 𝐴𝑉𝐿 tree is?
A. 0
B. 1
C. 2
D. 3

106. The worst case running time to search for an element in a balanced binary search tree with 𝑛2𝑛 elements is

A. Θ(𝑛log𝑛)
B. Θ(𝑛2n)
C. Θ(𝑛)
D. Θ(log𝑛)

107. In the balanced binary tree in the below figure, how many nodes will become unbalanced when a node is
inserted as a child of the node “g”?

A. 1
B. 3
C. 7
D. 8

𝑎,𝑏,𝑐 will become unbalanced with Balance factor as +2,+2,+2 respectively. Balance factor should be −1,0,+1.

Balance factor = Height(LST) - Height(RST)

108. Which one of the following sequences when stored in an array at locations 𝐴[1],…,𝐴[10] forms a max-heap?

A. 23,17,10,6,13,14,1,5,7,12
B. 23,17,14,7,13,10,1,5,6,12
C. 23,17,14,6,13,10,1,5,7,15
D. 23,14,17,1,10,13,16,12,7,5
109. Let 𝐻 be a binary min-heap consisting of 𝑛 elements implemented as an array. What is the worst case time
complexity of an optimal algorithm to find the maximum element in 𝐻?

A. Θ(1)
B. Θ(log𝑛)
C. Θ(𝑛)
D. Θ(𝑛log𝑛)

110. Given a binary-max heap. The elements are stored in an arrays as 25,14,16,13,10,8,12. What is the content of the
array after two delete operations?

A. 14,13,8,12,10
B. 14,12,13,10,8
C. 14,13,12,8,10
D. 14,13,12,10,8 max-heap deletion is always done at the root node. first, we delete a root node and call heapify.

111. Consider a complete binary tree where the left and right subtrees of the root are max-heaps. The lower bound for
the number of operations to convert the tree to a heap is

A. Ω(log𝑛) Max heapify Root


B. Ω(𝑛)
C. Ω(𝑛log𝑛)
D. Ω(𝑛2)

112. A priority queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the
heap is: 10,8,5,3,2. Two new elements 1 and 7 are inserted into the heap in that order. The level-order traversal of the
heap after the insertion of the elements is:

A. 10,8,7,3,2,1,5 Insert 1 and 7 in order and heapify


B. 10,8,7,2,3,1,5
C. 10,8,7,1,2,3,5
D. 10,8,7,5,3,2,1

113. A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following
is a max-heap?

A.

B.

C.

D.

In option A (a heap must have all levels till last but one completely filled and in the last level all nodes must be filled from the
left end without a gap till the last node)

114. In a binary max heap containing 𝑛 numbers, the smallest element can be found in time

A. 𝑂(𝑛)
B. 𝑂(log𝑛)
C. 𝑂(loglog𝑛)
D. O(1)

In a max heap, the smallest element is always present at a leaf node. Heap being a complete binary tree, there can be up to 𝑛2 leaf
nodes and to examine all of them we would need 𝑂(𝑛) time.

115. In a min-heap with 𝑛 elements with the smallest element at the root, the 7𝑡ℎ smallest element can be found in
time

A. Θ(𝑛log𝑛)
B. Θ(𝑛)
C. Θ(log𝑛)
D. Θ(1)

Time to find the smallest element on a min-heap- one retrieve operation - Θ(1)
Time to find the second smallest element on a min-heap- requires 22−1=3 check operations to find the second smallest element out
of 3 elements - Θ(1)

Time to find the 7𝑡ℎ smallest element - requires 𝑂(27−1)=𝑂(127) check operations to find the seventh smallest element out
of 127 possible ones - Θ(1)

In short if the number of required operations is independent of the input size 𝑛, then it is always Θ(1).

(Here, we are doing a level order traversal of the heap and checking the elements)

If we are not allowed to traverse the heap and allowed only default heap-operations, we will be restricted with doing Extract-
min 7 times which would be 𝑂(log𝑛).

116. Consider any array representation of an 𝑛 element binary heap where the elements are stored from index 1 to
index 𝑛 of the array. For the element stored at index 𝑖 of the array (𝑖≤𝑛), the index of the parent is

A. 𝑖−1
B. ⌊𝑖/2⌋ floor
C. ⌈𝑖/2⌉ ceil
D. (𝑖+1)/2

for node at index 𝑖


left 𝑐ℎ𝑖𝑙𝑑(𝐿) at 2i
right 𝑐ℎ𝑖𝑙𝑑(𝑅) at 2𝑖+1
for node at index 𝑖
parent will be at floor 𝑖/2

117. Of the following, which best approximates the ratio of the number of nonterminal nodes in the total number of
nodes in a complete 𝐾-ary tree of depth 𝑁 ?

A. 1/𝑁
B. 𝑁−1/𝑁
C. 1/𝐾
D. 𝐾−1/𝐾

118. Consider the following rooted tree with the vertex labeled 𝑃 as the root:
The order in which the nodes are visited during an in-order traversal of the tree is

A. 𝑆𝑄𝑃𝑇𝑅𝑊𝑈𝑉 The inorder traversal order of a ternary tree is left → root → middle → right.
B. 𝑆𝑄𝑃𝑇𝑈𝑊𝑅𝑉
C. 𝑆𝑄𝑃𝑇𝑊𝑈𝑉𝑅
D. 𝑆𝑄𝑃𝑇𝑅𝑈𝑊𝑉

119. The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is:

A. 𝑛/2
B. (𝑛−1)/3
C. (𝑛−1)/2
D. (2𝑛+1)/3

120. A complete 𝑛-ary tree is one in which every node has 0 or 𝑛 sons. If 𝑥 is the number of internal nodes of a
complete 𝑛-ary tree, the number of leaves in it is given by

A. 𝑥(𝑛−1)+1 1 for root and n-1 nodes to be inserted for every new node
B. 𝑥𝑛−1
C. 𝑥𝑛+1
D. 𝑥(𝑛+1)

121. In linear hashing, if blocking factor 𝑏𝑓𝑟, loading factor 𝑖 and file buckets 𝑁 are known, the number of records
will be

A. 𝑐𝑟=𝑖+𝑏𝑓𝑟+𝑁
B. 𝑟=𝑖−𝑏𝑓𝑟−𝑁
C. 𝑟=𝑖+𝑏𝑓𝑟−𝑁
D. 𝑟 = 𝑖∗𝑏𝑓𝑟∗𝑁

122. A Hash Function 𝑓 defined as 𝑓(𝑘𝑒𝑦)=𝑘𝑒𝑦mod7. With linear probing while inserting the
keys 37,38,72,48,98,11,56 into a table indexed from 0, in which location key 11 will be stored (Count table
index 0 as 0𝑡ℎ location)?

A. 3
B. 4 Location Key
C. 5 0 98
D. 6 1 56
2 37
3 38
4 72
123. Given that hash 5 11 table 𝑇 with 25 slots that
stores 2000 elements, the load 6 48 factor 𝑎 for 𝑇 is ___ 80______.

Load factor = n/k  2000/ 25  80 answer


124. A hash table contains 10 buckets and uses linear probing to resolve collisions. The key values are integers and
the hash function used is key%10. If the values 43,165,62,123,142 are inserted in the table, in what location would the
key value 142 be inserted?

A. 2
B. 3
C. 4
D. 6

165 in loc 5
62 in loc 2
123 in loc 4 ( collission and next free space)
142 in loc 6 (collision in 2, and 3,4,5 already occupied)

E. 125. Given the following input (4322,1334,1471,9679,1989,6171,6173,4199) and the hash


function 𝑥 mod 10, which of the following statements are true?
I. 9679,1989,4199 hash to the same value
II. 1471,6171 hash to the same value
III. All elements hash to the same value
IV. Each element hashes to a different value

A. I only
B. II only
C. I and II only the last digit of every digit given is equal in I and II.
D. III or IV

126. An advantage of chained hash table (external hashing) over the open addressing scheme is

A. Worst case complexity of search operations is less

B. Space used is less

C. Deletion is easier

D. None of the above

Chaining having two draw back  1. pointer overhead 2. searching time is high

You might also like