Linked List

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

1.

Which of the following points is/are true about


Linked List data structure when it is compared with
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. All of the above
Ans: d
2.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
Ans: b
3.What is the output of following function for start
pointing to first node of following linked list?
1->2->3->4->5->6
void fun(struct node* start)
{
if(start == NULL) return; printf("%d ", start->data);
if(start->next != NULL ) fun(start->next->next);
printf("%d ", start->data);
}
a.1 4 6 6 4 1 b. 1 3 5 1 3 5
c. 1 2 3 5 d. 1 3 5 5 3 1
Ans: d
4.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 deletion of a node is easier than single
linked list
d. None of the mentioned
Ans: d
5.The situation when in a linked list
START=NULL is ____________

a. Underflow
b. Overflow
c. Houseful
d. Saturated.
Ans: a
6.In a circular linked list

a. Components are all linked together in some


sequential manner.
b. There is no beginning, only end will be there.
c.Components are arranged hierarchically.
d. Forward and backward traversal within the
list is permitted.
Ans: b

To implement a circular singly linked list, we


take an external pointer that points to the last
node of the list. If we have a pointer last
pointing to the last node, then last -> next will
point to the first node.
7.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. None
Ans: b
8.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));
Ans: a
9. A circularly linked list is used to represent a Queue. A single
variable p is used to access the Queue. To which node should p
point such that both the operations enQueue and deQueue can be
performed in constant time?

(A) rear node
(B) front node
(C) not possible with a single pointer
(D) node next to front.
Answer: (A)
10. 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.
Answer: (A)
11. The time required to search an element in a linked list of
length n is
(A) O (log n)
(B) O (n)
(C)O (1)
(D) O(n2)
Answer: (B)
12. The minimum number of fields with each node of doubly
linked list is
(A) 1
(B)2
(C) 3
(D) 4
Answer: (C)

Explanation: In general, each node of doubly link list always has 3


fields, i.e., the previous node pointer, the data field, and the next
node pointer

You might also like