UNIT 4 - Linked List: 1. Which of The Following Is Not A Disadvantage To The Usage of Array?
UNIT 4 - Linked List: 1. Which of The Following Is Not A Disadvantage To The Usage of Array?
a) Fixed size
b) There are chances of wastage of memory space if elements inserted in an array are lesser
than the allocated size
Answer: d
Explanation: Array elements can be accessed in two steps. First, multiply the size of the data
type with the specified position, second, add this value to the base address. Both of these
operations can be done in constant time, hence accessing elements at a given index/position is
faster.
a) O(1)
b) O(n)
c) O(logn)
Answer: d
Explanation: Depending on whether the array is full or not, the complexity in dynamic array
varies. If you try to insert into an array that is not full, then the element is simply stored at the
end, this takes O(1) time. If you try to insert into an array which is full, first you will have to
allocate an array with double the size of the current array and then copy all the elements into it
and finally insert the new element, this takes O(n) time.
3. What is the time complexity to count the number of elements in the linked list?
a) O(1)
b) O(n)
c) O(logn)
d) O(n2)
Answer: b
Explanation: To count the number of elements, you have to traverse through the entire list,
hence complexity is O(n).
Answer: d
Explanation: To implement file system, for separate chaining in hash-tables and to implement
non-binary trees linked lists are used. Elements are accessed sequentially in linked list. Random
access of elements is not an applications of linked list.
a) O(1)
b) O(n)
d) O(logn)
Answer: a
Explanation: You need a temp variable to keep track of current node, hence the space
complexity is O(1).
Answer: d
Explanation: A doubly linked list has two pointers ‘left’ and ‘right’ which enable it to traverse in
either direction. Compared to singly liked list which has only a ‘next’ pointer, doubly linked list
requires extra space to store this extra pointer. Every insertion and deletion requires
manipulation of two pointers, hence it takes a bit longer time. Implementing doubly linked list
involves setting both left and right pointers to correct nodes and takes more time than singly
linked list.
8. How do you calculate the pointer difference in a memory efficient double linked list?
Answer: b
Explanation: The pointer difference is calculated by taking XOR of pointer to previous node and
pointer to the next node.
9. 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).
10. What differentiates a circular linked list from a normal linked list?
a) You cannot have the ‘next’ pointer point to null in a circular linked list
b) It is faster to traverse the circular linked list
c) You may or may not have the ‘next’ pointer point to null in a circular linked list
Answer: c
Explanation: The ‘next’ pointer points to null only when the list is empty, otherwise it points to
the head of the list. Every node in a circular linked list can be a starting point(head).
11. What is the time complexity of searching for an element in a circular linked list?
a) O(n)
b) O(nlogn)
c) O(1)
d) O(n2)
Answer: a
Explanation: In the worst case, you have to traverse through the entire list of n elements.
12. Which of the following application makes use of a circular linked list?
Answer: c
Explanation: Generally, round robin fashion is employed to allocate CPU time to resources
which makes use of the circular linked list data structure. Recursive function calls use stack data
structure. Undo Operation in text editor uses doubly linked lists. Hash tables uses singly linked
lists.
b) Time complexity of inserting a new node at the head of the list is O(1)
c) Time complexity for deleting the last node is O(n)
d) We can traverse the whole circular linked list by starting from any point
Answer: b
Explanation: Time complexity of inserting a new node at the head of the list is O(n) because you
have to traverse through the list to find the tail node.
14. What is the best case time complexity of deleting a node in a Singly Linked list?
a) O (n)
b) O (n2)
c) O (nlogn)
d) O (1)
Answer: d
Explanation: Deletion of the head node in the linked list is taken as the best case. The successor
of the head node is changed to head and deletes the predecessor of the newly assigned head
node. This process completes in O(1) time.
15. Which of the following statements are not correct with respect to Singly Linked List(SLL)
and Doubly Linked List(DLL)?
a) Complexity of Insertion and Deletion at known position is O(n) in SLL and O(1) in DLL
Answer: d
Explanation: To insert and delete at known positions requires complete traversal of the list in
worst case in SLL, SLL consists of an item and a node field, while DLL has an item and two node
fields, hence SLL occupies lesser memory, DLL can be traversed both ways(left and right), while
SLL can traverse in only one direction, hence more searching power of DLL. Node fields in SLL is
2 (data and address of next node) whereas in DLL is 3(data, address to next node, address to
previous node).
16. What does ‘stack overflow’ refer to?
Answer: b
17. In linked list implementation of queue, if only front pointer is maintained, which of the
following operation take worst case linear time?
a) Insertion
b) Deletion
c) To empty a queue
Answer: d
Explanation: Since front pointer is used for deletion, so worst time for the other two cases.
18. In linked list implementation of a queue, where does a new element be inserted?
Answer: c
19. In case of insertion into a linked queue, a node borrowed from the __________ list is
inserted in the queue.
a) AVAIL
b) FRONT
c) REAR
d) NULL
Answer: a
20. In linked list implementation of a queue, the important condition for a queue to be empty
is?
a) FRONT is null
b) REAR is null
c) LINK is empty
d) FRONT==REAR-1
Answer: a
21. The essential condition which is checked before insertion in a linked queue is?
a) Underflow
b) Overflow
c) Front value
d) Rear value
Answer: a
Answer: d