{"id":1842,"date":"2019-04-04T18:25:10","date_gmt":"2019-04-04T18:25:10","guid":{"rendered":"https:\/\/andnewsindia.com\/?p=1842"},"modified":"2019-04-04T18:25:10","modified_gmt":"2019-04-04T18:25:10","slug":"difference-between-linear-search-and-binary-search","status":"publish","type":"post","link":"https:\/\/andnewsindia.com\/difference-between-linear-search-and-binary-search\/","title":{"rendered":"Difference Between Linear Search and Binary Search"},"content":{"rendered":"
Difference Between Linear Search and Binary Search<\/strong>: When it comes to the search operation in programming, two names come in mind. Linear search and binary search. Some people confuse in these terms. So let\u2019s see what are the difference between liner search and binary search?<\/p>\n Linear search is a simple searching algorithm. In this type of search, the searching process occurs from one item after the other. Means this search algorithm checks every item present and checks for a matching item on that.<\/p>\n Searching starts from the first item. If the item does not match, then it moves to the second item and does the same. It continues the same process until it finds the match.<\/p>\n In a linear search, the efficiency of the algorithm determined by the number of comparisons to search an element or time consumption in the process. If the element we are searching for, is in the first position of the data structure, then it requires only one comparison. In this case, the efficiency will be good because it takes less time to find the item. When the element we are searching for, is in the last position, then it requires an N number (number of data items) of comparisons to find the element.<\/p>\n The pseudocode of linear search algorithms look like this \u2013<\/p>\n procedure linear_search (list, value)<\/p>\n <\/p>\n for each item in the list<\/p>\n if match item == value<\/p>\n return the item’s location<\/p>\n end if<\/p>\n end for<\/p>\n end procedure<\/p>\n Linear search<\/strong><\/p>\n<\/td>\n Binary search<\/strong><\/p>\n<\/td>\n<\/tr>\n In a linear search, it scans one item at a time in a sequential basis without jumping to any item<\/p>\n<\/td>\n Input data need not to be sorted in linear search<\/p>\n<\/td>\n Input data needs to be sorted in before starting the binary search<\/p>\n<\/td>\n<\/tr>\n Also called sequential search<\/p>\n<\/td>\n Also called logarithmic search or half-interval search<\/p>\n<\/td>\n<\/tr>\n Time complexity is O(N)<\/p>\n<\/td>\n Time complexity is O(log2N)<\/p>\n<\/td>\n<\/tr>\n Best case is to find the element in the first position<\/p>\n<\/td>\n Best case is to find the element in the middle position<\/p>\n<\/td>\n<\/tr>\n Take more time<\/p>\n<\/td>\n Take less time<\/p>\n<\/td>\n<\/tr>\n Less efficient<\/p>\n<\/td>\n More efficient<\/p>\n<\/td>\n<\/tr>\n More complex<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n Linear search and binary search both are used to search an element in a data structure such as an array. Of course, binary search is more efficient than the linear search but the elements should be shorted in the array. These are some of the difference between linear search and binary search you may consider. Depending on the requirements, you can choose one of them.<\/p>\n","protected":false},"excerpt":{"rendered":" Difference Between Linear Search and Binary Search Difference Between Linear Search and Binary Search: When it comes to the search operation in programming, two names come in mind. Linear search and binary search. Some people confuse in these terms. So let\u2019s see what are the difference between liner search and binary search? What is Linear […]<\/p>\n","protected":false},"author":1,"featured_media":1844,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[123,389,399],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/andnewsindia.com\/wp-json\/wp\/v2\/posts\/1842"}],"collection":[{"href":"https:\/\/andnewsindia.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/andnewsindia.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/andnewsindia.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/andnewsindia.com\/wp-json\/wp\/v2\/comments?post=1842"}],"version-history":[{"count":0,"href":"https:\/\/andnewsindia.com\/wp-json\/wp\/v2\/posts\/1842\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/andnewsindia.com\/wp-json\/wp\/v2\/media\/1844"}],"wp:attachment":[{"href":"https:\/\/andnewsindia.com\/wp-json\/wp\/v2\/media?parent=1842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/andnewsindia.com\/wp-json\/wp\/v2\/categories?post=1842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/andnewsindia.com\/wp-json\/wp\/v2\/tags?post=1842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}What is Linear search?<\/h2>\n
\n\n
\n \n \n \n \n Binary search divides the whole array to half and starts searching. If not found then it searches in the left or right sub-array<\/td>\n<\/tr>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n Less complex<\/td>\n \n Conclusion<\/h3>\n