Some "hello world"-style data structure objects. Helps with inane tech interview questions and/or teaching computer science - whichever comes first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Charles Reid 2239877924 add deque example in Python 5 years ago
..
BinaryTree.py expanding on python binary tree class. 5 years ago
LList1.py Update Python linked list to use __str__ 5 years ago
README.md add deque example in Python 5 years ago
UseDeque.py add deque example in Python 5 years ago
Zoo.py updating zoo of Python containers 5 years ago

README.md

Python Data Structures

Python Linked List

Python Binary Tree

Binary Tree class:

  • Fields
    • root - points to the root node of the tree
  • Constructors
    • initialize with a root node, or without a root node

Binary Tree Node class:

  • Fields
    • data - stores the data for this node
    • left - points to left child
    • right - points to right child
  • Constructors
    • initialize with data (left and right are null pointers)
    • initialize with data, left, and right

Key functionality:

  • Insert
    • Add new node to a leaf node (specify which child it should be)
    • Add new node to an internal node (speicfy which child it should be)
  • Delete
    • Delete a node with one child
    • Delete an internal node with multiple
  • Traversal
    • Depth first (recursive)
    • Breadth first (queue)
  • Duplicate removal
  • Properties
    • Count number of nodes
    • Count levels in tree
    • Check if full or proper tree (each node has 0 or 2 children)
    • Check if perfect tree (proper tree, and all leaves have same depth or level)
    • Check if complete tree (every level, except possibly last, are full)

Python Binary Array Tree

Array implementation of the binary tree, in lieu of the Node plus pointer concept.

This is kind of like the way we do it in Perl.

Zoo

The zoo exhibits basic behaviors of some built-in collection types in Python. Why roll your own when you can use a standard library?

UseDeque

This script shows the use of a deque (double-ended queue) to pop items front-to-back or back-to-front, switching direction occasionally.