**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?

temp->next != 0 | |

temp == 0 | |

temp != 0 | |

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

4 | |

5 | |

6 | |

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?

O(1) | |

O(n) | |

O(n ^{2}) | |

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

0 | |

Garbage value | |

Compile time error | |

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?

if(current....node == 0) return 1 | |

if(current....node->next == 0) return 1 | |

if(current....node->next == 0) return 0 | |

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.

There are 5 questions to complete.