Skip to content

Instantly share code, notes, and snippets.

View gcallah's full-sized avatar

Gene Callahan gcallah

View GitHub Profile
@gcallah
gcallah / greedy_algorithms.py
Created October 19, 2017 20:08
Greedy algorithm Python code.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This file contains Python implementations of greedy algorithms
from Intro to Algorithms (Cormen et al.).
The aim here is not efficient Python implementations
but to duplicate the pseudo-code in the book as closely as possible.
Also, since the goal is to help students to see how the algorithm
works, there are print statements placed at key points in the code.
The performance of each function is stated in the docstring, and
@gcallah
gcallah / quick_sort.py
Last active September 19, 2017 19:06
Quick sort for algorithms/quicksort.html
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This file contains Python implementations of the quicksort algorithm from
Intro to Algorithms (Cormen et al.)
The aim here is not efficient Python implementations (we'd just call
the native sort if we wanted that) but to duplicate the pseudo-code
in the book as closely as possible.
Also, since the goal is to help students to see how the algorithm
works, there are print statements placed at key points in the code.
@gcallah
gcallah / find_max_subarray.py
Last active April 28, 2021 11:35
Find maximum subarray code from CLRS implemented in Python.
import sys
NEG_INF = -1 * sys.maxsize
def find_max_crossing_subarray(l, low, high, mid):
"""
Args:
l: the list to search.
low: the lowest index to look at.
@gcallah
gcallah / binary_search_trees.py
Created April 22, 2017 22:12
Binary search tree algorithms from CLRS Intro to Algorithms.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This file contains Python implementations of binary search tree
from Intro to Algorithms (Cormen et al.).
The aim here is not efficient Python implementations
but to duplicate the pseudo-code in the book as closely as possible.
Also, since the goal is to help students to see how the algorithm
works, there are print statements placed at key points in the code.
The performance of each function is stated in the docstring, and
@gcallah
gcallah / dynamic_programming.py
Created April 22, 2017 00:29
Dynamic programming code from CLRS Intro to Algorithms pseudocode..
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This file contains Python implementations of dynamic programming
from Intro to Algorithms (Cormen et al.).
The aim here is not efficient Python implementations
but to duplicate the pseudo-code in the book as closely as possible.
Also, since the goal is to help students to see how the algorithm
works, there are print statements placed at key points in the code.
The performance of each function is stated in the docstring, and