Data Structure Questions and Answers-Length of a Linked List using Recursion

DOWNLOAD FREE PDF <<CLICK HERE>>

Data Structure Questions and Answers-Length of a Linked List using Recursion

Congratulations - you have completed Data Structure Questions and Answers-Length of a Linked List using Recursion.

You scored %%SCORE%% out of %%TOTAL%%.

Your performance has been rated as %%RATING%%


Your answers are highlighted below.
Question 1 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
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 = 0; while(.....) { len++; temp = temp->next; } return len; }

Which of the following conditions should be checked to complete the above code?

A
temp->next != 0
B
temp == 0
C
temp != 0
D
none of the mentioned
Question 1 Explanation: 
The condition "temp != 0" should be checked to complete the above code.

Question 2 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
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 = 0; while(temp != 0) { len++; temp = temp->next; } return len; } int main() { int arr[10] = {1, 2, 3, 4, 5},  n = 5,  i; struct Node *temp,  *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = 0; temp = head; for(i=0; i<n; i++) { newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->val = arr[i]; newNode->next = 0; temp->next = newNode; temp = temp->next; } int len = get....len(); printf("%d", len); return 0; }
A
4
B
5
C
6
D
7
Question 2 Explanation: 
The program prints the length of the linked list, which is 5.

Question 3 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What is the time complexity of the above iterative implementation used to find the length of a linked list?
A
O(1)
B
O(n)
C
O(n2)
D
O(logn)
Question 3 Explanation: 
The time complexity of the above iterative implementation used to find the length of a linked list is O(n).

Question 4 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
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 = 0; while(temp != 0) { len++; temp = temp->next; } return len; } int main() { int arr[10] = {1, 2, 3, 4, 5},  n = 5,  i; struct Node *temp,  *newNode; head = (struct Node*)malloc(sizeof(struct Node)); head->next = 0; int len = get....len(); printf("%d", len); return 0; }
A
0
B
Garbage value
C
Compile time error
D
Runtime error
Question 4 Explanation: 
The program prints the length of the linked list, which is 0.

Question 5 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
Which of the following can be the base case for the recursive implementation used to find the length of linked list?
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
Question 5 Explanation: 
The line "if(current....node == 0) return 0" can be used as a base case in the recursive implementation used to find the length of a linked list. Note: The line "if(current....node->next == 0) return 1" cannot be used because it won't work when the length of the linked list is zero.

Once you are finished, click the button below. Any items you have not completed will be marked incorrect. Get Results
There are 5 questions to complete.