Skip to content

Instantly share code, notes, and snippets.

View RuolinZheng08's full-sized avatar

Lynn Zheng RuolinZheng08

View GitHub Profile
@RuolinZheng08
RuolinZheng08 / backtracking_template.py
Last active March 30, 2026 00:56
[Algo] Backtracking Template & N-Queens Solution
def is_valid_state(state):
# check if it is a valid solution
return True
def get_candidates(state):
return []
def search(state, solutions):
if is_valid_state(state):
solutions.append(state.copy())
@RuolinZheng08
RuolinZheng08 / graph_traversal_template.py
Last active July 1, 2022 13:54
[Algo] Graph Traversal Template
# Iterative
def dfs(graph, start):
visited, stack = set(), [start]
while stack:
node = stack.pop()
visited.add(node)
for neighbor in graph[node]:
if not neighbor in visited:
stack.append(neighbor)
return visited
@RuolinZheng08
RuolinZheng08 / tree_traversal_template.py
Created November 20, 2020 15:19
[Algo] Tree Traversal Template
# DFS
def preorder(self, root):
if not root:
return []
ret = []
stack = [root]
while stack:
node = stack.pop()
ret.append(node.val)
if node.right:
@RuolinZheng08
RuolinZheng08 / permutation_test.ipynb
Created January 31, 2021 20:45
[Python, Statistics] Permutation Test
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@RuolinZheng08
RuolinZheng08 / epidemic_network.ipynb
Last active January 31, 2021 20:59
[Python, Statistics] An SIR (Susceptible, Infected and Recovered) Network Example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.