Interpolation Search visualizer using PyQt5
In this article we will see how we can make a PyQt5 application which will visualize the interpolation search algorithm.
The Interpolation Search is an improvement over Binary Search for instances, where the values in a sorted array are uniformly distributed. Binary Search always goes to the middle element to check. On the other hand, interpolation search may go to different locations according to the value of the key being searched. For example, if the value of the key is closer to the last element, the interpolation search is likely to start search toward the end side.
GUI implementation steps :
1. Create a list of label according to the given list of numbers
2. Set their text, border, color and geometry with a respective gap from each other
3. Each label height should be proportional to the value of each number
4. Create a start and pause push button to start the searching and pause the searching
5. Create a result label to show the searching status
Back end implementation steps :
1. Create label list corresponding to the given numbers
2. Create variable for the lower higher and position index and flag for searching
3. Add action to the push button their action should change the flag status i.e start action should make flag true and pause action should make flag false.
4. Create timer object which calls a method after every specific time
5. Inside the timer method check for the flag is flag is true begin the interpolation search algorithm
6. Check if value lies within the range if not show output as not found else continue
7. If the index of lower index is greater then higher index stop the search and show result as not found
8. Calculate the position index through the interpolation search formula
9. Check if the desired value is at position index if matches show result as found
10. If desired value is not equal then update the lower and higher index according to the desired value.
Below is the implementation
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course