+ 4
What is difference between binary and linear search? And which one is best to use in programming and why and give me some tips
6 Réponses
+ 9
https://techdifferences.com/difference-between-linear-search-and-binary-search.html
https://stackoverflow.com/questions/700241/what-is-the-difference-between-linear-search-and-binary-search
https://www.geeksforgeeks.org/linear-search-vs-binary-search/
Input data needs to be sorted in Binary Search and not in Linear Search
Linear search does the sequential access whereas Binary search access data randomly.
Time complexity of linear search -O(n) , Binary search has time complexity O(log n).
Linear search performs equality comparisons and Binary search performs ordering comparisons
+ 5
To clear your concept on this topic, you should follow some "Discrete mathematics" books.
*Discrete Mathematics and Its Applications Seventh Edition
by Kenneth H Rosen
You can try this one.
+ 4
Linear search: You go through each element until you find the one you're searching for. Let's say you have an array and search element x, so you start at element 0 and progress until you find x or reach the end.
In binary search you have a tree structure. Imagine having integers and your root is 5. Now this 5 can have two child nodes - the left one is smaller than 5, the right one is bigger than 5. Now you want to go to element 7, so instead of going through all elements of the tree, you start by 5, then go to the right child node. You skip the left node and thereby skip all elements lower than 5 which decreases the search time in the worst case.
I'm not good at examples, but I hope it's a bit clearer now.
+ 1
Instead of starting from the first element, your starting element can be anywhere. Instead of going through there in a 1 long line, each element has 0, 1 or 2 short paths.
While linear search is basically a for-loop, a binary search tree has a more complex algorithm that chooses the correct path through the tree.
0
well i m not understand yet
0
speed. the main difference is speed of search