Name : Usman Ahmad Siddiqui
Name : Usman Ahmad Siddiqui
Name : Usman Ahmad Siddiqui
Linear search
In computer science, a linear search or sequential search is a method for
finding an element within a list. It sequentially checks each element of the list until
a match is found or the whole list has been searched.
Start from the leftmost element of arr[] and one by one compare x with each
element of arr[]
If x matches with an element, return the index.
If x doesn’t match with any of elements, return -1
Advantages
The advantages of linear search
is its simplicity:
conceptually
it's extraordinarily
easy to understand
implementation-wise
Disadvantages
Binary search
In computer science, binary search, also known as half-interval search,
logarithmic search, or binary chop, is a search algorithm that finds the position of a
target value within a sorted array. Binary search compares the target value to the
middle element of the array.
Sentinel value
In computer programming, a sentinel value (also referred to as a flag value,
trip value, rogue value, signal value, or dummy data) is a special value in the
context of an algorithm which uses its presence as a condition of termination,
typically in a loop or recursive algorithm. For example, a loop may execute
while the value of a variable is not -1. Here -1 is the sentinel value.