This file contains 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 collections import defaultdict | |
class DoubleNode: | |
def __init__(self, data=0, next_node=None, prev_node=None): | |
self.data = data | |
self.next = next_node | |
self.prev = prev_node | |
class Cache: | |
def __init__(self): |
This file contains 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 collections import defaultdict | |
from heapq import heappush, heappop | |
class WeightedVertex: | |
def __init__(self, name): | |
self.name = name | |
self.adjacent = [] | |
def addEdge(self, vertex, weight): | |
self.adjacent.append((vertex, weight)) |
This file contains 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 rapin_karp(pat, txt): | |
M = len(pat) | |
N = len(txt) | |
p = 0 | |
t = 0 | |
h = 1 | |
d = 256 | |
q = 101 | |
for i in range(M - 1): |
This file contains 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 HashNode: | |
def __init__(self, key, value): | |
self.next = None | |
self.key = key | |
self.value = value | |
class HashTable: | |
def __init__(self): | |
self.table = [None] * 101 |
This file contains 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=0, next_node=None): | |
self.data = data | |
self.next = next_node | |
class LinkedList: | |
def __init__(self): | |
self.head = None | |
def appendleft(self, new_data): |
This file contains 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 DoubleNode: | |
def __init__(self, data=0, next_node=None, prev_node=None): | |
self.data = data | |
self.next = next_node | |
self.prev = prev_node | |
class DoublyLinkedList: | |
def __init__(self): | |
self.head = None | |
self.tail = None |
This file contains 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 collections import defaultdict, deque, Counter | |
class Vertex: | |
def __init__(self, name): | |
self.name = name | |
self.adjacent = [] | |
def addEdge(self, vertex): | |
self.adjacent.append(vertex) |
This file contains 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 BinaryTreeNode: | |
def __init__(self, data=None, left=None, right=None): | |
self.data = data | |
self.left = left | |
self.right = right | |
class BinarySearchTree: | |
def __init__(self): | |
self.root = None |
This file contains 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 TrieNode: | |
def __init__(self): | |
self.children = [None] * 26 | |
self.end = False | |
self.prefix = 0 | |
def has_no_children(self): | |
for child in self.children: | |
if child: | |
return False |
This file contains 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 MinHeap: | |
def __init__(self): | |
self.heap = [] | |
def peek(self): | |
if not self.heap: | |
return False | |
return self.heap[0] | |
def push(self, data): |