Advertisements
Advertisements
Question
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.
Solution
Element 8 is found at position 4 after 4 comparisons.
Element 1 is found at position 1 after 1 comparisons.
Element 99 is not found in the list.
Element 44 is found at position 10.
APPEARS IN
RELATED QUESTIONS
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.
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.
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.
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.