DOWNLOAD FREE PDF <<CLICK HERE>>
Data Structure Questions and Answers-Search an Element in a Linked List using Recursion
Congratulations - you have completed Data Structure Questions and Answers-Search an Element 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 search an element in a linked list?
Iterative linear search | |
Iterative binary search | |
Recursive binary search | |
All of the mentioned |
Question 1 Explanation:
Iterative linear search can be used to search an element in a linked list. Binary search can be used only when the list is sorted.
Question 2 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |
Consider the following code snippet to search an element in a linked list:
struct Node { int val; struct Node* next; }*head; int linear....search(int value) { struct Node *temp = head->next; while(temp != 0) { if(temp->val == value) return 1; .....; } return 0; }
Which of the following lines should be inserted to complete the above code?
temp = next | |
temp->next = temp | |
temp = temp->next | |
return 0 |
Question 2 Explanation:
The line "temp = temp->next" should be inserted to complete the above code.
Question 3 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |
What does the following code do?
#include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node* next; }*head; int linear....search(int value) { struct Node *temp = head->next; while(temp != 0) { if(temp->val == value) return 1; temp = temp->next; } return 0; } int main() { int arr[5] = {1, 2, 3, 4, 5}; int n = 5, i; head = (struct Node*)malloc(sizeof(struct Node)); head->next = 0; struct Node *temp; temp = head; for(i=0; i<n; i++) { struct Node *newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->next = 0; newNode->val = arr[i]; temp->next = newNode; temp = temp->next; } int ans = linear....search(60); if(ans == 1) printf("Found"); else printf("Not found"); return 0; }
Finds the index of the first occurrence of a number in a linked list | |
Finds the index of the last occurrence of a number in a linked list | |
Checks if a number is present in a linked list | |
None of the mentioned |
Question 3 Explanation:
The above code checks if a number is present in a linked list.
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 linear....search(int value) { struct Node *temp = head->next; while(temp != 0) { if(temp->val == value) return 1; temp = temp->next; } return 0; } int main() { int arr[5] = {1, 2, 3, 4, 5}; int n = 5, i; head = (struct Node*)malloc(sizeof(struct Node)); head->next = 0; struct Node *temp; temp = head; for(i=0; i<n; i++) { struct Node *newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->next = 0; newNode->val = arr[i]; temp->next = newNode; temp = temp->next; } int ans = linear....search(-1); if(ans == 1) printf("Found"); else printf("Not found"); return 0; }
Found | |
Not found | |
Compile time error | |
Runtime error |
Question 4 Explanation:
Since the number -1 is not present in the linked list, the program prints not found.
Question 5 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |
What is the time complexity of the above implementation of linear search on a linked list?
O(1) | |
O(n) | |
O(n2) | |
O(n3) |
Question 5 Explanation:
The time complexity of the above implementation of linear search on a linked list is O(n).
Once you are finished, click the button below. Any items you have not completed will be marked incorrect.
There are 5 questions to complete.