Skip to content

Conversation

@Erennn7
Copy link
Contributor

@Erennn7 Erennn7 commented Oct 20, 2025

Iterative Deepening Depth-First Search (IDDFS) in R

This PR introduces a fully documented, optimized, and production-ready implementation of the Iterative Deepening Depth-First Search (IDDFS) algorithm in R.
IDDFS combines the completeness of Breadth-First Search (BFS) with the space efficiency of Depth-First Search (DFS), making it suitable for exploring large or infinite state spaces where depth is unknown.


🔍 Overview

The iddfs() function repeatedly performs Depth-Limited Search (DLS) from depth 0 up to a user-defined max_depth.
It halts once the target vertex is found, ensuring the shallowest (shortest depth) solution is discovered efficiently.


✨ Key Features

  • 🚀 Optimized implementation — no global assignments, magic numbers, or redundant loops
  • 🧩 Graph normalization through normalize_graph() ensures robust adjacency handling
  • 🛡️ Cycle-safe search using path-based cycle detection
  • 📊 Verbose tracing for step-by-step exploration visualization
  • 🧠 Comprehensive examples in example_iddfs() demonstrating typical graph search cases

⚙️ Algorithm Details

  • Time Complexity: O(b^d) — where b is the branching factor and d is the depth of the solution
  • Space Complexity: O(d) — proportional to recursion or stack depth

🧮 Applications

  • Artificial Intelligence search problems (e.g., puzzles, decision trees)
  • Graph traversal in unweighted or depth-limited problems
  • Optimal exploration in unknown-depth environments

🧱 Example Usage

# Example: Simple directed graph
graph <- list(
  "1" = c(2, 3),
  "2" = c(4),
  "3" = c(5),
  "4" = c(),
  "5" = c()
)

iddfs(graph, start = 1, target = 5, max_depth = 5, verbose = TRUE)

# Output:
# Iterative Deepening DFS
# ============================================================
# Searching at depth limit: 0
# Searching at depth limit: 1
# Searching at depth limit: 2
# ✓ Target 5 found at depth 2

Copilot AI review requested due to automatic review settings October 20, 2025 02:48
@Erennn7 Erennn7 requested review from acylam and siriak as code owners October 20, 2025 02:48
@Erennn7
Copy link
Contributor Author

Erennn7 commented Oct 20, 2025

@siriak please have a look sir.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a comprehensive implementation of the Iterative Deepening Depth-First Search (IDDFS) algorithm to the R repository. IDDFS combines the space efficiency of DFS with the optimality guarantees of BFS by performing repeated depth-limited searches with increasing depth limits.

  • Implements IDDFS with robust graph normalization and cycle detection
  • Includes comprehensive documentation, examples, and verbose output options
  • Provides production-ready code with proper error handling and input validation

Copilot AI review requested due to automatic review settings October 20, 2025 02:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@siriak siriak merged commit b2d6b24 into TheAlgorithms:master Oct 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants