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.
Explanation
This program demonstrates the difference between linear search and binary search. In part (a), linear search on unsorted list requires up to N comparisons. After sorting in part (b), linear search in part (c) shows varying comparisons based on position. Binary search in part (d) shows significantly fewer iterations (log₂N) compared to linear search, demonstrating its efficiency for sorted data.