Skip to main content

List Search

Well Hello there!!
From this blog myself would love to go with List search algorithms.

What are they ?

  • Linear Search
  • Binary Search
At the end of this Blog you will able to gain the knowledge about these two searching algorithms perfectly.

Let's go deep then !

Linear Search 
This algorithm is also known as sequential search when it's comes to the programming.
     "Linear Search is an algorithm for searching through elements of an array"

Let's try searching for the number 6.(Our objective is equals to Find 6)




First we examine the left most number in the array.In this Example it's 3.
We compare it with 6,and if it matches, the search ends. If it doesn't match we examine the next number to the right.In this case 9 is the next number.
                                     We repeat this comparisons until the 6 is found.




                                               We found the 6, so the search ends
As you can see, linear search is a simple technique for doing repeated comparisons in order from the beginning.
When there's a lot of data, the number of comparisons increases,and it takes more time.
This chapter concludes the explanation of linear search.




Binary Search 

"Binary Search is an algorithm for searching through elements of a presorted array".


                                                                 My objective is to find 6
                   First, we look at the number in the center of the array. In this case it's 5.
We compare 5 to the number 6 that we're searching for.Because 5 is less than 6, we know that                                                        the number 6 is to the right of 5.

                          From the Candidates, we remove numbers that are no longer needed.

                      Again we look at the number in the center of the remaining array. This time it's 7

            We compare 7 to 6. Because 6 is less than 7, we know that the number 6 is to the left of 7.


                             From the candidates, we remove numbers that are no longer needed.

                           We look at the number in the center of the array. This time it's 6.
                                      6=6 , so we found the number we were looking for.

In this way, we see that binary search makes use of a presorted array and continuously halves the numbers to search through, allowing it to search for numbers efficiently.
This chapter concludes the explanation of Binary Search.

Comments

Popular posts from this blog

Ruby on Rails Tutorial

Ruby on Rails Introduction  Hi all I,m here with a new article actually It's trending laguage for you all .Invented in Japan. That means it's very active language. Also it's  need some theory parts to understand these things very well so i will go through by explaining them simply. What is Ruby? Before we Ride on Rails , let us recapitulate a few points of ruby, which is the base of Rails. Ruby is the successful combination of Smalltalk's conceptual elegance python's ease of use and learning and perl's pragmatism Ruby is   A high level programming language. Interpreted like Perl, Python , Tcl/Tk. Object oriented like Smalltalk, Eiffel, Ada ,Java Why Ruby? Ruby originated in japan and now it is gaining popularity in US and Europe  as well. The following factors contribute towards  its popularity. Easy to learn Open source(very liberal license) rich libraries very easy to extend  Truly Object Oriented Less coding with f...

Euclidian Algorithm(Math)

Hi all ! I,m here again with some interesting article. It's not about programming or databases this time. It's algorithm. Actually It's Math. We all know it as Euclidian Algorithm(Euclid in Math). Let's start this then !!! The "Euclidian algorithm" is an algorithm that finds the greatest common divisor of 2 numbers.Discovered by Euclid in the mid 4th century BC, it's referred to as the world's oldest algorithm. As an example, let's consider the largest common divisor of 1112 and 695. With the usual method, we factorize the 2 numbers into prime numbers. and the greatest common divisor(GCD) from the prime numbers they share. Now we know that the greatest common divisor for 1112 and 695 is 139. However, with this method, the larger the 2 numbers get, the more difficult prime factorization becomes.With Euclidian Algorithm, we can find greatest common divisors more efficiently. Before we Enter an expla...

Quick Tutorial with Pedometer

For a better start i'm gonna go through some points Arduino uno(with connecting cable) Accelerometer Jumper Cables Bouth & Pb (since i,m a chemistry student)                                                               Ok here we go!  I hope you all familiar with what above mention with the points. If not quickly follow me whatever the social media i mentioned in my blog i'm willing to help you. First of all i would like to introduce Arduino Uno here. This is a simple picture of it. as i mention in the picture arduino uno consists with digital pins & power pins. Accelerometer is the sensor what we going to work with now.It will look like this.     in this picture it's just a sensor with holes. to fill with that up you gonna need headers(male/female). Probably now you need your bo...