InterviewSolution
Saved Bookmarks
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
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» None | |
| 2. |
You 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?(A) Delete the first element(B) Insert a new element as a first element(C) Delete the last element of the list(D) Add a new element at the end of the list |
| Answer» | |
| 3. |
Is it possible to create a doubly linked list using only one pointer with every node.(A) Not Possible(B) Yes, possible by storing XOR of addresses of previous and next nodes.(C) Yes, possible by storing XOR of current node and next node(D) Yes, possible by storing XOR of current node and previous node |
| Answer» | |
| 4. |
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 is not last node. Use following two steps (a) Copy the data of next of X to X. (b) Delete next of X.(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. Use following two steps (a) Copy the data of next of X to X. (b) Delete next of X. |
| Answer» None | |
| 5. |
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» | |
| 6. |
In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is (GATE CS 2002)(A) log 2 n(B) n/2(C) log 2 n – 1(D) n |
| Answer» | |
| 7. |
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» | |
| 8. |
Consider 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 (GATE CS 2003)(A) not all elements in the list have the same data value.(B) the elements in the list are sorted in non-decreasing order of data value(C) the elements in the list are sorted in non-increasing order of data value(D) None of them |
| Answer» | |
| 9. |
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 |
| Answer» | |