Skip to content

Latest commit

 

History

History

Searching

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Searching

Linear Search

Algorithm:

linearSearch(array, size, element):
    for i -> size
        if array[i] = element
            return i
    return -1

Complexity:

  • Time:
    • Worst Case: formula
    • Average Case: formula
    • Best Case: formula
  • Space:
    • Worst Case: formula

Binary Search

Algorithm:

binarySearch(array, size, element):
    start = 0
    end = size - 1
    while (start <= end){
        mid = start + (end - start) / 2;
        if (array[mid] == element){
            return mid
        }
        if (array[mid] < element){
            start = mid + 1
        }
        else {
            end = mid - 1;
        }
    }
    return -1

Complexity: