Plan...Search...Repeat
Tags: beginners
Published: 2021-06-30 12:04:35

Suppose we're going on a trip to the beach. It's 500 km away, with two stops: one at a petting zoo and one at a pizza restaurant. We will sleep at a lodge close to the beach on arrival and partake in three activities. The trip to the destination will take approximately 8 hours...

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8mjngtej9e3qc076zce8.png)

We drive on and start getting hungry; it’s time for the stop at the restaurant. But to our surprise, the restaurant recently went out of business. We need to adjust our plan and find another place to eat, which involves searching.

After driving around for a while, we find a restaurant, enjoy a pizza, and get back on the road. Upon approaching the shortcut private road, we realize that it’s 2:20. The road is closed; yet again, we need to adjust our plan.

Searching involves evaluating future states toward a goal with the aim of finding an optimal path of states until the ultimate goal is reached. Search algorithms use this intuition to solve hard problems in many pieces of software we use everyday.

Understanding that different algorithms have different computation costs is critical because addressing this is the entire purpose of intelligent algorithms that solve problems well and fast. Big O makes sense of this - if it's confusing, look at the Good, Bad, and Okay labels.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sq10usu8967jdjt9ov8o.png)

Theoretically, we can solve almost any problem by trying every possible option until we find the best one (brute-forcing), but in reality, the computation on traditional computer architectures could take hours or even decades, which makes it infeasible for real-world scenarios.

Uninformed search is also known as unguided search or brute-force search. Uninformed search algorithms have no additional information about the domain of the problem apart from the representation of the problem, which is usually a tree data structure.

Breadth-first search is an algorithm used to traverse or generate a tree. This algorithm starts at a specific node, called the root, and explores every node at that depth before exploring the next depth of nodes, until it finds a goal leaf node.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sq10usu8967jdjt9ov8o.png)

Depth-first search is another algorithm used to traverse a tree or generate nodes and paths in a tree. It starts at a specific node and explores paths of connected nodes of the first child, doing this recursively until it reaches the farthest leaf node before backtracking.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m51ta0lqucl269wk4i5e.png)

Search algorithms are versatile and useful in several real-world use cases, such as finding paths between nodes in a computer network, crawling web pages, and finding degrees of possible friendship in social networks.

If you enjoyed this thread and want to learn more about search and other AI algorithms, check out my book, Grokking Artificial Intelligence Algorithms: [http://bit.ly/gaia-book](http://bit.ly/gaia-book), consider [following me](https://twitter.com/RishalHurbans) for more, or join my mailing list for infrequent knowledge drops in your inbox: [https://rhurbans.com/subscribe](https://rhurbans.com/subscribe).