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
# A Huffman Tree Node | |
class node: | |
def __init__(self, freq, symbol, left=None, right=None): | |
# frequency of symbol | |
self.freq = freq | |
# symbol name (character) | |
self.symbol = symbol | |
# node left of current 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
# A Huffman Tree Node | |
class node: | |
def __init__(self, freq, symbol, left=None, right=None): | |
# frequency of symbol | |
self.freq = freq | |
# symbol name (character) | |
self.symbol = symbol | |
# node left of current 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
# print all elements of a matrix with a Single loop | |
arr = [[0, 1, 2], | |
[3, 4, 5], | |
[6, 7, 8] | |
] | |
# Method 1 | |
row = len(arr) | |
col = len(arr[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
''' | |
28 | |
27 21 | |
26 20 15 | |
25 19 14 10 | |
24 18 13 9 6 | |
23 17 12 8 5 3 | |
22 16 11 7 4 2 1 | |
''' | |
def num(n1): |
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
# Python Program To Find out the Maximum Value in Nested List | |
list2 = [] | |
def get_max(list1): | |
for i in list1: | |
if type(i) == list: | |
get_max(i) | |
else: | |
list2.append(i) | |
return max(list2) |
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
# Function to determine how many days required to wait for the next warmer day | |
def dailyTemperatures(T): | |
n = len(T) | |
# To store the answer | |
daysOfWait = [-1] * n | |
s = [] | |
# Traverse all the temperatures |
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 Node: | |
def __init__(self,data): | |
self.data = data | |
self.next = None | |
class Linkedlist: | |
def __init__(self): | |
self.head = None | |
# To print the total LinkedList |
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 BS_first(ll,key): | |
left = 0 | |
right = len(ll)-1 | |
while left<=right: | |
mid = int((left+right)/2) | |
if key == ll[mid]: | |
a = mid | |
right = mid - 1 | |
elif key > ll[mid]: | |
left = mid +1 |
NewerOlder