Skip to content

Instantly share code, notes, and snippets.

View mgarod's full-sized avatar

Michael Garod mgarod

View GitHub Profile
def insert(self, d):
if self.head is None:
self.head = Node(d)
else:
self.insert_helper(self.head, d)
def insert_helper(self, nd, d):
if d < nd.data:
if nd.left is None:
nd.left = Node(d)
@mgarod
mgarod / subseq.py
Last active January 28, 2016 19:32
you have a function that takes a positive integer N and another positive integer S that function should generate all the subsequences with size S of the numbers within the range [1, N]. you can either return a collection of these sequences or just print each one to the standard output. example: subsequences(3,2) yields: 1,2 1,3 2,3
def sub(N, S):
sub_helper(S, range(1,N+1), list())
def sub_helper(S, remainingList, subseq):
if S == 0:
print subseq
return
else:
for i in range(0, len(remainingList)-S+1):
subseq.append(remainingList[i])
input:
(c1, [p1])
(c2, [p1, p2])
(c3, [p1])
-----------------------------------------------------------------
QUESTION 1:
Given a customer-product graph where customers and products are nodes,
and an edge is formed if a customer buys a product, design an MapReduce
algorithm to compute the frequency distribution of the number of customers
class Node:
def __init__(self, val=None):
self.data=val
self.left=None
self.right=None
class BST:
def __init__(self):
self.root=None
self.head=None
# Title: charfreq.py
# Author: Michael Gard
# Date Created: 8/14/16
# Description: Given the plain text resume "pt_MG_Resume.txt", output a barplot in Seaborn representing individual character frequency. Colors of the bars are determined by creating one "color bucket" per each of the 26 characters. Higher frequencies get darker colors
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import string
#include <fstream>
#include <iostream>
#include <unordered_map>
#include <vector>
int main() {
std::ifstream datafile("data.txt");
int64_t numlists;
int64_t a, b, c, d;
std::vector<int64_t> A, B, C, D;
#include <iostream>
using namespace std;
void printTriangle(int n) {
for (int i = 0; i < n; ++i) {
for (int j = ((2*n-1) - (2*i+1))/2; j > 0; --j){
cout << " ";
}
for (int k = (2*i+1); k > 0; --k){
var callback = function(x) { coordinates = x; }
navigator.geolocation.getCurrentPosition(callback);
console.log(coordinates);
@mgarod
mgarod / max2.cpp
Last active October 27, 2016 15:41
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
class Max2{
public:
Max2() : largest(INT_MIN), nextlargest(INT_MIN), lindex(-1), nlindex(-1) { };
friend ostream& operator<<(ostream& os, Max2 m);
void insert(int n, int nindex);
#include <iostream>
using namespace std;
int reverseAsHex(int n) {
int mask = 0xF; // or 15
int answer = 0;
while (n != 0) {
answer = (answer << 4) | (n & mask);
n >>= 4;
}