This file contains 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
############################################################## | |
# # | |
# Copyright 2013 Christopher Abiad. All rights reserved. # | |
# # | |
############################################################## | |
__author__ = 'Chris Abiad <cabiad@oanda.com>' | |
""" | |
Directed graph |
This file contains 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
######################################################### | |
# # | |
# Copyright 2013 Christopher Abiad All rights reserved. # | |
# # | |
######################################################### | |
__author__ = 'Chris Abiad <chris@chrisabiad.com>' | |
import collections |
This file contains 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
######################################################### | |
# # | |
# Copyright 2013 Christopher Abiad All rights reserved. # | |
# # | |
######################################################### | |
__author__ = 'Chris Abiad <chris@chrisabiad.com>' | |
def f1(): | |
while True: |
This file contains 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
#################################### | |
# Copyright Christopher Abiad, 2013 | |
# All Rights Reserved | |
#################################### | |
__author__ = 'Christopher Abiad' | |
def find_missing_one(bit_index, A): | |
# there is only one item | |
if bit_index == 0: |
This file contains 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
#################################### | |
# Copyright Christopher Abiad, 2013 | |
# All Rights Reserved | |
#################################### | |
__author__ = 'Christopher Abiad' | |
def toh(num, src, dest, other): | |
if num <= 0: |
This file contains 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
#################################### | |
# Copyright Christopher Abiad, 2013 | |
# All Rights Reserved | |
#################################### | |
"""In-place quicksorting.""" | |
__author__ = 'Christopher Abiad' | |
from random import randrange |
This file contains 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
#################################### | |
# Copyright Christopher Abiad, 2013 | |
# All Rights Reserved | |
#################################### | |
"""Binary min-heap with a simple heapsort implementation. | |
Heap is stored entirely in an array (Python list) using the property that | |
for any node at position i, its two children can be stored at 2i and | |
2i + 1 without any collisions with other nodes. | |
""" |
This file contains 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
#################################### | |
# Copyright Christopher Abiad, 2012 | |
# All Rights Reserved | |
#################################### | |
__author__ = 'Christopher Abiad' | |
def mergesort(l): | |
n = len(l) | |
if n <= 1: |