Linear Search vs Binary Search

Linear 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
linear_search(arr, 3) # returns true
linear_search(arr, 9) #…



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store