Unit-4 MCQ

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

1. 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
View Answer

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.

2. 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?

i) Insertion at the front of the linked list

ii) Insertion at the end of the linked list

iii) Deletion of the front node of the linked list

iv) Deletion of the last node of the linked list

a) I and II
b) I and III
c) I, II and III
d) I, II and IV
View Answer

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).

3. 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
View Answer
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.

advertisement

4. 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)
View Answer

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).

5. 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)
View Answer

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).

6. 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)
View Answer

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.

7. 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)
View Answer

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).

8. 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
View Answer

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.

9. 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)); View
Answer

Answer: a
Explanation: As it represents the right way to create a node.

10. What kind of linked list is best to answer questions like “What is the item at position n?”
a) Singly linked list
b) Doubly linked list
c) Circular linked list
d) Array implementation of linked list
View Answer

Answer: d
Explanation: Arrays provide random access to elements by providing the index value within square
brackets. In the linked list, we need to traverse through each element until we reach the nth position.
Time taken to access an element represented in arrays is less than the singly, doubly and circular linked
lists. Thus, array implementation is used to access the item at the position n.

11. Linked lists are not suitable for the implementation of


a) Insertion sort
b) Radix sort
c) Polynomial manipulation
d) Binary search
View Answer

Answer: d
Explanation: It cannot be implemented using linked lists.

12. Linked list is considered as an example of type of memory allocation.


a) Dynamic
b) Static
c) Compile time
d) Heap
View Answer

Answer: a
Explanation: As memory is allocated at the run time.

13. In Linked List implementation, a node carries information regarding


a) Data
b) Link
c) Data and Link
d) Node
View Answer

Answer: b
Explanation: A linked list is a collection of objects linked together by references from an object to
another object. By convention these objects are names as nodes. Linked list consists of nodes where
each node contains one or more data fields and a reference(link) to the next node.

14. Linked list data structure offers considerable saving in


a) Computational Time
b) Space Utilization
c) Space Utilization and Computational Time
d) Speed Utilization
View Answer

Answer: c
Explanation: Linked lists saves both space and time.

advertisement

15. Which of the following points is/are not true about Linked List data structure when it is compared
with an array?
a) Arrays have better cache locality that can make them better in terms of performance
b) It is easy to insert and delete elements in Linked List
c) Random access is not allowed in a typical implementation of Linked Lists
d) Access of elements in linked list takes less time than compared to arrays
View Answer

Answer: d
Explanation: To access an element in a linked list, we need to traverse every element until we reach the
desired element. This will take more time than arrays as arrays provide random access to its elements.

16. What does the following function do for a given Linked List with first node as head?

void fun1(struct node* head)

if(head == NULL)

return;

fun1(head->next);

printf("%d ", head->data);


}

a) Prints all nodes of linked lists


b) Prints all nodes of linked list in reverse order
c) Prints alternate nodes of Linked List
d) Prints alternate nodes in reverse order
View Answer

17. 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
View Answer

Answer: d
Explanation: Both Merge sort and Insertion sort can be used for linked lists. The slow random-access
performance of a linked list makes other algorithms (such as quicksort) perform poorly, and others (such
as heapsort) completely impossible. Since worst case time complexity of Merge Sort is O(nLogn) and
Insertion sort is O(n2), merge sort is preferred.

18. 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
c) Insertion based on position
d) Accessing elements at specified positions
View Answer

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.

19. What is the time complexity of inserting at the end in dynamic arrays?
a) O(1)
b) O(n)
c) O(logn)
d) Either O(1) or O(n)
View Answer

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.

20. 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)
View Answer

Answer: b
Explanation: To count the number of elements, you have to traverse through the entire list, hence
complexity is O(n).

21 .Which of the following is false about a doubly linked list?


a) We can navigate in both the directions
b) It requires more space than a singly linked list
c) The insertion and deletion of a node take a bit longer
d) Implementing a doubly linked list is easier than singly linked list
View Answer

Answer: d

22.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
d) Head node is known in circular linked list
View Answer

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)

You might also like