liveBook · Manning

Stack

As explained in Applied Reinforcement Learning

A stack is a data structure that processes elements in last-in, first-out order.

A stack stores items in last-in, first-out (LIFO) order: the newest item is added to and removed from the top. section 7.2

Depth-first search uses a stack to follow one branch deeply before backtracking. Recursion can provide this stack through the function call stack. section 7.2

Exploring delivery routes

In a route search, DFS extends one customer route until all customers are visited, then backtracks to try another order. section 7.2

dfs("Depot")
 ├── dfs("C1")
 │     ├── dfs("C3")
 │     │     ├── dfs("C5")   → no unvisited neighbors, backtrack
 │     │     └── dfs("C6")   → continue exploration
 │     └── dfs("C4")         → new branch
 └── dfs("C2")               → new high-level branch

Follow recursive calls as DFS explores route branches and backtracks. section 7.2

How Applied Reinforcement Learning covers it

How deep it goes
Defines LIFO behavior and relates it to DFS recursion, without detailing stack internals.
Examples
Demonstrates recursive depth-first exploration of customer routes and backtracking.
What you can do after
Apply recursion to explore a search tree deeply before backtracking.
How it connects
Links stacks to depth-first search, recursion, and breadth-first search as a contrast.

Also explained in

Compare how 17 books explain stack →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Applied Reinforcement Learning. The section links point to the parts of the book it draws on.