Sub Set Search Visualizer using PyQt5
In this article we will see how we can make a PyQt5 application which will visualize the subset search algorithm.
Sub Set Search : Sometimes we encounter the problem of checking if one list is just an extension of the list i.e just a superset of one list. This kind of problems are quite popular in competitive programming.
Input: list = [1, 2, 3, 4, 5, 6, 7], sub-list = [2, 4, 7]
Output : List Found
Input: list = [1, 2, 3, 4, 5, 6, 7], sub-list = [5, 1, 7]
Output : List Found
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
Back end implementation steps :
1. Create label list corresponding to the given numbers
2. Create variable for the list index and sub-list 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 and a counter to count number of matches
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 perfect sub-list search algorithm
6. Check for the first element of sub-list with first element of the list if found increment sub-list index, increment counter and reset the index of list else increment list index
7. If the index becomes equal to the list length stop the search and show result as not found.
8. If counter becomes equal to the length of the sub-list show result as 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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course