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
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: |
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
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) |
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 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) | |
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
###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 |
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
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) |
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
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 |
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
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) |
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
import string | |
import random | |
import math | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import time | |
import pylab | |
class CBFclass(): | |
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
#### 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: |
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
## | |
## Binary Search Tree | |
## | |
class Node: | |
def __init__(self, val): | |
self.l_child = None | |
self.r_child = None | |
self.parent = None | |
self.data = val |
NewerOlder