Data Structure Questions and Answers-Largest and Smallest Number in a Linked List using Recursion

DOWNLOAD FREE PDF <<CLICK HERE>>

Data Structure Questions and Answers-Largest and Smallest Number in a Linked List using Recursion

Congratulations - you have completed Data Structure Questions and Answers-Largest and Smallest Number in 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]
Which of the following methods can be used to find the largest and smallest number in a linked list?
A
Recursion
B
Iteration
C
Both Recursion and iteration
D
None of the mentioned
Question 1 Explanation: 
Both recursion and iteration can be used to find the largest and smallest number in a linked list.

Question 2 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
Consider the following code snippet to find the largest element in a linked list:

struct Node{ int val; struct Node *next; }*head; int get....max() { struct Node* temp = head->next; 	 int max....num = temp->val; 	 while(.....) 	 { 	 if(temp->val > max....num) 		 max....num = temp->val; 		temp = temp->next; 	 } 	 return max....num; }

Which of the following lines should be inserted to complete the above code?

A
temp->next != 0
B
temp != 0
C
head->next != 0
D
head != 0
Question 2 Explanation: 
The line "temp != 0" should be inserted to complete the above code.

Question 3 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
Consider the following code snippet to find the smallest element in a linked list:

struct Node { int val; struct Node* next; }*head; int get....min() { struct Node* temp = head->next; 	 int min....num = temp->val; 	 while(temp != 0) 	 { 	 if(.....) 		 min....num = temp->val; 		temp = temp->next; 	 } 	 return min....num; }

Which of the following lines should be inserted to complete the above code?

A
temp > min....num
B
val > min....min
C
temp->val < min....num
D
temp->val > min....num
Question 3 Explanation: 
The line "temp->val = min....num" should be inserted to complete the above code.

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....max() { struct Node* temp = head->next; 	 int max....num = temp->val; 	 while(temp != 0) 	 { 	 if(temp->val > max....num) 		 max....num = temp->val; 		temp = head->next; 	 } 	 return max....num; } int main() { int n = 9,  arr[9] ={5, 1, 3, 4, 5, 2, 3, 3, 1}, 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->next = 0; newNode->val = arr[i]; temp->next =newNode; temp = temp->next; } int max....num = get....max(); printf("%d %d", max....num); return 0; }
A
5
B
1
C
runtime error
D
garbage value
Question 4 Explanation: 
The variable temp will always point to the first element in the linked list due to the line "temp = head->next" in the while loop. So, it will be an infinite while loop and the program will produce a runtime error.

Question 5 [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....max() { struct Node* temp = head->next; 	 int max....num = temp->val; 	 while(temp != 0) 	 { 	 if(temp->val > max....num) 		 max....num = temp->val; 		temp = temp->next; 	 } 	 return max....num; } int get....min() { struct Node* temp = head->next; 	 int min....num = temp->val; 	 while(temp != 0) 	 { 	 if(temp->val < min....num) 		 min....num = temp->val; 		temp = temp->next; 	 } 	 return min....num; } int main() { int i,  n = 9,  arr[9] ={8, 3, 3, 4, 5, 2, 5, 6, 7}; 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->next = 0; newNode->val = arr[i]; temp->next =newNode; temp = temp->next; } int max....num = get....max(); int min....num = get....min(); printf("%d %d", max....num, min....num); return 0; }
A
2 2
B
8 8
C
2 8
D
8 2
Question 5 Explanation: 
The program prints the largest and smallest elements in the linked list, which are 8 and 2 respectively.

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.

DOWNLOAD FREE PDF <<CLICK HERE>>