Interactive Uninformed Search Demo
Prerequisites
- BFS, DFS, UCS — Understanding of each algorithm’s expansion strategy
- Comparison — Differences between strategies
🎯 Learning Objectives
- Visualise how BFS, DFS, and UCS explore a search tree differently
- Observe the frontier and explored set at each step
- Compare node expansion order across algorithms
- Build intuition for why each algorithm makes the choices it does
1. How to Use This Demo
The interactive visualisation below lets you watch uninformed search algorithms execute on a sample search tree. Here’s how to use it:
- Select an algorithm using the dropdown: BFS, DFS, or UCS.
- Click Step to advance one expansion at a time, or Play to auto-advance.
- Click Reset to return to the initial state and try a different algorithm.
- Watch the colour coding:
- Blue = In frontier (queued for expansion)
- Orange = Currently being expanded
- Green = Goal found!
- Grey = Explored (already expanded)
- The log panel below the tree shows the frontier contents and explanation for each step.
2. Search Tree Visualisation
🔮 Search tree visualisation will render here.
Select an algorithm and click Step or Play to begin.
Step log will appear here…
3. The Sample Search Tree
The demo uses the following weighted tree. Edge weights are used by UCS; BFS and DFS ignore them.
S (Start)
/ \
1/ \5
/ \
A B
/ \ \
3/ \4 \2
/ \ \
C D E
/ \ \
2/ \6 \1
/ \ \
F H G (Goal)
Goal node: G. The optimal path is S→A→D→G with cost 1+4+1 = 6.
3.1 Expected Behaviour by Algorithm
| Algorithm | Expansion Order | Path Found | Cost | Optimal? |
|---|---|---|---|---|
| BFS | S, A, B, C, D, E, F, H, G | S→A→D→G | 6 | Yes (unit-depth, but cost = 6) |
| DFS | S, A, C, F, H, D, G | S→A→D→G | 6 | Happens to be optimal here, but not guaranteed |
| UCS | S, A, C, D, F, B, G | S→A→D→G | 6 | Yes (always optimal) |
💡 Observe the Differences
BFS expands level by level (S, then A&B, then C&D&E, …). DFS dives deep-left first (S→A→C→F) before backtracking. UCS expands cheapest-first (S at cost 0, then A at cost 1, then C at cost 4, then D at cost 5, …).
4. What to Observe
As you step through each algorithm, pay attention to these key differences:
4.1 Frontier Data Structure
| Algorithm | Data Structure | Effect |
|---|---|---|
| BFS | FIFO Queue | Nodes are expanded in the order they were discovered — breadth-first, level by level. |
| DFS | LIFO Stack | The most recently discovered node is expanded first — depth-first, diving deep before backtracking. |
| UCS | Priority Queue (min g(n)) | The node with the lowest cumulative path cost is expanded first — cost-first. |
4.2 Memory Usage
Watch the Frontier Size counter. BFS’s frontier grows wide (many nodes at the same level). DFS’s frontier stays narrow (only siblings along the current path). UCS’s frontier grows like BFS but may differ in composition due to cost ordering.
4.3 Path Quality
When the goal is found, compare the Path Cost. BFS finds the shallowest path (optimal for unit costs). UCS finds the cheapest path (optimal for any non-negative costs). DFS finds a path, which may or may not be optimal.
4.4 Expansion Count
The Nodes Expanded counter shows efficiency. UCS may expand fewer nodes than BFS if it can find a cheap path before BFS finishes exploring expensive shallow branches (or more, if costs create longer detours).
5. Hands-On Exercises
Try these exercises using the demo above:
Exercise 1: Compare BFS and DFS
- Run BFS to completion. Note the expansion order and total nodes expanded.
- Reset and run DFS. Compare the expansion order.
- Question: Did DFS find the goal sooner (fewer expansions) or later? Why?
Exercise 2: UCS Cost Advantage
- Run UCS and note which node it expands third (after S and A). Why that node?
- Answer: It should expand the node with the lowest g(n). After S (g=0) and A (g=1), the cheapest node in the frontier determines the next expansion.
Exercise 3: Frontier Size Tracking
- For each algorithm, note the maximum frontier size during the search.
- Question: Which algorithm had the largest frontier at its peak? This illustrates the memory trade-off.
Exercise 4: Predict Before Stepping
- Start BFS. After expanding S, predict what the frontier contains before clicking Step.
- Verify your prediction. Repeat for each step.
- This builds the mental model needed for GATE paper-tracing questions.
6. Quick Algorithm Recap
6.1 BFS (Breadth-First Search)
Explores all nodes at depth k before moving to depth k+1. Uses a FIFO queue. Guarantees the shallowest solution. Time and space: O(bd).
6.2 DFS (Depth-First Search)
Explores as deep as possible along each branch before backtracking. Uses a LIFO stack (or recursion). Space-efficient: O(b·m). Not complete or optimal in general.
6.3 UCS (Uniform-Cost Search)
Expands the node with the lowest cumulative cost g(n). Uses a min-priority queue. Always finds the optimal solution (if step costs ≥ ε > 0). Goal test at expansion, not generation.
💡 The Key Distinction for UCS
UCS tests for the goal when a node is removed from the priority queue (expanded), not when it is first generated. This ensures that a cheaper path to the goal is always found before a more expensive one is declared the solution.
7. Interpreting Your Results
After running all three algorithms, you should observe:
- BFS explores nodes systematically, level by level. It finds the goal at the correct depth but may explore many nodes at each level.
- DFS reaches deep nodes quickly. In this tree, it may find the goal with fewer expansions if the goal is on the left side, or many more if it’s on the right side.
- UCS expands in order of cost. It may skip cheap deep nodes in favour of exploring all cheap paths first, eventually finding the optimal path.
- The frontier size tells you the memory story: BFS and UCS have larger frontiers; DFS keeps it lean.
These observations directly map to the theoretical properties covered in the Comparison of Strategies and Complexity Analysis pages.
Summary
- Use the interactive demo to visualise BFS, DFS, and UCS in action.
- Observe how the data structure (FIFO, LIFO, priority queue) determines expansion order.
- Track frontier size and nodes expanded to understand memory and time trade-offs.
- Practice predicting the next step before clicking — this builds the skills needed for GATE.
- The demo reinforces theory from previous pages; revisit them to deepen understanding.
References
- Russell & Norvig, AIMA, Chapter 3.4 — Uninformed Search Strategies.