
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Pygorithm Module in Python
The Pygorithm module is an educational module containing the implementation of various algorithms. The best use of this module is to get the code of an algorithm implemented using python. But it can also be used for actual programming where we can apply the various algorithms to a given data set.
Finding the Data Structures
After installing the module in the python environment we can find the various data structures that is present in the package.
Example
from pygorithm import data_structures help(data_structures
Running the above code gives us the following result −
Output
Help on package pygorithm.data_structures in pygorithm: NAME pygorithm.data_structures - Collection of data structure examples PACKAGE CONTENTS graph heap linked_list quadtree queue stack tree trie DATA __all__ = ['graph', 'heap', 'linked_list', 'queue', 'stack', 'tree', '...
Getting Algorithm Code
In the below program we see how to get the code of the algorithm for the Queue data structure.
Example
from pygorithm.data_structures.queue import Queue the_Queue = Queue() print(the_Queue.get_code())
Running the above code gives us the following result −
Output
class Queue(object): """Queue Queue implementation """ def __init__(self, limit=10): """ :param limit: Queue limit size, default @ 10 """ self.queue = [] self.front = None self.rear = None self.limit = limit self.size = 0 ………………………… ………………
Applying a Sort
In the below example we see how to apply a quick sort to given list.
Example
from pygorithm.sorting import quick_sort my_list = [3,9,5,21,2,43,18] sorted_list = quick_sort.sort(my_list) print(sorted_list)
Running the above code gives us the following result −
Output
[2, 3, 5, 9, 18, 21, 43]
Advertisements