Skip to content

Instantly share code, notes, and snippets.

View ZinebSalimi's full-sized avatar
👋

ZinebSalimi ZinebSalimi

👋
  • New York, NY
View GitHub Profile
import heapq
from urllib.request import urlopen
import shutil
import gzip
import os
from collections import defaultdict
from bitarray import bitarray
import pickle
class Node:
import heapq
class hall:
def __init__(self, name, end=0, activities=[]):
self.name = name
self.end = end #updates time when hall gets free
self.activities = activities
def add(self, a):
self.activities.append(a)
def print_LCS(b,X,i,j):
if i==0 and j==0:
return
if b[i][j]=='diagonal':
print_LCS(b,X,i-1,j-1)
print (X[i])
elif b[i][j]== 'up':
print_LCS(b,X,i-1,j)
else: print_LCS(b,X,i,j-1)
###TOP-DOWN RECURSIVE SOLUTION
import math
def CUT_ROD(prices,n):
if n==0: #base case
return 0
q = -math.inf
for i in range(1,n+1):
q = max(q, prices[i-1]+ CUT_ROD(prices,n-i))
return q
import queue
n=len(g.nodes)
list=['r', ['s','v'],'s', ['r','w'],'v',['r'],'t', ['w','x','u'],'u', ['t','x','y'], 'w', ['s','t','x'],'x', ['w','t','u','y'],'y', ['u','x']]
visited=[]
def BFS(graph, root, target):
queue=[]
queue.append(root)
import random
#Write python code that calculates the average number of
#comparisons required to search for a randomly chosen
#element of a standard BST.
#average height of a tree is O(log n)
def avg_cmp(bst):
cmp_count=0
level=1
class CBFclass():
def __init__(self, n, m):
#counter size (size of buckets)
self.bit_max =8
#number of entries
self.n = n
#size of the table (number of buckets)
import string
import random
import math
import numpy as np
import matplotlib.pyplot as plt
import time
import pylab
class CBFclass():
#### QUESTION 1 ####
import random
#function that generates N empty guesses
def empty_guess(size):
return ['']*size
#sets a guess for the ith entry (guess is given by user)
def guess(direction, entry, guess):
if direction[entry] != None:
##
## Binary Search Tree
##
class Node:
def __init__(self, val):
self.l_child = None
self.r_child = None
self.parent = None
self.data = val