Theory

A random search algorithm works by randomly selecting points from a defined search space and evaluating them to find the best solution to a problem. It explores the space without following a specific pattern, Despite its simplicity, it can be effective in scenarios with large or complex search spaces where exhaustive search is impractical.

Algorithm For Random Search

  1. Function Input:
    • The 'randomSearch' function takes nodes, links, a start node, and an end node as input.
  2. Initialization:
    • Start with an empty path to keep track of the nodes visited during the search.
  3. Check Start Node:
    • Verify if the start node has been visited previously..
    • If it has, backtrack to the previous node and return false.
  4. Visit Start Node:
    • Mark the start node as visited and add it to the path.
  5. Select Links:
    • Identify all available links from the start node..
  6. Random Link Selection:
    • Randomly choose one link from the available links.
  7. Check Target Node:
    • Examine if the selected link leads to the end node
    • If it does, return the path as the solution.
    • If it doesn't, proceed to the next step.
  8. Recursive Call:
    • Call the randomSearch function recursively on the target node.
  9. Backtracking:
    • If no path is found from the current node (i.e., the link doesn't lead to the end node), backtrack to the previous node.
  10. Repeat:
    • Repeat steps 3-9 until a path is found or all nodes have been explored.
  11. No Path Found:
    • If no path is found after exploring all nodes, return false.