Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 merge_tuple(a,b): | |
""" Function to merge two arrays of tuples """ | |
c = [] | |
while len(a) != 0 and len(b) != 0: | |
if a[0][0] < b[0][0]: | |
c.append(a[0]) | |
a.remove(a[0]) | |
else: | |
c.append(b[0]) | |
b.remove(b[0]) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
from random import randrange | |
def partition(x, pivot_index = 0): | |
i = 0 | |
if pivot_index !=0: x[0],x[pivot_index] = x[pivot_index],x[0] | |
for j in range(len(x)-1): | |
if x[j+1] < x[0]: | |
x[j+1],x[i+1] = x[i+1],x[j+1] | |
i += 1 | |
x[0],x[i] = x[i],x[0] |
This file contains hidden or 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
#!/usr/bin/env | |
# Case I | |
# First element of the unsorted array is chosen as pivot element for sorting using Quick Sort | |
def countComparisonsWithFirst(x): | |
""" Counts number of comparisons while using Quick Sort with first element of unsorted array as pivot """ | |
global count_pivot_first | |
if len(x) == 1 or len(x) == 0: |
This file contains hidden or 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
2148 | |
9058 | |
7742 | |
3153 | |
6324 | |
609 | |
7628 | |
5469 | |
7017 | |
504 |
This file contains hidden or 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 quicksort(x): | |
if len(x) == 1 or len(x) == 0: | |
return x | |
else: | |
pivot = x[0] | |
i = 0 | |
for j in range(len(x)-1): | |
if x[j+1] < pivot: | |
x[j+1],x[i+1] = x[i+1], x[j+1] | |
i += 1 |
This file contains hidden or 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
## if fxregime is absent from installed packages, download it and load it | |
if(!require('fxregime')){ | |
install.packages("fxregime") | |
} | |
## load package | |
library("fxregime") | |
# load the necessary data related to exchange rates - 'FXRatesCHF' | |
# this dataset treats CHF as unit currency | |
# install / load Quandl |
This file contains hidden or 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
## if fxregime or strucchange package is absent from installed packages, download it and load it | |
if(!require('fxregime')){ | |
install.packages("fxregime") | |
} | |
if(!require('strucchange')){ | |
install.packages("strucchange") | |
} | |
## load packages | |
library("fxregime") |