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 …
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 …
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) …
#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. …