Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

KLU- CLUSTER -6 DAY-7

Total questions: 30

Worksheet time: 30mins

Name
Class
Date
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
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)
None of these
3.
What is the time complexity to count the number of elements in the linked list?
a)
O(1)
b)
O(n)
c)
O(logn)
d)
None of the mentioned
4.
What would be the asymptotic time complexity to add a node at the end of singly linked list, if the pointer is initially pointing to the head of the list?
a)
O(1)
b)
O(n)
c)
θ (n)
d)
θ (1)
5.
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
6.
What is the functionality of the following piece of code? public int function(int data) { Node temp = head; int var = 0; while(temp != null) { if(temp.getData() == data) { return var; } var = var+1; temp = temp.getNext(); } return Integer.MIN_VALUE; }
a)
Find and delete a given element in the list
b)
Find and return the given element in the list
c)
Find and return the position of the given element in the list
d)
Find and insert a new element in the list
7.
Linked lists are not suitable to for the implementation of?
a)
Insertion sort
b)
Radix sort
c)
Polynomial manipulation
d)
Binary search
8.
In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is
a)
log 2 n
b)
n/2
c)
log 2 n – 1
d)
n
9.
Which of these is an application of linked lists?
a)
To implement file systems
b)
For separate chaining in hash-tables
c)
To implement non-binary trees
d)
All of the mentioned
10.
In circular linked list, insertion of node requires modification of?
a)
One pointer
b)
Two pointer
c)
Three pointer
d)
None
11.
Consider an implementation of unsorted singly linked list. Suppose it has its representation with a head pointer only. Given the representation, which of the following operation can be implemented in O(1) time? i) Insertion at the front of the linked list ii) Insertion at the end of the linked list iii) Deletion of the front node of the linked list iv) Deletion of the last node of the linked list
a)
I and II
b)
I and III
c)
I, II and III
d)
I, II and IV
12.
In linked list each node contain 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
13.
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 of the mentioned
14.
The concatenation of two list can performed in O(1) time. Which of the following variation of linked list can be used?
a)
Singly linked list
b)
Doubly linked list
c)
Circular doubly linked list
d)
Array implementation of list
15.
Consider the following definition in c programming language.Which of the following c code is used to create new node? struct node { int data; struct node * next; } typedef struct node NODE; NODE *ptr;
a)
ptr = (NODE*)malloc(sizeof(NODE));
b)
ptr = (NODE*)malloc(NODE);
c)
ptr = (NODE*)malloc(sizeof(NODE*));
d)
ptr = (NODE)malloc(sizeof(NODE));
16.
What kind of linked list is best to answer question 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
17.
Linked lists are not suitable to for the implementation of?
a)
Insertion sort
b)
Radix sort
c)
Polynomial manipulation
d)
Binary search
18.
Linked list is considered as an example of ___________ type of memory allocation.
a)
Dynamic
b)
Static
c)
Compile time
d)
None of the mentioned
19.
In Linked List implementation, a node carries information regarding
a)
Data
b)
Link
c)
Data and Link
d)
None of the mentioned
20.
Linked list data structure offers considerable saving in
a)
Computational Time
b)
Space Utilization
c)
Space Utilization and Computational Time
d)
None of the mentioned
21.
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 mentioned
22.
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
23.
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
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
24.
The following function reverse() is supposed to reverse a singly linked list. There is one line missing at the end of the function.What should be added in place of "/*ADD A STATEMENT HERE*/", so that the function correctly reverses a linked list. struct node { int data; struct node* next; }; static void reverse(struct node** head_ref) { struct node* prev = NULL; struct node* current = *head_ref; struct node* next; while (current != NULL) { next = current->next; current->next = prev; current = next; } /*ADD A STATEMENT HERE*/ }
a)
*head_ref = prev;
b)
*head_ref = current;
c)
*head_ref = next;
d)
*head_ref = NULL;
25.
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
26.
What is the functionality of the following code? public void function(Node node) { if(size == 0) head = node; else { Node temp,cur; for(cur = head; (temp = cur.getNext())!=null; cur = temp); cur.setNext(node); } size++; }
a)
Inserting a node at the beginning of the list
b)
Deleting a node at the beginning of the list
c)
Inserting a node at the end of the list
d)
Deleting a node at the end of the list
27.
The following function reverse() is supposed to reverse a singly linked list. There is one line missing at the end of the function. /* Link list node */ struct node { int data; struct node* next; }; /* head_ref is a double pointer which points to head (or start) pointer of linked list */ static void reverse(struct node** head_ref) { struct node* prev = NULL; struct node* current = *head_ref; struct node* next; while (current != NULL) { next = current->next; current->next = prev; prev = current; current = next; } /*ADD A STATEMENT HERE*/ } What should be added in place of “/*ADD A STATEMENT HERE*/”, so that the function correctly reverses a linked list.
a)
*head_ref = prev;
b)
*head_ref = current;
c)
*head_ref = next;
d)
*head_ref = NULL;
28.
The following C function takes a simply-linked list as an 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;
29.
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
30.
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