Path: blob/master/python/algorithms/basic_data_structure.ipynb
1480 views
Basic Data Structure
Following the online book, Problem Solving with Algorithms and Data Structures. Chapter 4 works through basic data structures and some of its use cases.
Stack
Write a function rev_string(mystr) that uses a stack to reverse the characters in a string.
Check for balance parenthesis.
Convert numbers into binary representation.
Convert operators from infix to postfix.
Queue
From Python Documentation: Using Lists as Queues
Although the queue functionality can be implemented using a list, it is not efficient for this purpose. Because doing inserts or pops from the beginning of a list is slow (all of the other elements have to be shifted by one).
We instead use deque
. It is designed to have fast appends and pops from both ends.
Implement the palindrome checker to check if a given word is a palindrom. A palindrome is a string that reads the same forward and backward, e.g. radar.
Unordered (Linked)List
Ordered (Linked)List
As the name suggests, compared to unordered linkedlist, the elements will always be ordered for a ordered linked list. The is_empty
and size
method are exactly the same as the unordered linkedlist as they don't have anything to do with the actual item in the list.
Python's list is actually based on the notion of array list instead of the linked list in this section.