DS - Exit - Exam - LinkedList

You might also like

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

Linked List

1. Which data structure consists of a sequence of nodes where each node contains a reference to the next
node?
a) Stack b) Queue c) Linked list d) Array
2. What is the time complexity for inserting a node at the beginning of a linked list?
a) O(1) b) O(log n) c) O(n) d) O(n^2)
3. The following C code searches for a value (key) in a doubly linked list. Assuming we have initialized the
linked list and temp is a struct type pointer. Answer the questions shown as numbers 1, 2 and 3
inside the code.
What code is correct in place of 1?
a) temp->info b)temp!=null c) temp->next d) none of the above
struct node{
struct node *prev;
int info;
struct node *next;
};
void search(){
int key, count = 0;
struct node *temp;
if (temp == NULL){
printf("List is empty.");
return;
}
printf("Enter value to search : ");
scanf("%d", &key);
while (______1_______){
if (______2_____ == key){
printf("key found in %d position",count+1);
return;
}
else
temp = temp->____3____];
count++; }
printf("Error : %d not found in the list.", key);
}

4. Based on question number 43, what code is correct in place of 2?


a) temp->info b)temp!=null c) temp->next d) none of the above
5. Based on question number 43, what code is correct in place of 3?
A) temp->info b)temp!=null c) temp->next d) next
6. What is the maximum number of elements that can be stored in an empty linked list?
a) 0 b) 1 c) 10 d) Unlimited
7. Which of the following statements about a circular linked list is true?
a) It is as same as circular doubly linked list.
b) It can only be traversed in one direction.
c) It is more efficient to access the last node than a singly linked list.
d) It can be used to implement a stack.
e) All are correct.
8. What name do you suggest to the following function with respect to linked list?
struct Node {
int data;
struct Node* next;
};

void Function(struct Node** head, int data) {


struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = NULL;

if (*head == NULL) {
*head = newNode;
} else {
struct Node* current = *head;
while (current->next != NULL) {
current = current->next;
}
current->next = newNode;
}
}
a) InsertingAtBeginning b) InsertionAtTheEnd c) InsertionInTheMiddle d) all

9. Which of the following data structures can be implemented using a linked list?
a) Stack b) Queue c) Binary tree d) All of the above
10. Which operation allows you to access the value of a node in a linked list?
a) Insert b) Delete c) Search d) Traverse
11. Which of the following is not an advantage of using a linked list?
a) Dynamic size
b) Efficient random access
c) Easy insertion and deletion
d) Memory efficiency
12. What is the polynomial representation f(x) of the polynomial linked list representation given below.

a) f(x) = mx3+nx4+kx2+px+q
b) f(x) = mx4+nx3+kx2+px+qx10
c) f(x) = mx4+nx3+kx2+px+0
d) f(x) = mx4+nx3+kx2+px+q
13. Which data structure allows access to elements in a sequential order?
a) Stack
b) Queue
c) Linked list
d) Tree
14. In a circular linked list, which node contains no reference to the next node?
a) First node
b) Last node
c) Middle node
d) None of the above

You might also like