From a6f9448ef922843f061318d1cfcc7c62a5eafd33 Mon Sep 17 00:00:00 2001 From: Madhan M <54719274+CaptMadhan@users.noreply.github.com> Date: Fri, 1 Oct 2021 23:58:22 +0530 Subject: [PATCH] docs(en): added linear-search (#503) --- docs/en/README.md | 1 + docs/en/Searching/Linear-Search.md | 64 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 docs/en/Searching/Linear-Search.md diff --git a/docs/en/README.md b/docs/en/README.md index 2d68cec6..aa1b5fd4 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -16,6 +16,7 @@ ## Searching - [Binary Search](./Searching/Binary-Search.MD) +- [Linear Search](./Searching/Linear-Search.md) ## Others diff --git a/docs/en/Searching/Linear-Search.md b/docs/en/Searching/Linear-Search.md new file mode 100644 index 00000000..1d4487ad --- /dev/null +++ b/docs/en/Searching/Linear-Search.md @@ -0,0 +1,64 @@ +# Linear Search + +**linear search**, also known as **Sequential search** is a method for finding an element within a list. A linear search sequentially checks each element of the list until it finds an element that matches the target value. If the algorithm reaches the end of the list, the search terminates unsuccessfully. +1. Time Complexity: O(n) +2. Space Complexity: O(1) +3. Applications: practical when the list has only a few elements when performing a single search in an unordered list. +4. Founder's Name: Anatole Beck and Donald J. Newman (1970) +Linear search is usually very **simple to implement**. + +## Steps/Algorithm: +**Linear Search( Array A, Value x)** + +Step 1: Set i to 1 +Step 2: if i > n then go to step 7 +Step 3: if A[i] = x then go to step 6 +Step 4: Set i to i + 1 +Step 5: Go to Step 2 +Step 6: Print Element x Found at index i and go to step 8 +Step 7: Print element not found +Step 8: Exit + +## Pseudocode + +**procedure linear_search (list, value)** +``` +start procedure + for each item in the list + if match item == value + return the item's location + end if + end for +end procedure +``` + +## Example +Input A[]: **10,20,30,40,50,60,70,80** + +Element to search: **50** + +Procedure: +Step 1: i = 0 +Step 2: Comparing A[i] and Element to search, if equal numbers return i, else i = i + 1. + **comparing 10 and 50 ->False**, i = i + 1 +Step 3: **comparing 20 and 50 ->False**, i = i + 1 +Step 4: **comparing 30 and 50 ->False**, i = i + 1 +Step 5: **comparing 40 and 50 ->False**, i = i + 1 +Step 6: **comparing 50 and 50 ->True -> Element Found** + +Output: i + +## Implementation + +- [C](https://github.com/MakeContributions/DSA/blob/main/algorithms/C/searching/linearsearch.c) +- [C++](https://github.com/MakeContributions/DSA/blob/main/algorithms/CPlusPlus/Searching/linear-search.cpp) +- [CSharp](https://github.com/MakeContributions/DSA/blob/main/algorithms/CSharp/src/Search/linear-search.cs) +- [Go](https://github.com/MakeContributions/DSA/blob/main/algorithms/Go/searching/linear-search.go) +- [Java](https://github.com/MakeContributions/DSA/blob/main/algorithms/Java/searching/linear-search.java) +- [JavaScript](https://github.com/MakeContributions/DSA/blob/main/algorithms/JavaScript/src/searching/linear-search.js) +- [Python](https://github.com/MakeContributions/DSA/blob/main/algorithms/Python/searching/linear_search.py) + +## Video URL + +[Watch Linear Search Implementation](https://www.youtube.com/watch?v=4GPdGsB3OSc) +