Skip to content

Commit cac1bf4

Browse files
authored
Added Testing Table to Linear Search Project (#360)
* Added testing table to linear search * Update index.md
1 parent bd24867 commit cac1bf4

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

projects/linear-search/index.md

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22
title: Linear Search in Every Language
33
layout: default
44
date: 2019-10-17
5-
last-modified: 2020-05-02
5+
last-modified: 2020-10-15
66
featured-image:
77
tags: [linear-search]
88
authors:
99
- frankhart2017
10+
- the_renegade_coder
1011
---
1112

1213
This article introduces Linear Search which is the simplest search algorithm.
1314

1415
## Description
1516

16-
Linear search is quite intuitive, it is basically searching an element in an array by traversing the array from the beginning to the end and comparing each item in the array with the key. If a particular array entry matches with the key the position is recorded and the loop is stopped. The algorithm for this is:
17+
Linear search is quite intuitive, it is basically searching an element in an array by traversing
18+
the array from the beginning to the end and comparing each item in the array with the key. If a
19+
particular array entry matches with the key the position is recorded and the loop is stopped.
20+
The algorithm for this is:
1721

1822
1. Define a flag (set it's value to 0) for checking if key is present in array or notation.
1923
2. Iterate through every element in array.
2024
3. In each iteration compare the key and the current element.
2125
4. If they match set the flag to 1, position to the current iteration and break from the loop.
22-
5. If entire loop is traversed and the element is not found the value of flag will be 0 and user can notified that key is not in array.
26+
5. If entire loop is traversed and the element is not found the value of flag will be 0 and user
27+
can notified that key is not in array.
2328

2429
### Performance
2530

@@ -43,7 +48,7 @@ Linear search is not efficient for large arrays, but for relatively smaller arra
4348
<br>key != array[i]
4449

4550
<b>Iteration 2</b>
46-
<br>array[i] = array[i] = 2
51+
<br>array[i] = array[1] = 2
4752
<br>key = 3
4853
<br>key != array[i]
4954

@@ -57,38 +62,41 @@ Linear search is not efficient for large arrays, but for relatively smaller arra
5762

5863
## Requirements
5964

60-
Write a sample program that takes a key in the format 3 and a list of numbers in the format "1, 2, 3, 4, 5".
65+
Write a sample program that takes a list of numbers (e.g. "1, 2, 3, 4, 5") and a key (e.g. "3").
6166

62-
### C++ Program
63-
64-
```console
65-
$ cd archives/c/c-plus-plus/
66-
$ g++ -o linear-search linear-search.cpp
67-
$ ./linear-search 3 "1, 2, 3, 4, 5"
68-
3 found at position 2.
6967
```
70-
71-
### Python Program
72-
73-
```console
74-
$ cd archives/p/python/
75-
$ python linear-search.py 6 "1, 2, 3, 4, 5"
76-
6 not found in the array .
68+
linear-search.lang "1, 4, 2, 9" "3"
7769
```
7870

7971
In addition, there should be some error handling for situations where the user
8072
doesn't supply correct input.
8173

74+
## Testing
75+
76+
| Description | List Input | Target Integer Input | Output |
77+
|---------------------------|--------------|----------------------|---------|
78+
| No Input | | | error\* |
79+
| Missing Input: List | `1, 2, 3, 4` | | error\* |
80+
| Missing Input: Target | `""` | `5` | error\* |
81+
| Sample Input: First True | `1, 3, 5, 7` | `1` | `true` |
82+
| Sample Input: Last True | `1, 3, 5, 7` | `7` | `true` |
83+
| Sample Input: Middle True | `1, 3, 5, 7` | `5` | `true` |
84+
| Sample Input: One True | `5` | `5` | `true` |
85+
| Sample Input: One False | `5` | `7` | `false` |
86+
| Sample Input: Many False | `1, 3, 5, 6` | `7` | `false` |
87+
88+
\*The error string to print: `Usage: please provide a list of integers ("1, 4, 5, 11, 12") and the integer to find ("11")`
89+
8290
## Articles
8391

8492
{% include article_list.md collection=site.categories.linear-search %}
8593

8694
## Further Readings
8795

88-
- [Linear search on Wikipedia][1]
89-
- [A beginner's guide to Big O notation- Rob Bell][2]
90-
- [Big O notation on Wikipedia][3]
96+
- [Linear search on Wikipedia][linear-search-wiki]
97+
- [A beginner's guide to Big O notation- Rob Bell][big-o-notation-guide]
98+
- [Big O notation on Wikipedia][big-o-notation-wiki]
9199

92-
[1]: https://en.wikipedia.org/wiki/Linear_search
93-
[2]: https://rob-bell.net/2009/06/a-beginners-guide-to-big-o-notation/
94-
[3]: https://en.wikipedia.org/wiki/Big_O_notation
100+
[linear-search-wiki]: https://en.wikipedia.org/wiki/Linear_search
101+
[big-o-notation-guide]: https://rob-bell.net/2009/06/a-beginners-guide-to-big-o-notation/
102+
[big-o-notation-wiki]: https://en.wikipedia.org/wiki/Big_O_notation

0 commit comments

Comments
 (0)