Package: python-pypeline
PypelineThis is a python library for easy implementation of Data Structures and Algorithms. In future iterations, this library will include plugins for Data Analysis and Machine Learning, specifically for data collection and manipulation.Future WorkOn the next iteration of Pypeline, we will release a method to pass Python Data Structures to files for seamless integration with R graphing plugins.InstallationInstall Pypeline v1.0.1 usingpip:$pipinstallpython-pypelineIf version installed is <= v1.0.1 then you need to upgrade to the latest version of Pypeline:$pipinstallpython-pypeline--upgradeTo test install, run the following line of code:>>>importPypelineDevelopmentRun all scripts from within thePypelinefolder as follows:$./scripts/run_tests.shData Structures ImplementedAVL TreeBinary Search TreeMax HeapMin HeapNodeLinked ListQueueStackTrieTernary Search TreeSample ImplementationsAVL TreefromPypeline.Pypes.AVLTreeimportAVL# Instantiate AVL Treeavl=AVL()# Add Nodes to the Tree; the tree will automatically balance itselfforiinrange(10):avl.insert(i)# Display the AVL Tree using an In Order Traversalavl.traverse()# will display numbers 1 - 10# Remove nodes from the Treeavl.remove(5)Binary Search TreefromPypeline.Pypes.BinarySearchTreeimportBST# Instantiate Binary Search Treebst=BST()# Add Nodes to the Tree; the tree will NOT balance itselfforiinrange(10):bst.insert(i)# Get size of the Treebst_size=bst.getSize()# Display the BST using an In Order Traversal; can also use preOrderTraversal and postOrderTraversalbst.inOrderTraversal()# will display numbers 1 - 10# Remove nodes from the Treebst.remove(5)# Get min value and max valuebst_min,bst_max=bst.getMinValue(),bst.getMaxValue()Max HeapfromPypeline.Pypes.MaxHeapimportMaxHeap# Instantiate the Max Heap; the list can be passed in on instantiation or with a builtin methodmaxheap=MaxHeap()# Convert list to MaxHeapmaxheap.heapify([2,4,10,8])# Merge heap with another listmaxheap.merge([1,5,3,7])# Pop largest value from the heap_=maxheap.heappop()# Insert value (type int or float) into the Heapmaxheap.heappush(20)# Convert heap into numpy arraynp_maxheap=maxheap.to_array()# Print the Max Heap Contents; Currently the Data Structure is not iterableprint(maxheap)Min HeapfromPypeline.Pypes.MinHeapimportMinHeap# Instantiate the Min Heap; the list can be passed in on instantiation or with a builtin methodminheap=MinHeap()# Convert list to MinHeapminheap.heapify([2,4,10,8])# Merge heap with another listminheap.merge([1,5,3,7])# Pop smallest value from the heap_=minheap.heappop()# Insert value (type int or float) into the Heapminheap.heappush(20)# Convert heap into numpy arraynp_minheap=minheap.to_array()# Print the Min Heap Contents; Currently the Data Structure is not iterableprint(minheap)NodefromPypeline.Pypes.NodeimportNode# Instantiation; However, this is meant to be a super class not a stand alone objectnode=Node()# Set Node value; This can be passed into object instantiation as wellnode.setVal(10)# Get value of the Node_=node.getVal()# Set/Swap Visisted (if needed); default is falsenode.setVisited()# visted -> truenode.swapVisited()# visited -> false# Check if Node is Visited_=node.isVisited()Linked ListfromPypeline.Pypes.LinkedListimportLinkedList# Instantiationlinked=LinkedList()# Insert Value to list (dtype -> any); T.C -> O(1)foriinrange(10):linked.insert(i)# Delete node from the linkedlist T.C -> O(N)linked.remove(5)# Get Size of the linkedlist_=linked.getSize()# Traverse List: print all values in linkedlist; T.C -> O(N)linked.traverseList()# Convert linkedlist to numpy array; returns the converted arraynplinked=linked.to_array()# Convert linkedlist to python list; return the converted listregular_list=linked.to_list()# Can print linked list and it will display the corresponding python listprint(linked)QueuefromPypeline.Pypes.QueueimportQueue# Instantiation of Queue; maxlen property specifies largest size for arrayqueue=Queue(maxlen=1e9)# Enqueue data to the queueforiinrange(10):queue.enqueue(i)# Dequeue data from the queue; FIFO_=queue.dequeue()# Peek the front of the queue; returns the value without removingfront=queue.peek()# Get the size of the queuesize=queue.sizeQueue()# Check if queue is empty; returns -> type bool_=queue.isEmpty()# Convert queue to numpy arraynpqueue=queue.to_array()# Convert queue to python listlist_queue=queue.to_list()StackfromPypeline.Pypes.StackimportStack# Instantiation of Stack; maxlen property specifies largest size for arraystack=Stack(maxlen=1e9)# Enqueue data to the stackforiinrange(10):stack.push(i)# Dequeue data from the stack; LIFO_=stack.pop()# Peek the top of the stack; returns the value without removingfront=stack.peek()# Get the size of the queuesize=stack.sizeStack()# Check if stack is empty; returns -> type bool_=stack.isEmpty()# Convert stack to numpy arraynpstack=stack.to_array()# Convert queue to python listlist_stack=stack.to_list()TriefromPypeline.Pypes.TrieimportTrie# Instantiationtree=Trie()# Insert word into the treetree.insert('word')tree.insert('data structure')# Search for a word in the tree_=tree.search('word')# -> returns true if word in tree_=tree.search('data')# -> returns false if word not in treeTernary Search TreefromPypeline.Pypes.TernarySearchTreeimportTST# Instantiationtst=TST()# Put Key and value into the treetst.put("cat",5)tst.put("dog",10)# Get the value from the key of the tree_=tst.get('cat')# -> returns 5_=tst.get("bird")# -> returns -1 if key not in tree