Objectivequestions DS Example-1
Objectivequestions DS Example-1
insertion can take place only at the other end (rear) is known as _____________
a) Queue
b) Stack
c) Tree
d) Linked list
Answer a
2) The data structure required for Breadth First Traversal on a graph is?
a) Stack
b) Array
c) Queue
d) Tree
Answer: c
Answer: a
a) Ring Buffer
b) Square Buffer
c) Rectangle Buffer
d) Curve Buffer
Answer: a
Answer: a
Explanation: Queue follows FIFO approach. i.e. First in First Out Approach. So, the
order of removal elements are ABCD.
6) A data structure in which elements can be inserted or deleted at/from both ends but
not in the middle is?
a) Queue
b) Circular queue
c) Dequeue
d) Priority queue
Answer: c
Explanation: In dequeuer, we can insert or delete elements from both the ends. In
queue, we will follow first in first out principle for insertion and deletion of elements.
Element with least priority will be deleted in a priority queue.
7) A normal queue, if implemented using an array of size MAX_SIZE, gets full when?
a) Rear = MAX_SIZE – 1
b) Front = (rear + 1)mod MAX_SIZE
c) Front = rear + 1
d) Rear = front
Answer: a
Explanation: When Rear = MAX_SIZE – 1, there will be no space left for the elements to
be added in queue. Thus queue becomes full.
8) Queues serve major role in ______________
a) Simulation of recursion
b) Simulation of arbitrary linked list
c) Simulation of limited resource allocation
d) Simulation of heap sort
Answer: c
Explanation: Simulation of recursion uses stack data structure. Simulation of arbitrary
linked lists uses linked lists. Simulation of resource allocation uses queue as first
entered data needs to be given first priority during resource allocation. Simulation of
heap sort uses heap data structure.
9) Which of the following is not the type of queue?
a) Ordinary queue
b) Single ended queue
c) Circular queue
d) Priority queue
10) A linear collection of data elements where the linear node is given by means of
pointer is called?
a) Linked list
b) Node list
c) Primitive list
d) Unordered list
Answer: a
Explanation: In Linked list each node has its own data and the address of next node.
These nodes are linked by using pointers. Node list is an object that consists of a list of
all nodes in a document with in a particular selected set of nodes.
11) Consider an implementation of unsorted singly linked list. Suppose it has its
representation with a head pointer only. Given the representation, which of the
following operation can be implemented in O(1) time?
Answer: b
Explanation: We know the head node in the given linked list. Insertion and deletion of
elements at the front of the linked list completes in O (1) time whereas for insertion and
deletion at the last node requires to traverse through every node in the linked list.
Suppose there are n elements in a linked list, we need to traverse through each node.
Hence time complexity becomes O(n).
12) In linked list each node contains a minimum of two fields. One field is data field to
store the data second field is?
a) Pointer to character
b) Pointer to integer
c) Pointer to node
d) Node
Answer: c
Explanation: Each node in a linked list contains data and a pointer (reference) to the
next node. Second field contains pointer to node.
13) What would be the asymptotic time complexity to add a node at the end of singly
linked list, if the pointer is initially pointing to the head of the list?
a) O(1)
b) O(n)
c) θ(n)
d) θ(1)
Answer: c
Explanation: In case of a linked list having n elements, we need to travel through every
node of the list to add the element at the end of the list. Thus asymptotic time
complexity is θ(n).
14) What would be the asymptotic time complexity to insert an element at the front of
the linked list (head is known)?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
Answer: a
Explanation: To add an element at the front of the linked list, we will create a new node
which holds the data to be added to the linked list and pointer which points to head
position in the linked list. The entire thing happens within O (1) time. Thus the
asymptotic time complexity is O (1).
15) What would be the asymptotic time complexity to find an element in the linked list?
a) O(1)
b) O(n)
c) O(n2)
d) O(n4)
Answer: b
Explanation: If the required element is in the last position, we need to traverse the entire
linked list. This will take O (n) time to search the element.
16) What would be the asymptotic time complexity to insert an element at the second
position in the linked list?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
Answer: a
Explanation: A new node is created with the required element. The pointer of the new
node points the node to which the head node of the linked list is also pointing. The head
node pointer is changed and it points to the new node which we created earlier. The
entire process completes in O (1) time. Thus the asymptotic time complexity to insert an
element in the second position of the linked list is O (1).
17) The concatenation of two lists can be performed in O(1) time. Which of the following
variation of the linked list can be used?
a) Singly linked list
b) Doubly linked list
c) Circular doubly linked list
d) Array implementation of list
Answer: c
Explanation: We can easily concatenate two lists in O (1) time using singly or doubly
linked list, provided that we have a pointer to the last node at least one of the lists. But
in case of circular doubly linked lists, we will break the link in both the lists and hook
them together. Thus circular doubly linked list concatenates two lists in O (1) time.
18) Consider the following definition in c programming language.
struct node
{
int data;
struct node * next;
}
typedef struct node NODE;
NODE *ptr;
Which of the following c code is used to create new node?
a) ptr = (NODE*)malloc(sizeof(NODE));
b) ptr = (NODE*)malloc(NODE);
c) ptr = (NODE*)malloc(sizeof(NODE*));
d) ptr = (NODE)malloc(sizeof(NODE));
Answer: a
Explanation: Memory efficient doubly linked list has only one pointer to traverse the list
back and forth. The implementation is based on pointer difference. It uses bitwise XOR
operator to store the front and rear pointer addresses. Instead of storing actual memory
address, every node store the XOR address of previous and next nodes.
21)How do you calculate the pointer difference in a memory efficient double linked list?
a) head or tail
b) pointer to previous node or pointer to next node
c) pointer to previous node – pointer to next node
d) pointer to next node – pointer to previous node
Answer: b
Explanation: The pointer difference is calculated by taking XOR of pointer to previous
node and pointer to the next node.
22) What is the worst case time complexity of inserting a node in a doubly linked list?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(1)
Answer: c
Explanation: In the worst case, the position to be inserted maybe at the end of the list,
hence you have to traverse through the entire list to get to the correct position, hence
O(n).
Answer: c
Explanation: The given sequence of operations performs addition of nodes at the head
and tail of the list.
25) What is the functionality of the following piece of code?
Answer: b
Explanation: The previous and next pointers of the tail and the last but one element are
manipulated, this suggests that the last node is being removed from the list.
26) Consider the following doubly linked list: head-1-2-3-4-5-tail. What will be the list
after performing the given sequence of operations?
Node temp = new Node(6,head,head.getNext());
head.setNext(temp);
temp.getNext().setPrev(temp);
tail.setPrev(temp1.getPrev());
temp1.getPrev().setNext(tail);
a) head-6-1-2-3-4-5-tail
b) head-6-1-2-3-4-tail
c) head-1-2-3-4-5-6-tail
d) head-1-2-3-4-5-tail
Answer: b
Explanation: A new node is added to the head of the list and a node is deleted from the
tail end of the list.
27) In a Doubly Linked list how many nodes have atleast 1 node before and after it?
A. N+1
B. N
C. N-2
D. N-1
Correct Option: C
Array
D. All of these
Correct Option: C
29) The height of a BST is given as h. Consider the height of the tree as the no. of
edges in the longest path from root to the leaf. The maximum no. of nodes possible in
A. 2h-1 -1
B. 2h+1 -1
C. 2h +1
D. 2h-1 +1
Correct Option: B
30. Which type of traversal of binary search tree outputs the value in sorted order?
A. Post-order
B. Pre-order
C. In-order
D. None
Correct Option: C
31) the run time for traversing all the nodes of a binary search tree with n nodes and
A. O(n)
B. O(√n)
C. O(log(n))
D. O(nlg(n))
Correct Option: A
32)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 the node in the left sub-tree and right
A. (3, 8)
B. (8, 3)
C. (7, 4)
D. (4, 7)
Correct Option: C
33) Which of the following is the correct postfix format for this infix format A + B – C + D
A. -+DC+BA
B. AB+CD+-
C. +BA-+CD
D. None of these
Correct Option: B
Group A Group B
C. Arrays 3. FIFO
D. Trees 4. LIFO
Correct Option: B
35) Priya has a box that looks like a stack and she does the following operations on
empty box
PUSH(8)
PUSH(7)
POP
PUSH(1)
PUSH(3)
A. 31_8
B. 8_1_7
C. 8_1_
D. None of these
Correct Option: C
36) Cloe has x number of stacks her father wants her to write a program that can
perform as a queue. What will you suggest to her how many stacks must she use?
A. 1
B. 2
C. 4
D. 3
Correct Option: B
37)These operations can be performed on which type of structure? Push, Pop, Peek
A. Queue
B. Priority Queue
C.Stack
D. Both 1 and 2
Correct Option: C
B. When data is transferred asynchronously (data not necessarily received at same rate
C. Load Balancing
Correct Option: D
Explain :- Queue has many applications like – 1) When a resource is shared among
multiple consumers. Examples include CPU scheduling, Disk Scheduling. 2) When data
between two processes. Examples include IO Buffers, pipes, file IO, etc.
39)The retrieval of items in a stack is ……….. operation.
A. push
B. pop
C. retrieval
D. access
Correct Option: B
40)In a queue, the initial values of front pointer f rare pointer r should be …….. and
……….. respectively.
A. -1, -1
B. 0, -1
C. 0, 0
D. -1, 0
Correct Option: A
41)When new data are to be inserted into a data structure, but there is not available
A. Memory Leak
B. Memory Full
C. OverLeak
D. Overflow
Correct Option: D
Correct Option: B
In a hash table, there are fewer array positions than the keys, so the position of the key
in the array has to be computed, this is done using the hash function.
A. O(n)
B. O(logn)
C. O(nlogn)
D. O(1)
Correct Option: D
Since every key has a unique array position, searching takes a constant time
Correct Option: B
Making the hash function random is not really a good choice, although it is considered
one of the techniques to avoid collisions along with chaining and simple uniform
45)Consider a hash function that distributes keys uniformly. The hash table size is 20.
After hashing of how many keys will the probability that any new key hashed collides
A. 40
B. 2
C. 5
D. 10
Correct Option: D
For each entry probability of collision is 1/20 {as possible total spaces =20, and an entry
will go into only 1 place} Say after inserting x values probability becomes ½ (1/20).x = ½
X=10
46)Which will be the best to implement the following a car comes at a petrol station and
waits. The next car to get its Gas filled should be the one which has waited the longest
A. Binary Trees
B. Heaps
C. m-way Trees
Correct Option: B
A. O(1)
B. O(n2)
C. O(log n)
D. O(n)
Correct Option: A
48) Every element of a data structure has an address and a key associated with it.A
search mechanism deals with two or more values assigned to the same address by
A. Linear Search
B. Binary search
D. None of these
Correct Option: C
49)In a binary max heap containing n numbers, the smallest element can be found in
time?
A. O(n)
B. O(log n)
C. O(log log n)
D. O(1)
Correct Option: A
50)The number of edges from the root to the node is called __________ of the tree.
a) Height
b) Depth
c) Length
d) Width
Answer: b
51)The number of edges from the node to the deepest leaf is called _________ of the
tree.
a) Height
b) Depth
c) Length
d) Width
Answer: a
Answer: a
53)What is a complete binary tree?
b) A binary tree, which is completely filled, with the possible exception of the bottom
c) A binary tree, which is completely filled, with the possible exception of the bottom
Answer: c
54)What is the average case time complexity for finding the height of the binary tree?
a) h = O(loglogn)
b) h = O(nlogn)
c) h = O(n)
d) h = O(log n)
Answer: d
a) Hierarchical structure
b) Faster search
c) Router algorithms
Answer:d
Explanation: Undo/Redo operations in a notepad is an application of stack.
Hierarchical structure, Faster search, Router algorithms are advantages of trees.
56)In a full binary tree if number of internal nodes is I, then number of leaves L are?
a)L=2*I
b)L=I+1
c)L=I–1
d) L = 2*I – 1
Answer: b
57)In a full binary tree if number of internal nodes is I, then number of nodes N are?
a)N= 2*I
b)N= I + 1
c)N = I – 1
d) N = 2*I + 1
Answer: d
58) In a full binary tree if there are L leaves, then total number of nodes N are?
a) N = 2*L
b) N = L + 1
c) N = L – 1
d) N = 2*L – 1
Answer: d
Answer: d
60)What is the maximum number of children that a binary tree node can have?
a) 0
b) 1
c) 2
d) 3
Answer: c
61)The following given tree is an example for?
a) Binary tree
b) Binary search tree
c) Fibonacci tree
d) AVL tree
Answer: a
Answer: b
Answer: c
Answer: b
Answer: c
Answer: a
Answer: b
Answer: d
70)How many orders of traversal are applicable to a binary tree (In General)?
a) 1
b) 4
c) 2
d) 3
Answer: d
71)If binary trees are represented in arrays, what formula can be used to locate a left
child,if the node has an index i?
a) 2i+1
b) 2i+2
c) 2i
d) 4i
Answer: a
Answer: b
73)Which of the following properties are obeyed by all three tree – traversals?
a) Left subtrees are visited before right subtrees
b) Right subtrees are visited before left subtrees
c) Root node is visited before left subtree
d) Root node is visited before right subtree
Answer :a
74)For the tree below, write the pre-order traversal.
a) 2, 7, 2, 6, 5, 11, 5, 9, 4
b) 2, 7, 5, 2, 6, 9, 5, 11, 4
c) 2, 5, 11, 6, 7, 4, 9, 5, 2
d) 2, 7, 5, 6, 11, 2, 5, 4, 9
Answer: a
a) 2, 7, 2, 6, 5, 11, 5, 9, 4
b) 2, 7, 5, 2, 6, 9, 5, 11, 4
c) 2, 5, 11, 6, 7, 4, 9, 5, 2
d) 2, 7, 5, 6, 11, 2, 5, 4, 9
Answer: c
Answer: b
78) What is the space complexity of the post-order traversal in the recursive fashion? (d
is the tree depth and n is the number of nodes)
a) O(1)
b) O(nlogd)
c) O(logd)
d) O(d)
Answer: d
Answer: b
80)Consider the following data. The pre order traversal of a binary tree is A, B, E, C, D.
The in order traversal of the same binary tree is B, E, A, D, C. The level order sequence
for the binary tree is _________
a) A, C, D, B, E
b) A, B, C, D, E
c) A, B, C, E, D
d) D, B, E, A, C
Answer: b
81)Consider the following data and specify which one is Preorder Traversal Sequence,
Inorder and Postorder sequences.
S1: N, M, P, O, Q
S2: N, P, Q, O, M
S3: M, N, O, P, Q
a) S1 is preorder, S2 is inorder and S3 is postorder
b) S1 is inorder, S2 is preorder and S3 is postorder
c) S1 is inorder, S2 is postorder and S3 is preorder
d) S1 is postorder, S2 is inorder and S3 is preorder
Answer: c
Answer: b
Explanation: As the name suggests, internal sorting algorithm uses internal main
memory.
Answer: d
Explanation: Bubble sort works by starting from the first element and swapping the
elements if required in each iteration.
Answer: d
Explanation: Bubble sort works by starting from the first element and swapping the
elements if required in each iteration even in the average case.
86. What is the best case efficiency of bubble sort in the improvised version?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
View Answer:-Answer: c
Explanation: Some iterations can be skipped if the list is sorted, hence efficiency
improves to O(n).
87. What is the worst case complexity of selection sort?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
View Answer
Answer: d
Explanation: Selection sort creates a sub-list, LHS of the ‘min’ element is already sorted
and RHS is yet to be sorted. Starting with the first element the ‘min’ element moves
towards the final element.
Answer: d
Explanation: The best, average and worst case complexities of selection sort is O(n 2).
(n-1) + (n-2) + (n-3) + …. + 1 = (n(n-1))/2 ~ (n2)/2.
89. How many passes does an insertion sort algorithm consist of?
a) N
b) N-1
c) N+1
d) N2
Answer: b
Explanation: An insertion algorithm consists of N-1 passes when an array of N elements
is given.
90. What is the average case running time of an insertion sort algorithm?
a) O(N)
b) O(N log N)
c) O(log N)
d) O(N2)
Answer: d
Explanation: The average case analysis of a tight bound algorithm is mathematically
achieved to be O(N2).
91. Any algorithm that sorts by exchanging adjacent elements require O(N2) on
average.
a) True
b) False
View Answer
Answer: a
Explanation: Each swap removes only one inversion, so O(N2) swaps are required.
92. What is the running time of an insertion sort algorithm if the input is pre-sorted?
a) O(N2)
b) O(N log N)
c) O(N)
d) O(M log N)
View Answer
Answer: c
Explanation: If the input is pre-sorted, the running time is O(N), because the test in the
inner for loop always fails immediately and the algorithm will run quickly.
93. What will be the number of passes to sort the elements using insertion sort?
14, 12,16, 6, 3, 10
a) 6
b) 5
c) 7
d) 1
View Answer
Answer: b
Explanation: The number of passes is given by N-1. Here, N=6. Therefore,
6-1=5 passes.
94. For the following question, how will the array elements look like after second pass?
34, 8, 64, 51, 32, 21
a) 8, 21, 32, 34, 51, 64
b) 8, 32, 34, 51, 64, 21
c) 8, 34, 51, 64, 32, 21
d) 8, 34, 64, 51, 32, 21
View Answer
Answer: d
Explanation: After swapping elements in the second pass, the array will look like, 8, 34,
64, 51, 32, 21.
95. Which of the following real time examples is based on insertion sort?
a) arranging a pack of playing cards
b) database scenarios and distributes scenarios
c) arranging books on a library shelf
d) real-time systems
View Answer
Answer: a
Explanation: Arranging a pack of cards mimics an insertion sort.
96. For the best case input, the running time of an insertion sort algorithm is?
a) Linear
b) Binary
c) Quadratic
d) Depends on the input
View Answer
Answer: a
Explanation: The best case input for an insertion sort algorithm runs in linear time and is
given by O(N).
97. Which of the following examples represent the worst case input for an insertion
sort?
a) array in sorted order
b) array sorted in reverse order
c) normal unsorted array
d) large array
Answer: b
Explanation: The worst case input for an insertion sort algorithm will be an array sorted
in reverse order and its running time is quadratic.
98. Merge sort uses which of the following technique to implement sorting?
a) backtracking
b) greedy algorithm
c) divide and conquer
d) dynamic programming
Answer: c
Explanation: Merge sort uses divide and conquer in order to sort a given array. This is
because it divides the array into two halves and applies merge sort algorithm to each
half individually after which the two sorted halves are merged together.
99. What is the average case time complexity of merge sort?
a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)
Answer: a
Answer: c
Explanation: An additional space of O(n) is required in order to merge two sorted arrays.
103. Which of the following method is used for sorting in merge sort?
a) merging
b) partitioning
c) selection
d) exchanging
Answer: a
Explanation: Merge sort algorithm divides the array into two halves and applies merge
sort algorithm to each half individually after which the two sorted halves are merged
together. Thus its method of sorting is called merging.
104. What will be the best case time complexity of merge sort?
a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)
Answer: a
Explanation: The time complexity of merge sort is not affected in any case as its
algorithm has to implement the same number of steps. So its time complexity remains
to be O(n log n) even in the best case.
107. What is the worst case time complexity of a quick sort algorithm?
a) O(N)
b) O(N log N)
c) O(N2)
d) O(log N)
Answer: c
Explanation: The worst case performance of a quick sort algorithm is mathematically
found to be O(N2).
108. What is the average running time of a quick sort algorithm?
a) O(N2)
b) O(N)
c) O(N log N)
d) O(log N)
Answer: c
Explanation: The best case and average case analysis of a quick sort algorithm are
mathematically found to be O(N log N).
109. How many sub arrays does the quick sort algorithm divide the entire array into?
a) one
b) two
c) three
d) four
Answer: b
Explanation: The entire array is divided into two partitions, 1st sub array containing
elements less than the pivot element and 2nd sub array containing elements greater
than the pivot element.
a) 26,53,41,97,58,59,31
b) 26,31,41,53,58,59,97
c) 26,41,53,97,31,58,59
d) 97,53,59,26,41,58,31
Answer: d
Explanation: Constructing a max heap using the elements 97,53,59,26,41,58,31 will
cause the heap to look like that.
113. In what position does the array for heap sort contains data?
a) 0
b) 1
c) -1
d) anywhere in the array
Answer: a
Explanation: The array for heap sort contains data at position 0 whereas for a binary
heap, array begins at 1. This is the reason for its complexity.