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; }
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}
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}
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}
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}
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}
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}
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}
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}
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}