In this article we will see how we can make a PyQt5 application which will visualize the Jump search algorithm.
Like Binary Search, Jump Search is a searching algorithm for sorted arrays. The basic idea is to check fewer elements (than linear search) by jumping ahead by fixed steps or skipping some elements in place of searching all elements.
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 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
Algorithm implementation steps :
1. Create label list corresponding to the given numbers.
2. Create variable for the index for jumping index and index of linear search. Also, a counter and flags for linear and jump searching process.
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. If flag is true start the jump search, check for the jump flag if true, start jumping the index.
6. If jump index value is equal to the desired value, make the label green and show the result through label. If index value is greater stop the jumping of index and start the linear search.
7. Check for the index value through linear search, if found show through label, else show result as not found.
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.