Algorithms

Browse the Algorithms posts.

Posts without dates

Traverse a tree

DFS (depth first search) DFS can be done easily with recursive method, because you can treat the subtrees as new trees and use the same function to traverse them. BFS (breadth first search) BFS will need extra space of a …

Traverse a graph

Mark all nodes as not visited. Create an empty ready bucket to hold nodes that has been visited itself but not its neighbors yet. Find a starting node, mark it as visited and put into the ready bucket. Get an node from …

Python `heapq` Priority queue (heap queue)

Attributes# “Min heap”, where index 0 is the smallest item APIs# heapq.heapify(iterable) -> None: Create a heap queue in-place heapq.heappush(heap, item) -> None: Add a new item heapq.heappop(heap) …

Boyer-Moore Voting Algorithm

#note #learn-with-chatgpt #algorithm NOTE: this is a note from ChatGPT The Boyer-Moore Voting Algorithm, also known simply as the Voting Algorithm, is a method for finding a majority element in a sequence of elements. …