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
library(rgenoud) | |
library(Matching) | |
library(quantreg) | |
library(foreign) | |
########################################################## | |
###################### QUESTION 1 ######################## | |
########################################################## |
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
## loading necessary packages | |
library(Zelig) | |
library("ZeligChoice") | |
library(xtable) | |
library(reshape) | |
library(apsrtable) | |
library(stargazer) | |
library(rms) |
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
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; |
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 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) |
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 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 |
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
## 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 |
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
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 | |
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 unittest | |
import time | |
start = time.time() | |
def _heappush_max(heap, item): | |
heap.append(item) | |
heapq._siftdown_max(heap, 0, len(heap)-1) |
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 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) |
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 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): |
OlderNewer