One more python implementation of a data structure. This is a heap implementation that follows an architecture similar to the binary search tree we have built earlier. from collections import Container class Heap(Container): array = [] # Allows “if item in tree:” def __contains__(self, item): return self._contains(item, 1) def _contains(self, item, index): if item > […]

# A binary search tree in Python

As part of my series on concepts you should never, ever need to reimplement in a real world scenario, here is a binary search tree in Python. This particular example contains a bit of duplicate code, but I doubt the benefits of changing this would outweigh the loss in readability, especially for a learning example. […]

# A bubble sort in Python

As a second exercise in preparation for my Microsoft phone interview, I give you the Python bubble sort (or sinking sort). Once again, this is just an exercise. You should use the standard Python facilities for your sorting needs, especially given the terrible efficiency of bubble sort. from random import shuffle countries = ["Afghanistan","Albania","Algeria", ...] […]