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 Graph: | |
def __init__(self): | |
self.adj_list = {} | |
def add_edge(self, u, v): | |
if u not in self.adj_list: | |
self.adj_list[u] = [] | |
self.adj_list[u].append(v) | |
def dfs(self, start, visited=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
from collections import deque | |
class Graph: | |
def __init__(self): | |
self.adj_list = {} | |
def add_edge(self, u, v): | |
if u not in self.adj_list: | |
self.adj_list[u] = [] | |
self.adj_list[u].append(v) |
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 TreeNode: | |
def __init__(self, key, left=None, right=None): | |
self.key = key | |
self.left = left | |
self.right = right | |
class LinkedBST: | |
def __init__(self): | |
self.root = None | |
self.size = 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
import math | |
class TreeNode: | |
def __init__(self, key, left=None, right=None): | |
self.key = key | |
self.left = left | |
self.right = right | |
class LinkedBST: | |
def __init__(self): |
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 AbstractCollection(object): | |
"""An abstract collection implementation.""" | |
# Constructor | |
def __init__(self, sourceCollection = None): | |
"""Sets the initial state of self, which includes the | |
contents of sourceCollection, if it's present.""" | |
self.size = 0 | |
if sourceCollection: |
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 Array(object): | |
"""Represents an array.""" | |
def __init__(self, capacity, fillValue = None): | |
"""Capacity is the static size of the array. | |
fillValue is placed at each position.""" | |
self.items = list() | |
for count in range(capacity): | |
self.items.append(fillValue) |
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 Array(object): | |
"""Represents an array.""" | |
def __init__(self, capacity, fillValue=None): | |
"""Capacity is the static size of the array. | |
fillValue is placed at each position.""" | |
self._items = [fillValue] * capacity | |
def __len__(self): | |
"""-> The capacity of the array.""" |
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 Array(object): | |
"""Represents an array.""" | |
def __init__(self, capacity, fillValue=None): | |
"""Capacity is the static size of the array. | |
fillValue is placed at each position.""" | |
self._items = [fillValue] * capacity | |
def __len__(self): | |
"""-> The capacity of the array.""" |
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 Array(object): | |
"""Represents an array.""" | |
def __init__(self, capacity, fillValue=None): | |
"""Capacity is the static size of the array. | |
fillValue is placed at each position.""" | |
self._items = [fillValue] * capacity | |
def __len__(self): | |
"""-> The capacity of the array.""" |
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 Array(object): | |
"""Represents an array.""" | |
def __init__(self, capacity, fillValue=None): | |
"""Capacity is the static size of the array. | |
fillValue is placed at each position.""" | |
self._items = [fillValue] * capacity | |
def __len__(self): | |
"""-> The capacity of the array.""" |
NewerOlder