Linked List Quiz
Linked Lists
Quizsummary
0 of 14 questions completed
Questions:
 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
Information
Basic questions on Data Structures.
You must specify a text. 

You must specify an email address. 
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
Results
0 of 14 questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 points, (0)
Categories
 Linked Lists 0%
 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 Answered
 Review

Question 1 of 14
1. Question
1 pointsWhat 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); }
Correct
Incorrect

Question 2 of 14
2. Question
1 pointsConsider the following function that takes reference to head of a Doubly Linked List as parameter. Assume that a node of doubly linked list has previous pointer as prev and next pointer as next
void fun(struct node **head_ref) { struct node *temp = NULL; struct node *current = *head_ref; while (current != NULL) { temp = current>prev; current>prev = current>next; current>next = temp; current = current>prev; } if(temp != NULL ) *head_ref = temp>prev; }
Assume that reference of head of following doubly linked list is passed to above function 1 2 3 4 5 6. What should be the modified linked list after the function call?
Correct
Incorrect

Question 3 of 14
3. Question
1 pointsWhat 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);
}
Correct
Incorrect
fun() prints alternate nodes of the given Linked List, first from head to end, and then from end to head. If Linked List has even number of nodes, then skips the last node.

Question 4 of 14
4. Question
1 pointsWhich of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?
Correct
Incorrect
Both Merge sort and Insertion sort can be used for linked lists. The slow randomaccess 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(n^2), merge sort is preferred.

Question 5 of 14
5. Question
1 pointsWhich of the following points is/are true about Linked List data structure when it is compared with an array?
Correct
Incorrect

Question 6 of 14
6. Question
1 pointsSuppose each set is represented as a linked list with elements in arbitrary order. Which of the operations among union, intersection, membership, cardinality will be the slowest? (GATE CS 2004)
Correct
Incorrect
For getting intersection of L1 and L2, search for each element of L1 in L2 and print the elements we find in L2. There can be many ways for getting union of L1 and L2. One of them is as follows
a) Print all the nodes of L1 and print only those which are not present in L2.
b) Print nodes of L2.
All of these methods will require more operations than intersection as we have to process intersection node plus other nodes. 
Question 7 of 14
7. Question
1 pointsConsider the function f defined below.
struct item { int data; struct item * next; }; int f(struct item *p) { return ((p == NULL)  (p>next == NULL)  (( p>data <= p>next>data) && f(p>next))); }
For a given linked list p, the function f returns 1 if and only if
Correct
Incorrect
The function f() works as follows
1) If linked list is empty return 1
2) Else If linked list has only one element return 1
3) Else if node>data is smaller than equal to node>next>data and same thing holds for rest of the list then return 1
4) Else return 0 
Question 8 of 14
8. Question
1 pointsA 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?
Correct
Incorrect
Answer is not “(b) front node”, as we can not get rear from front in O(1), but if p is rear we can implement both enQueue and deQueue in O(1) because from rear we can get front in O(1). Below are sample functions. Note that these functions are just sample are not working. Code to handle base cases is missing. 1

Question 9 of 14
9. Question
1 pointsWhat are the time complexities of finding 8th element from beginning and 8th element from end in a singly linked list? Let n be the number of nodes in linked list, you may assume that n > 8.
Correct
Incorrect
Finding 8th element from beginning requires 8 nodes to be traversed which takes constant time. Finding 8th from end requires the complete list to be traversed.

Question 10 of 14
10. Question
1 pointsIs it possible to create a doubly linked list using only one pointer with every node?
Correct
Incorrect

Question 11 of 14
11. Question
1 pointsGiven 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?
Correct
Incorrect
Following are simple steps.
struct node *temp = X>next;
X>data = temp>data;
X>next = temp>next;
free(temp); 
Question 12 of 14
12. Question
1 pointsYou are given pointers to first and last nodes of a singly linked list, which of the following operations are dependent on the length of the linked list?
Correct
Incorrect
a) Can be done in O(1) time by deleting memory and changing the first pointer.
b) Can be done in O(1) time, see push() here
c) Delete the last element requires pointer to previous of last, which can only be obtained by traversing the list.
d) Can be done in O(1) by changing next of last and then last. 
Question 13 of 14
13. Question
1 pointsConsider the following function to traverse a linked list.
void traverse(struct Node *head) { while (head>next != NULL) { printf("%d ", head>data); head = head>next; } }
Which of the following is FALSE about above function?
Correct
Incorrect

Question 14 of 14
14. Question
1 pointsIn the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is
Correct
Incorrect