Skip to content

Instantly share code, notes, and snippets.

View emmastiefel's full-sized avatar

Emma Stiefel emmastiefel

View GitHub Profile
@emmastiefel
emmastiefel / sorting _algorithm_analysis_cs110.py
Created January 17, 2019 02:33
Sorting Algorithm Analysis
# coding: utf-8
# In[103]:
import time
import timeit
import matplotlib.pyplot as plt
###define test arrays
@emmastiefel
emmastiefel / merge sort cs110.py
Created January 21, 2019 18:03
Merge Sort and Analysis
# 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
@emmastiefel
emmastiefel / gist:0a24fa1833cd3e4b4207bcb022b283c5
Created January 28, 2019 17:35
incremental maximum subarray
# coding: utf-8
# In[22]:
def max_subarray(x, mx):
#initializes variable to store max sum, start, and end points
max_profit = -float('inf')
# 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
# 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
# coding: utf-8
# In[140]:
class MaxHeap:
def __init__(self, alist):
self.heap = alist
# coding: utf-8
# In[3]:
##implements worst sorting function
import random
# coding: utf-8
# In[2]:
##define partition algorithm
#takes array and start and end indices as input
def partition(A, p, r):
# coding: utf-8
# In[10]:
##quicksort without separating equal items
import timeit
import random
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: