Advertisements
Advertisements
प्रश्न
Following is a list of unsorted/unordered numbers:
[50, 31, 21, 28, 72, 41, 73, 93, 68, 43, 45, 78, 5, 17, 97, 71, 69, 61, 88, 75, 99, 44, 55, 9]
- Use linear search to determine the position of 1, 5, 55, and 99 in the list. Also, note the number of key comparisons required to find each of these numbers in the list.
- Use a Python function to sort/arrange the list in ascending order.
- Again, use linear search to determine the position of 1, 5, 55, and 99 in the list and note the number of key comparisons required to find these numbers in the list.
- Use binary search to determine the position of 1, 5, 55, and 99 in the sorted list. Record the number of iterations required in each case.
उत्तर
According to the Linear Search algorithm the position and number of comparisons for the elements are given as:
1: not found in the array and the number of comparisons is 24.
5: position = 13, number of comparisons is 13.
55: position = 23, number of comparisons are 23.
99: position = 21, number of comparisons are 21.
After sorting,
list = [5, 9, 17, 21, 28, 31, 41, 43, 44, 45, 50, 55, 61, 68, 69, 71, 72, 73, 75, 78, 88, 93, 97, 99]
1: not found in the array and the number of comparisons is 24.
5: position = 1, number of comparisons is 1.
55: position = 12, number of comparisons are 12.
99: position = 24, number of comparisons are 24.
By applying Binary Search:
1: not found in the array
5: position = 1
55: position = 12
99: position = 24
APPEARS IN
संबंधित प्रश्न
The most fundamental and simplest search method is known as ______.
How many comparisons of Linear search will be required to search for key = 17 in the list [8,-4,7,17,0,12,56]?
If the key to be searched is the last element in the list, then linear search algorithm will make how many comparisons?
In which of the following scenarios would you prefer to use a Linear search algorithm?
Which is the most preferred technique used for finding a value in a list?
In the given list 1, 2, 3, 5, 6, 4. Given that number 13 is to be searched. In which call will it be known that 13 do not exist. Search is conducted using Linear search.
The biggest disadvantage of a Linear search is that ______.
Linear search is time consuming if applied on big lists.
Linear search works on the principle of divide and rule.
Using linear search determine the position of 8, 1, 99 and 44 in the list:
[1, -2, 32, 8, 17, 19, 42, 13, 0, 44]
Draw a detailed table showing the values of the variables and the decisions taken in each pass of linear search.
Use the linear search program to search the key with value 8 in the list having duplicate values such as [42, -2, 32, 8, 17, 19, 42, 13, 8, 44]. What is the position returned? What does this mean?
Write a program that takes as input a list having a mix of 10 negative and positive numbers and a key value. Apply linear search to find whether the key is present in the list or not. If the key is present it should display the position of the key in the list otherwise it should print an appropriate message. Run the program for at least 3 different keys and note the result.
Write a program that takes as input the following unsorted list of English words:
[Perfect, Stupendous, Wondrous, Gorgeous, Awesome, Mirthful, Fabulous, Splendid, Incredible, Outstanding, Propitious, Remarkable, Stellar, Unbelievable, Super, Amazing].
- Use linear search to find the position of Amazing, Perfect, Great, and Wondrous in the list. Also, note the number of key comparisons required to find these words in the list.
- Use a Python function to sort the list.
- Again, use linear search to determine the position of Amazing, Perfect, Great, and Wondrous in the list and note the number of key comparisons required to find these words in the list.
- Use binary search to determine the position of Amazing, Perfect, Great, and Wondrous in the sorted list. Record the number of iterations required in each case.