List
List
List
1. Definition of a list is to be
a) Finite
b) Infinite
c) No-limit
d) Empty
Answer: a
2. 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
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
Answer: c
6. 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
Answer: d
10. To Maintain a linked list in memory, how many parallel arrays of equal size are used?
a) 1
b) 2
c) 3
d) 4
Answer: b
13. 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
Answer: b
14. 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
Answer: d
15. The following C function takes a simply-linked list as input argument. It modifies the list by
moving the last element to the front of the list and returns the modified list. Some part of the
code is left blank. Choose the correct alternative to replace the blank line.
typedef struct node
{
int value;
struct node *next;
}Node;
Node *move_to_front(Node *head)
{
Node *p, *q;
if ((head == NULL: || (head->next == NULL))
return head;
q = NULL; p = head;
while (p-> next !=NULL)
{
q = p;
p = p->next;
}
----------------------------------------
return head;
}
a) q = NULL; p->next = head; head = p;
b) q->next = NULL; head = p; p->next = head;
c) head = p; p->next = q; q->next = NULL;
d) q->next = NULL; p->next = head; head = p;
Answer: d
16. The following C function takes a single-linked list of integers as a parameter and rearranges
the elements of the list. The function is called with the list containing the integers 1, 2, 3, 4,
5, 6, 7 in the given order. What will be the contents of the list after the function completes
execution?
struct node
{
int value;
struct node *next;
};
void rearrange(struct node *list) {
struct node *p, * q;
int temp;
if ((!list) || !list->next)
return;
p = list;
q = list->next;
while(q)
{
temp = p->value;
p->value = q->value;
q->value = temp;
p = q->next;
q = p?p->next:0;
}
}
a) 1, 2, 3, 4, 5, 6, 7
b) 2, 1, 4, 3, 6, 5, 7
c) 1, 3, 2, 5, 4, 7, 6
d) 2, 3, 4, 5, 6, 7, 1
Answer: b
17. Given pointer to a node X in a singly linked list. Only one pointer is given, pointer to head
node is not given, can we delete the node X from given linked list?
a) Possible if X not last node
b) Possible if size of linked list is even
c) Possible if size of linked list is odd
d) Possible if X is not first node
Answer: a
22. 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 give location
d) Traversing the list to process each node
Answer: a
23. The minimum number of fields with each node of doubly linked list is
a) 1
b) 2
c) 3
d) 4
Answer: c
25. Consider the below representation and predict what will be printed on the screen by
following statement ?
start->next->data
struct node {
int data;
struct node *next;
}*start = NULL
a) Access the “data” field of 3rd node
b) Access the “data” field of 1st node
c) Access the “data” field of 2nd node
d) None of these
Answer: c
29. When new element is added in the middle of singly linked list then --------.
a) Only elements that appear after the new element need to be moved
b) Only elements that appear before the new element need to be moved
c) No need to move element
d) Only elements that appear after the new element and before need to be moved
Answer: c