Lists, stacks, and queues (with attitude)
This post aims to introduce list, stack, and queue data structures with discussions about implementation and analysis.
This post aims to introduce list, stack, and queue data structures with discussions about implementation and analysis.
Depth-first search (DFS) on a graph (binary tree or otherwise) is most often implemented recursively, but there are occasions where it may be desirable to consider an iterative approach instead. Such as when we may be worried about overflowing the call stack. In such cases it makes sense to rely on implementing DFS with our own stack instead of relying on our program's implicit call stack. But doing so can lead to some problems if we are not careful.
Monotonic stacks and queues have a reputation for being notoriously difficult. Why? I suspect the difficulty lies not in what these data structures are but how they are often used to craft solutions to various problems.