Skip to content

codebinge/Data-Structures

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data-Structures Build Status Coverage Status

Implementation of simple data structures in Python.


Linked List

A singly linked list is made of nodes which contain a reference (or pointer) to the next node in the list and data. They are one of the simpliest data structures and can be used to implement other abstract data types including lists, stacks, queues etc.

linked list

Advatange of a Linked list is a dynamic data structure which can grow while program is running (unlike arrays). Insertion and deletion methods are easy to implement, and it is a simple building block for other more complex data structures.

The disadvantages of using a linked list is they use more memory than an array. Nodes must be read in order from the head to the tail (sequential access). Hard to reverse traverse a single linked list.

The list implementation supports the following methods:

Method Description Time Complexity
push(val) insert the value ‘val’ at the head of the list. O(1)
pop() removes the first value off the head of the list and return it O(1)
size() return the length of the list O(1)
search(val) return the node containing ‘val’ in the list, if present, else None O(n)
remove(node) remove the given node from the list, wherever it might be (node must be an item in the list) O(n)
display() return a unicode string representing the list as if it were a Python tuple literal: “(12, ‘sam’, 37, ‘tango’)” O(n)

Stack

A stack is a collection of nodes with operations occuring at one end only. It behaves like a real-world stack or pile of books - books can only be taken from or placed on the top of the pile in a First In Last Out (LIFO) operations.

stack

Stacks are handy for remembering state eg undo and redo

The Stack implementation supports the following methods:

Method Description Time Complexity
push(val) insert the value ‘val’ at the head of the stack. O(1)
pop() removes the first value off the head of the stack and return it O(1)

About

Implementation of simple data structures in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%