Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions search/linear_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
* \param [in] size length of array
* \param [in] key key value to search for
* \returns index where the key-value occurs in the array
* \returns -1 if key-value not found
* @returns index of the key if found, otherwise -1
*/
int LinearSearch(int *array, int size, int key) {
/**
* Time Complexity: O(n)
* Space Complexity: O(1)
*/
int linearSearch(int *array, int size, int key) {
for (int i = 0; i < size; ++i) {
if (array[i] == key) {
return i;
Expand Down