Search

A Search Algorithm finds something

What is a Search Algorithm?🧐

A Search Algorithm finds something.

Claw Machine

🐌Linear Search is an algorithm which looks at each item one by one in unordered list until the item is found.

  • Looking for scissors in the junk drawerβœ‚οΈ

  • Matching a single sock to the pair in a pile of laundry 🧦

  • Checking out the old photo album with grandma πŸ‘΅

πŸš€Binary Search is an algorithm which continually splits an ordered list in half until the item is found.

  • Finding a specific page number in a book πŸ“–

    • A person would look like so to find a specific page number

    • 500, 600, 580, 581, 582

    • Not like this

    • 1,2,3,4,5,6,7,8,9,10,11...582

  • Searching for an old holiday photo in a phoneπŸŽ„

    • Search by year

    • Search by month

    • Search by day

🐌Linear Search vsπŸš€Binary Search in a heads up comparison on the same list.

🌧️BFS: Breadth First Search algorithm Flows in every direction evenly to find the item. In a tree data structure for example it would search for the item in all the nodes by each level(floor). Dropping one level & then explore all nodes, dropping one level then explore all nodes, etc..

  • Tree branches growing out

  • Root system expanding out

🌩️DFS: Depth First Search algorithm Strikes each direction one by one to find the item. In a tree data structure for example it would search for the item by exploring a branch all the way to the bottom of a tree then trying a different branch all the way to the bottom.

  • Lightning strikes

Example Tree

BFS Example: first 8 nodes found

DFS Example: first 4 nodes found

Last updated

Was this helpful?