Skip to content

Instantly share code, notes, and snippets.

View MandlaSibanda196's full-sized avatar

Mandlenkosi Sibanda MandlaSibanda196

View GitHub Profile
library(rgenoud)
library(Matching)
library(quantreg)
library(foreign)
##########################################################
###################### QUESTION 1 ########################
##########################################################
## loading necessary packages
library(Zelig)
library("ZeligChoice")
library(xtable)
library(reshape)
library(apsrtable)
library(stargazer)
library(rms)
ssc install synth
ipolate educ year, gen(educ2) epolate by(countrycode)
clear
cd "C:\Users\Mandlenkosi Sibanda\Documents\Synth2"
use "data\sanctions.dta"
tsset countrycode year, year
#delimit;
@MandlaSibanda196
MandlaSibanda196 / gist:aab4deac3222775ad5afeb23c9c7a4dc
Created January 17, 2019 15:26
Pre-class Work: CS110 Session 1.2 - Analyzing elementary sorting algorithms
import matplotlib.pyplot as plt
import time
import random
import numpy as np
#insertion sort
def insertion_sort(array):
tt = time.clock()
steps = 0
length = len(array)
import matplotlib.pyplot as plt
import time
import random
import numpy as np
#create randomized arrays for the algorithm to sort
#size of the array is set to 10
#max is set to 50 as the maximum value of the randomy generated values in the array
def create_array(size=10,max=50):
from random import randint
## implementation of the max subarray
## naive approach
def incremental_max_subarray(x, mx):
return max(mx, max_subarray(x))
def max_subarray(x):
#for loops to keep a running max
max_so_far = float('-inf') #keep the maximum smallest value to compare with
array = [] #empty list that I will use to store the array producing the largest sum
def max_heapify(A, n, i): #function that takes in an array A and index i
#finding the largest among root and children
left = 2 * i + 1
right = 2 * i + 2
largest = i
#check if left child exists and greater than the root
if left < len(A) and A[left] > A[largest]:
largest = left
import heapq
import unittest
import time
start = time.time()
def _heappush_max(heap, item):
heap.append(item)
heapq._siftdown_max(heap, 0, len(heap)-1)
import random
newwarr =[]
def worstsort(x):
items = [[i] for i in len(x)]
random.shuffle(items)
newarr.append(random.shuffle(items)
if newarr == sorted(x):
print (newarr)
import random
import time
random.seed(123)
start = time.time()
def partition(arr,low,high):
i = ( low-1 )
pivot = arr[high]
for j in range(low , high):