Choose The Code Snippet Which Uses Recursion For Linear Search #451
Choose the code snippet which uses recursion for linear search.
This multiple choice question (MCQ) is related to the book/course gs gs122 Data Communication and Computer Network. It can also be found in gs gs122 Searching - Linear Search Iterative - Quiz No.1.
Choose the code snippet which uses recursion for linear search.
public void linSearch(int[] arr, int first, int last, int key) { if(first == last) { System.out.print("-1"); } else { if(arr[first] == key) { System.out.print(first); } else { linSearch(arr, first+1, last, key); } } }
public void linSearch(int[] arr, int first, int last, int key) { if(first == last) { System.out.print("-1"); } else { if(arr[first] == key) { System.out.print(first); } else { linSearch(arr, first+1, last-1, key); } } }
public void linSearch(int[] arr, int first, int last, int key) { if(first == last) { System.out.print("-1"); } else { if(arr[first] == key) { System.out.print(last); } else { linSearch(arr, first+1, last, key); } } }
public void linSearch(int[] arr, int first, int last, int key) { if(first == last) { System.out.print("-1"); } else { if(arr[first] == key) { System.out.print(first); } else { linSearch(arr, first+1, last+1, key); } } }
Similar question(s) are as followings:
Online Quizzes of gs122 Data Communication and Computer Network
Sorting - Insertion Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.3
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - LSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes