Linear Search vs Binary Search
As a beginner programmer, conducting a linear search on an array is conceptually simple and straight-forward to implement. Let’s take a look at an arbitrary example code below. The code is written in Ruby, but the concept of a linear search is language-agnostic.
arr = [1, 2, 3, 4, 5, 6, 7, 8, 11]def linear_search(arr, val)
arr.each do |n|
return true if n == val
endlinear_search(arr, 3) # returns true
linear_search(arr, 9) #…