DSA me only
DSA me only
DSA me only
DSA
O(1) < O(log n) < O(n) < O(nlog n) < O(n²) < O(2^n)
if (n=1) return a
var 11 as array = a[0] a[n/2] ...
var 12 as array = a[n/2+1] ... a[n]
11xSort(11)
12xSort(12)
return mergeArrays(11, 12)
end procedure
2. When two keys result in having the same hash value, the condition is call
Answer: Collision
3.Binary tree
Ans: 305
4.A self-adjusting tree in which the element on which operation is performed becomes the root
of the tree
Answer : Splay Tree
5.A B tree that stores data on leaf nodes and keys in internal nodes is known as
Answer : B+ Tree
6.The least time complexity of removing duplicate from the unsorted linked list
Answer: O(n)
The least time complexity for removing duplicates from an unsorted linked list is O(n), where n is
the number of elements in the linked list. This can be achieved by using a hash set to keep track
of unique elements while traversing the linked list.
8.There are two data structures, one an array and another a singleked list Both stores same set
of elements. Let A indicate time taken to search in an array,B indicate to search in a linked list.
Which of the following is true on a typical modern computer.
Answer: A< B
On a modern computer, searching in an array is generally faster than in a linked list due to
better cache efficiency and potential use of binary search. Hence, A < B.
Red-black trees
AVL Trees
2-3 Trees
None of the above
Ans:- None of the above
12.Sam has a problem K. The problem K is NP-complete if K is NP-hard. Which of the following
conditions satisfy this?
a) K:NP
b) K directly proportional to NP
c) KENP
d) K=NP
Answer: d) K=NP
13.A hash table has 12 buckets and uses linear probing to insert values. The hash function is K
mod 8 and the key values are combined. The elements 11, 17, 14, 21, 31, 28, 51, 18 were
inserted into the hash table in that order, which location holds the 18.
a) 1
b) 4
c) 7
d) 2
Answer: 2
14. Thomas has written an algorithm to sort an array. The algorithm is given below.
Thomas to get the running time required for this algorithm.
list: array of items
n: size of list
for i = 1 to n - 1
min=1 for j = 1 + 1 to n if list[j] < list[min] then min - 33
end if end for
if indexMin 1 = i then swap list[min] and 1ist[1] end if end for
end procedure
a) O(log(2n)) (logbase2)
B) O(n10g * 2n) logbase2)
c) O(n)
d) O(n ^ 2)
Answer: d) O(n ^ 2)
17. In linear search algorithm, the worst case manifests in which of the following situations?
a) When item is the last element in the array
b) When item is the last element in the array or When item is not in the array at all
c) None of the given options
Answer: b) When item is the last element in the array or When item is not in the array at all
18. Which of the following solutions would you get when you apply Prim's algorithm on a graph?
a) Traveling salesman problem
b) Graph coloring problem
c) Transitive closure of a graph
d) Minimum cost spanning tree
Answer: d) Minimum cost spanning tree
19. As a schedular, Operating System has to schedule different jobs that are coming for
processing. OS has to refine the precedence of each job for scheduling. Which queue is used
for storing and scheduling these jobs?
a) Linear Queue
b) Circular Queue
c) Dequeue
d) Priority Queue
Answer: d) Priority Queue
20. you want to store the following data of N students and porform the operations like searching
and sorting Which of the following you will use for the same?
Answer: Array of Structures.
21. Which of the following solutions would you get when you apply Prim's algorithmon a graph?
Answer: Minimum Spanning Tree (MST)
24.Which of the following sorting algorithms can be used to sort a random linked list with
minimum time complexity?
a) Insertion Sort
b) Quick Sort
c) Heap Sort
d) Merge Sort
Answer: d) Merge Sort
25. Which of the following is true about linked list implementation of stack?
a) In push operation, if new nodes are inserted at the beginning of linked list, then in pop
operation, nodes must be removed from end.
b) In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be
removed from the beginning.
c) Both of the above
d) None of the above
Answer: d) None of the above
26. Which of the following is an advantage of adjacency list representation over adjacency
matrix representation of a graph?
a) In adjacency list representation, space is saved for sparse graphs.
b) DFS and BSF can be done in O(V+ E) time for adjacency list representation.
These operations take O(V^2) time in adjacency matrix representation. Here is
V and E are number of vertices and edges respectively.
c) Adding a vertex in adjacency list representation is easier than adjacency matrix
representation.
d) All of the above
Answer: d) All of the above
27. Which of the following sorting algorithms follows the divide-and-conquer approach?
a) Insertion sort
b) Bubble sort
c) Quick sort
d) None of the above
Answer: c) Quick sort
30. When determining the efficiency of an algorithm, how would you measure
the space factor?
a) By counting the maximum memory needed by the algorithm
b) By counting the minimum memory owned by algorithm
c) By counting the average memory needed by the algorithm
d) By counting the maximum disk space made by the the algorithm
Answer: a) By counting the maximum memory needed by the algorithm
32. You want to store n integer numbers inputed by the user and perform the actions like
searching and sorting on those numbers. Which of the following
you will use to store the data?
a) Structure
b) Union
c) Variable
d) Arrays
Answer: d) Arrays
34. what an extra key inserted at the end of the arrayis called?
a) Transposition
b) Stop key
c) Sentinel
D) Not sure
Answer: c) Sentinel
39. What will be the output of the following code snippet if head is pointing to the first node of
the given linked list 6->7->8->9->10->11
void printx(struct node head)
{ if(!head)
return;
printf("%d ", head->data);
if(head->next){
printx(head->next->next);
printf("%d ", head->data);
}
}
Answer: B. 6 8 10 10 8 6
11 10 9 8 7 6
6 8 10 10 8 6
40.Stack is implemented using an array arr= (1, 4, 3, 6, 5), if for
every odd number one even number is popped, and if an even number does not exist, then the
odd number is not popped,
which element will be at TOP in the end?
Answer : 1 not confirmed
6
3
4
1
42.You are given a graph of 5 nodes. How will you detect whether the graph is also a tree?
Answer: b.if there are not one or more cycles in the graph.
43.What will strcmp() function returns when two strings are identical?
Answer : 0
1
-1
0
True
45. Given an array that contains the numbers 1 through 8 in ascending order, identify the
longest subsequence where the product of its elements, when divided by 8, yields a reminder of
exactly 1
Answer : 1 3 5 7
1357
12357
1246
1568
46.What is the minimum time complexity for removing duplicates from an unsorted linked list?
Answer : O(n)
O(n ^ 3)
O(n ^ 4)
O(n)
None
48.count = 0
for i in range(3):
for j in range(3):
count += i+ j
After the code execution, what will be the value of 'count?
Answer : 18
6
14
18
24
49.Which of the following data structure can be used for performing undo and redo operations?
Answer: stack
Tree
Graph
Stack
// Step 2: Transfer all elements back from the stack to the queue
while (!isEmpty(&st)) // Check if the stack is not empty
{
enQueue(Queue, pop(&st)); // Pop the top element from the stack and enqueue it back to
the queue
}
}
Answer : D. Reversea the queue
Removes the last from Queue
Keeps the queue the same as it was before the ca
Makes the queue empty
Reverse the Queue
51. Consider the following statements about the Insertion Sort algorithm:
1. When the elements are already sorted, it takes an order of n time to complete
2. It is a stable sorting technique.
3. it is typically used when the number of elements is extremely large.
Which of the above statements are true?
Answer : 1&2 are true
doselectau izdoselectquiz
ziuatcelesod
poselectquiz
53.
10
12
16
9
54.The steps to write a function in C language that adds a single new node at the start of any
linked list are given in a jumbled order. Select the option that denotes the correct sequence of
steps.
A. Make the first pointer point to the new node.
B. Allocate a new node from the heap.
C. Store the required data in data element of the node.
D. Make the new node point to the current first node of the list.
Answe : B C D A
ABCD
CBDA
BCDA
55.
56.Given a binary max heap that contains 'n' numbers, what is the time complexity to find the
smallest element?
Answer : O(n)
O(logn)
O(n)
O(loglogn)
O(1)
57.If the stack is implemented using an array arr = (2, 5, 13, 4, 15, 6, 7, 8, 9) (0-based indexing)
Which element would be at the top of stack, if the last element of the array is inserted first in the
stack?
Answer: 2
13
5
9
2
58.Which sorting algorithm is the most efficient for large datasets with random order?
Answer : Quick Sort
Bubble Sort
Selection Sort
Quick Sort
insertion Sort
59.Bran made a full binary tree. If the binary tree contains 12 numbers of internal nodes, how
many leave nodes does the binary tree contain
Choose from the following options.
Answer :
24
11
13
25
Answer: 5
64.Stephen has a linked list composed of 6 nodes that he wishes to sort. Given the sorting
techniques of Quick Sort and Merge Sort, which one would be the most suitable for his needs?
Answer: 1. (Merge sort most suitable)
65.Consider a node X in a Binary Tree. Given that X has two children, let Y be inorder
successor of X. Which of the following is true about Y?
Answer : B.Y has no left child
Y has no right child
Y has no left child
Y nas both children
None of the above
Ans: C.ArrayIndexOutOfBoundsException
NullPointerException
0
ArrayIndexOutOfBoundsException
it prints nothing
67.What is the lifetime of a dynamically allocated variable?
Answer : B.until programs ends
Until scope end
until manually deallocated
Until program ends
Until function returns
69.If a stack of N elements is implemented with only one queue, one pop operation is equal to
how many enqueue and dequeue operations in general?
Answer : N-1 enqueue, 1 dequeue
(Please choose answer)
N-1 enqueue. N dequeue
1 enqueue, N-Idequeue
1 enqueue, 1 dequeue
N-1 enqueue, 1 dequeue
70. The enqueue() method is used to add an element to a queue whereas the deque() method
is used to remove an element from the queue.
What is the output of the following pseudocode?
QUEUE q
q.enqueue(9)
q.enqueue(4)
q.deque()
q.enqueue(2)
q.deque()
q.enqueue(6)
q.enqueue(12)
PRINT q.front()
Ans : 2
71. What is the complexity of Dijkstra's Algorithm? No
Answer :
(Please choose a correct answer)
O(E + V logE)
O(V logE)
O(V + ElogV)
0(E logV)
72. Aman likes to solve challenging problems. Once his friend gave him two arrays of the same
length. His task is to find the value of two summations
Z=Σ Σ max(Ai+Bj, Bi+Aj)
A=[1,2,4,3]
B=(2,3,8,1]]
Answer : 114
(Please choose a correct answer)
120
114
130
None of these
73. How many subarrays have to be searched to find the element 0 in the given below array
when the Binary search algorithm is applied?
A = (0,1,2,3,4,5,12,13,15)
Answer :
(Please choose a correct answer)
2
3
1
0
74.Consider a sorting technique referred to as 'X'. The following characteristics are known about
'X':
1. 'X' is not a comparison-based sorting technique.
2. The running time complexity of 'X' is O(n).
3. The space-time complexity is proportional to the range of the data.
Based on these characteristics, which sorting technique could 'X' possibly be?
Answer : C.Count sort
(Please choose a correct answer)
Bubble sort
Insertion sort
Count sort
Merge Sort
75.
76.Consider the below algorithm. What is the error in the logic for the given binary search ?
1. Set L to and R ton - 1.
2. If L < R, the search terminates as unsuccessful.
3. Set m (the position of the middle element) to the floor (the largest previous integer) of (L +
R)/2.
4. If Am <T, set L to m + 1 and go to step 2
5. If Am > T, set R to m1 and go to step 2.
6. Now Am T, the search is done; return m.
Answer : In line 2, L should be greater than R for array arranged in descending order
(Please choose a correct answer)
In line 2, L should be greater than R
In line 3, the floor ((L+R)/2) should be (L+(L+R))/2)
In line 2, L should be greater than R for array arranged in descending order
None
77.Suppose we are sorting an array of eight integers using heapsort, and we have just finished
some heapify (either maxheapify or minheapify) operations. The array now looks like this
16 14 15 10 12 27 28
How many heapify operations have been performed on root of heap?
Answer : 3 or 4
Please choose a correct answer)
1
2
3 or 4
5
78.Stack is implemented using an array arr=(11, 12, 13, 14, 15) of size 5, what would be an
index of TOP if 16 is to be pushed? (assume 0-based indexing
Answer: C. No element can be pushed
15
11
No element can be pushed.
None of the Above
79.
Answer: 9 6 3
80.Bran made a full binary tree. If the binary tree contains 12 numbers of internal nodes, how
many leave nodes does the binary tree contain.
Choose from the following options.
Answer: 13. L = i+1
Please choose a correct answer)
24
11
13
25
Answer : Stack
(Please choose a correct answer)
Heap
Stack
Text
Data