Q.1
Consider the following iterative implementation used to find the length of a linked list: struct Node { int val; struct Node *next; }*head; int get_len() { struct Node *temp = head->next; int len = while(_____) { len++; temp = temp->next; } return len; }
  • a) temp->next != 0
  • b) temp == 0
  • c) temp != 0
  • d) temp->next == 0
Q.2
What is the output of the following code? #include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node *next; }*head; int get_len() { struct Node *temp = head->next; int len = while(temp != { len++; temp = temp->next; } return len; } int main() { int arr[= {1,2,3,4,5}, n =i; struct Node *temp, *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = temp = head; for(i=i<n; i++) { newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->val = arr[i]; newNode->next = temp->next = newNode; temp = temp->next; } int len = get_len(); printf("%d",len); return}
  • a) 4
  • b) 5
  • c) 6
  • d) 7
Q.3
What is the time complexity of the following iterative implementation used to find the length of a linked list? #include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node *next; }*head; int get_len() { struct Node *temp = head->next; int len = while(temp != { len++; temp = temp->next; } return len; } int main() { int arr[= {1,2,3,4,5}, n =i; struct Node *temp, *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = temp = head; for(i=i<n; i++) { newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->val = arr[i]; newNode->next = temp->next = newNode; temp = temp->next; } int len = get_len(); printf("%d",len); return}
  • a) O(1)
  • b) O(n)
  • c) O(n2)
  • d) O(logn)
Q.4
What is the output of the following code? #include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node *next; }*head; int get_len() { struct Node *temp = head->next; int len = while(temp != { len++; temp = temp->next; } return len; } int main() { int arr[= {1,2,3,4,5}, n =i; struct Node *temp, *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = int len = get_len(); printf("%d",len); return}
  • a) 0
  • b) Garbage value
  • c) Compile time error
  • d) Runtime error
Q.5
Which of the following can be the base case for the recursive implementation used to find the length of linked list? #include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node *next; }*head; int get_len() { struct Node *temp = head->next; int len = while(temp != { len++; temp = temp->next; } return len; } int main() { int arr[= {1,2,3,4,5}, n =i; struct Node *temp, *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = int len = get_len(); printf("%d",len); return}
  • a) if(current_node == 0) return 1
  • b) if(current_node->next == 0) return 1
  • c) if(current_node->next == 0) return 0
  • d) if(current_node == 0) return 0
Q.6
Which of the following lines should be inserted to complete the following recursive implementation used to find the length of a linked list? #include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node *next; }*head; int recursive_get_len(struct Node *current_node) { if(current_node == return return _____; } int main() { int arr[= {1,2,3,4,5}, n =i; struct Node *temp, *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = temp = head; for(i=i<n; i++) { newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->val = arr[i]; newNode->next = temp->next = newNode; temp = temp->next; } int len = recursive_get_len(head->next); printf("%d",len); return}
  • a) recursive_get_len(current_node)
  • b) 1 + recursive_get_len(current_node)
  • c) recursive_get_len(current_node->next)
  • d) 1 + recursive_get_len(current_node->next)
Q.7
What is the output of the following code? #include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node *next; }*head; int recursive_get_len(struct Node *current_node) { if(current_node == return return 1 + recursive_get_len(current_node->next); } int main() { int arr[= {-1,2,3,-3,4,5,0}, n =i; struct Node *temp, *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = temp = head; for(i=i<n; i++) { newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->val = arr[i]; newNode->next = temp->next = newNode; temp = temp->next; } int len = recursive_get_len(head->next); printf("%d",len); return}
  • a) 6
  • b) 7
  • c) 8
  • d) 9
Q.8
What is the time complexity of the following code used to find the length of a linked list? #include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node *next; }*head; int recursive_get_len(struct Node *current_node) { if(current_node == return return 1 + recursive_get_len(current_node->next); } int main() { int arr[= {-1,2,3,-3,4,5,0}, n =i; struct Node *temp, *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = temp = head; for(i=i<n; i++) { newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->val = arr[i]; newNode->next = temp->next = newNode; temp = temp->next; } int len = recursive_get_len(head->next); printf("%d",len); return}
  • a) O(1)
  • b) O(n)
  • c) O(n2)
  • d) O(n3)
Q.9
What is the output of the following code? #include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node *next; }*head; int recursive_get_len(struct Node *current_node) { if(current_node == return return 1 + recursive_get_len(current_node->next); } int main() { int arr[= {-1,2,3,-3,4,5}, n =i; struct Node *temp, *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = temp = head; for(i=i<n; i++) { newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->val = arr[i]; newNode->next = temp->next = newNode; temp = temp->next; } int len = recursive_get_len(head->next); printf("%d",len); return}
  • a) 5
  • b) 6
  • c) 7
  • d) 8
Q.10
How many times is the function recursive_get_len() called when the following code is executed? #include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node *next; }*head; int recursive_get_len(struct Node *current_node) { if(current_node == return return 1 + recursive_get_len(current_node->next); } int main() { int arr[= {-1,2,3,-3,4,5}, n =i; struct Node *temp, *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = temp = head; for(i=i<n; i++) { newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->val = arr[i]; newNode->next = temp->next = newNode; temp = temp->next; } int len = recursive_get_len(head->next); printf("%d",len); return}
  • a) 5
  • b) 6
  • c) 7
  • d) 8
0 h : 0 m : 1 s