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
# coding: utf-8 | |
# In[103]: | |
import time | |
import timeit | |
import matplotlib.pyplot as plt | |
###define test arrays |
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
# coding: utf-8 | |
# Write a Python function that implements merge sort such that it not only sorts a given input list, but also records a count of the steps performed. | |
# In[102]: | |
##define merge function |
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
# coding: utf-8 | |
# In[22]: | |
def max_subarray(x, mx): | |
#initializes variable to store max sum, start, and end points | |
max_profit = -float('inf') |
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
# coding: utf-8 | |
# In[39]: | |
####define heap functions | |
#ideally, these would be implemented as part of a heap class | |
#add 1 to left and right indices to account for how python counts numbers |
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
# coding: utf-8 | |
# In[39]: | |
####define heap functions | |
#ideally, these would be implemented as part of a heap class | |
#add 1 to left and right indices to account for how python counts numbers |
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
# coding: utf-8 | |
# In[140]: | |
class MaxHeap: | |
def __init__(self, alist): | |
self.heap = alist |
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
# coding: utf-8 | |
# In[3]: | |
##implements worst sorting function | |
import random |
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
# coding: utf-8 | |
# In[2]: | |
##define partition algorithm | |
#takes array and start and end indices as input | |
def partition(A, p, r): |
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
# coding: utf-8 | |
# In[10]: | |
##quicksort without separating equal items | |
import timeit | |
import random |
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
import heapq | |
import random | |
#####implement median heap | |
##define function to build median heap | |
def add_to_median_heap(minh, maxh, elem): | |
#add element so that the heap lengths don't differ by more than 1 | |
if len(minh) < len(maxh) +1: |
OlderNewer