> For the complete documentation index, see [llms.txt](https://ksmcclay.gitbook.io/no-code-computer-science/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ksmcclay.gitbook.io/no-code-computer-science/algorithms/search.md).

# Search

## What is a Search Algorithm?:face\_with\_monocle:

A Search Algorithm finds something.

![Claw Machine](/files/-MMbfr34GLuySIBUyT_z)

## :snail: Linear Search vs Binary Search :rocket:&#x20;

:snail:**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:scissors:&#x20;
* Matching a single sock to the pair in a pile of laundry :socks:&#x20;
* Checking out the old photo album with grandma :older\_woman:&#x20;

:rocket:**Binary Search** is an algorithm which continually splits an ordered list in half until the item is found.&#x20;

* Finding a specific page number in a book :book:&#x20;
  * 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:christmas\_tree:
  * Search by year
  * Search by month
  * Search by day

:snail:**Linear Search** vs:rocket:**Binary Search** in a heads up comparison on the same list.

```
Array:
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]

Goal:
Find the number 14

Linear Search:
1,2,3,4,5,6,7,8,9,10,11,12,13,14

Binary Search:
10,15,14
```

## :cloud\_rain:BFS: Breadth First Search vs DFS: Depth First Search:cloud\_lightning:&#x20;

:cloud\_rain:**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

&#x20;:cloud\_lightning:**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**

```
        A Tree Data Structure
                Start
                  '
         -------------------
        '                   '
        *                   *
        '                   '
   ----------          ----------
  '          '        '          '
  *          *        *          *
  '          '        '          '
 ---        ---      ---        ---        
'   '      '   '    '   '      '   '
*   *      *   *    *   *      *   *
```

**BFS Example: first 8 nodes found**

```
        Breadth First Search
                  1
                  '
         -------------------
        '                   '
        2                   3
        '                   '
   ----------          ----------
  '          '        '          '
  4          5        6          7
  '          '        '          '
 ---        ---      ---        ---        
'   '      '   '    '   '      '   '
8   *      *   *    *   *      *   *
```

**DFS Example: first 4 nodes found**

```
          Depth First Search
                  1
                  '
         -------------------
        '                   '
        2                   *
        '                   '
   ----------          ----------
  '          '        '          '
  3          *        *          *
  '          '        '          '
 ---        ---      ---        ---        
'   '      '   '    '   '      '   '
4   *      *   *    *   *      *   *
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ksmcclay.gitbook.io/no-code-computer-science/algorithms/search.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
