Data Structure Questions and Answers-Search an Element in a Linked List using Recursion

 

 Help authour, Buy PDF Ebook   >>>Click Here<<<

Data Structure Questions and Answers-Search an Element in a Linked List using Recursion

Click on any option to know the CORRECT ANSWERS

Question 1
Which of the following methods can be used to search an element in a linked list?
A
Iterative linear search
B
Iterative binary search
C
Recursive binary search
D
All of the mentioned
Data interpretation (DI) Questions answers

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

A
temp = next
B
temp->next = temp
C
temp = temp->next
D
return 0
Aptitude test Questions answers

Question 2 Explanation: 
The line "temp = temp->next" should be inserted to complete the above code.

Question 3
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; }
A
Finds the index of the first occurrence of a number in a linked list
B
Finds the index of the last occurrence of a number in a linked list
C
Checks if a number is present in a linked list
D
None of the mentioned
Bank exam Questions answers

Question 3 Explanation: 
The above code checks if a number is present in a linked list.

Question 4
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; }
A
Found
B
Not found
C
Compile time error
D
Runtime error
Arab culture Questions answers

Question 4 Explanation: 
Since the number -1 is not present in the linked list, the program prints not found.

Question 5
What is the time complexity of the above implementation of linear search on a linked list?
A
O(1)
B
O(n)
C
O(n2)
D
O(n3)
UPSC GS Questions answers

Question 5 Explanation: 
The time complexity of the above implementation of linear search on a linked list is O(n).

There are 5 questions to complete.

 

 Download all FREE PDF Ebook >>>CLICK HERE<<<