This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |