Learn R Programming

cayleyR (version 0.2.1)

bidirectional_bfs: Bidirectional BFS Shortest Path

Description

Finds the shortest path between two permutation states using bidirectional breadth-first search. Expands from both the start and goal states simultaneously, meeting in the middle.

Usage

bidirectional_bfs(n, state1, state2, max_level, moves, k)

Value

Character vector of operations forming the shortest path, or NULL if no path found within max_level

Arguments

n

Integer, size of the permutation

state1

Integer vector, start state

state2

Integer vector, goal state

max_level

Integer, maximum BFS depth in each direction

moves

Character vector, allowed operations (e.g., c("1", "2", "3"))

k

Integer, parameter for reverse operations

Examples

Run this code
# Find path between two small states
path <- bidirectional_bfs(5, 1:5, c(2, 3, 4, 5, 1), max_level = 5,
                          moves = c("1", "2", "3"), k = 3)
path

Run the code above in your browser using DataLab