Comparisons between linear and binary search, Data Structure & Algorithms

Assignment Help:

Comparative Study of Linear and Binary Search

Binary search is lots quicker than linear search. Some comparisons are following:

NUMBER OF ARRAY ELEMENTS EXAMINED

array size   |     linear search    binary search

                  |        (avg. case)    (worst case)

--------------------------------------------------------

8                    |        4                  4

128                |       64                  8

256                |      128                9

1000              |      500               11

100,000           |    50,000            18

A binary search on an array is O(log2 n) because at each test, you can "throw out" one half of the search space or array while a linear search in an array is O(n).

It is noteworthy that, for extremely small arrays a linear search can prove quicker than a binary search. Though, as the size of the array to be searched increases, the binary search is the clear winner in terms of many comparisons and therefore total speed.

Still, the binary search has some disadvantage. First, it needs that the data to be searched be in sorted order. If there is just one element out of order within the data being searched, it can throw off the entire process. While presented with a set of unsorted data, the efficient programmer has to decide whether to sort the data & apply a binary search or simply apply the less-efficient linear search. Is the cost of sorting the data is worth the raise in search speed gained along with the binary search? If you are searching only once, then it is possibly to better do a linear search in most cases.


Related Discussions:- Comparisons between linear and binary search

Convert graph into tree, How can we convert a graph into a tree ? Do we hav...

How can we convert a graph into a tree ? Do we have any standardized algorithm for doing this?

Explain the arrays in ruby, Explain the Arrays in Ruby Ruby arrays are ...

Explain the Arrays in Ruby Ruby arrays are dynamic arrays which expand automatically whenever a value is stored in a location beyond current end of the array. To the programmer

Program to manipulate the data structure, Data Structure and Methods: ...

Data Structure and Methods: Build an array structure to accomodate at least 10 elements. Provide routines for the following: An initializer. A routine to populate (

R. Studio, I need a person who has a good background in using R. Studio? I...

I need a person who has a good background in using R. Studio? In adition, a person who is good in using algorithms.

Write the algorithm to find input and output value, This algorithm inputs 5...

This algorithm inputs 5 values and outputs how many input numbers were positive and how many were negative. Data to be used: N = 1, -5, 2, -8, -7

If else, design algorithm and flow chart that computes the absolute differe...

design algorithm and flow chart that computes the absolute difference of two values x and y

Adjacency matrix of an undirected graph, 1) What will call a graph that hav...

1) What will call a graph that have no cycle? 2) Adjacency matrix of an undirected graph is------------- on main diagonal. 3) Represent the following graphs by adjacency matr

Best case, Best Case: If the list is sorted already then A[i] T (n) = ...

Best Case: If the list is sorted already then A[i] T (n) = c1n + c2 (n -1) + c3(n -1) + c4 (n -1)  = O (n), which indicates that the time complexity is linear. Worst Case:

Sparse matrix, Q. Define a sparse matrix. Explain different types of sparse...

Q. Define a sparse matrix. Explain different types of sparse matrices? Show how a triangular array is stored in memory. Evaluate the method to calculate address of any element ajk

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd