Binary Search

Binary Search is a searching algorithm for sorted lists, and it works by comparing the search key value with the key value of the middle element of the list. If the keys match, then a matching element has been found and its index, or position, is returned. Otherwise, if the search key is less than the middle element’s key, then the algorithm repeats its action on the sublist to the left of the middle element or, if the search key is greater, on the sublist to the right. If the remaining list to be searched is empty, then the key value is not present in the list.

[Example] [Example]
[Resource] [Resource]

Performance
Worst case performance O(log n)
Best case performance Ω(1)
Average case performance O(log n)

Step by Step

Sequential Search (Linear Search)

In computer science, Sequential Search(linear search) is a searching algorithm that checks each element in sequence until the desired element is found or the list is exhausted.

[Example] [Example]
[Resource] [Resource]

Performace
Worst case scenario O(n)
Best case scenario Ω(1)
Average case scenario O(n)

Step by Step