Skip to main content

A library for data structures.

Project description

ProfQ-Data

Usage

You can import the module like any other with:

import profq_data

Then you have access to all kinds of data structures.

For example, a queue:

from profq_sorting import Queue

queue = Queue()

queue.enqueue(1)
queue.enqueue(3)

print(queue.dequeue())
Output: 1

There are many more data structures which I have implemented, but here is a few that may interest you: queue, stack, binary tree and linked list.

Data Structures

Binary Tree

from profq_sorting import BinaryTree

A Binary tree is a data structure in which you can input numbers and it will put them at a certain spot. Every node has a right child and a left child, the idea is that every node that is smaller than the parent, will be on the left and every nod that's bigger, on the right. This implementation has no balancing, so it can be quite ineffecient.

Hash Table

from profq_sorting import HashTable

This data structure uses a hashing function to determine an index in where it should put an item in an array. If the index is the same, however, it will take the node that is already inside the index and add a reference, basically creating a linked list in that spot.

Heap

from profq_sorting import Heap

A heap is kind of like a binary tree, in that it has a tree-like architecture. It is implemented however with an array. It uses some formulas to see what items are parents and children of each other. Also, it ensures that the minimum element is always on top, and when an item gets added, the tree is always filled left to right.

Queue

from profq_sorting import Queue

Queue is a simple data structure, it's almost identical to an actual queue except it's with data in a computer instead of with people. It works according to FIFO (First In First Out), the acronym says it all really. The items that are added first will exit first, like a queue to see a movie. They don't let the people in the back of the line in first, they let the people on the front in first. The data structure is also very similar to a linked list.

Priority Queue

from profq_sorting import PriorityQueue

A priority queue is the same as a queue, instead it just has a priority, every item has a priority and items with the highest priority are the first to go out. My implementation lets you have control over what the priority is decided by.

Stack

from profq_sorting import Stack

Basically the opposite of a queue. It uses the principle LIFO (Last In First Out), and again it says it all. You can imagine a "stack" (see what I did there?) of pancakes. You don't take the bottom one (FIFO), you take the top one (LIFO). This one is also based on the linked list.

Linked List

from profq_sorting import SinglyLinkedList

A the famed linked list, I've talked about it so much because many other data structures use this or the principles of this. It starts with one node, the head, and that node links to another node, that one links to the next and so on and so forth, until you reach the end of the list. This means that, unlike arrays, you can't access every element instantly, you first have to traverse the list. That's a big negative, BUT it can be any length. And maybe Python isn't the greatest programming language to have that in. In other programming languages it can be very easy to make dynamically sized lists.

You may have also noticed the class not being called LinkedList but instead SinglyLinkedList. That's because there are many other linked lists including one doubly linked list and one skip list.

Doubly Linked List

from profq_sorting import DoublyLinkedList

A doubly linked list is the same as a singly linked list except that it has another reference, namely the previous node, meaning you can traverse it both ways. This can be extremely helpful for the history of web pages, because you can go forward AND backward, which you can't do with a normal linked list.

Skip List

from profq_sorting import SkipList

A skip list is the same as a linked list except it has one "express lane" or another linked list. When it wants to insert a node, it uses the express lane to find the node that is before a node that is higher that the one you want to insert and then it traverses the normal linked list. Then it flips a coin to decide whether to add this node to the express lane. Deletion is the same, only it also has to delete the node in the express lane.

Conclusion

I made this package to learn more about data structures and their uses plus now I can say I've published MULTIPLE Python packages (just 2, but still). And I like this way of doing it, because I hope it can help someone who is looking for some implementation of data structures and that they can find this.

I used this playlist from HackerRank a lot, it's really helpful!

GeeksForGeeks also has a lot of videos about data structures (and I mean a LOT).

It has been really fun learning about all these data structures and I highly encourage you to try and implement some for yourself and see where you can use this in your current/future job!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

profq_data-1.0.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

profq_data-1.0.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file profq_data-1.0.0.tar.gz.

File metadata

  • Download URL: profq_data-1.0.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.4

File hashes

Hashes for profq_data-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7fdb8e712af7a387aae499bc95fcc8343d047f1ae202b40e7dd74498812f38cf
MD5 3b34e74f8faf48039fa1a7cca72107dc
BLAKE2b-256 83fbe09cb86e87ddf846588139a5ceea40484cba70b99612da3e48600039879f

See more details on using hashes here.

File details

Details for the file profq_data-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: profq_data-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.4

File hashes

Hashes for profq_data-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a27113bf34c74f7f00683808c0772a4c3f1f84cd8e97243689b6fce12e177c3
MD5 14119bcfc5749fc861efddb9db9646b8
BLAKE2b-256 4aaab0d5af5211e62a0197d0148db3cafd68ac186bfb23c545c5af57a08e5b57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page