Suppose you’re given a binary tree implemented somewhat like this: Breadth-First Search (BFS) means you traverse the tree level by level, not diving deep into a child node every chance you get. The blocker here is not knowing how to link all nodes belonging to the same level, because in a binary tree, same-level nodes… Continue reading Breadth-First Search (BFS)
Tag: queue
Stack & Queue in Go
1. Stack This is your good ol’ LIFO (last-in, first-out) structure. Just imagine a Pringles tube. A basic stack should have the following methods: In Go, you can use a slice as the underlying data structure. Notice how initiating the store slice in the NewStack[T any]() constructor is optional? This is because we have enough… Continue reading Stack & Queue in Go