Linear and
Binary search
Título 1
Título 2
Subtítulo
What is linear and binary search?
Both linear and binary search are used for finding a value within a list. Although they are used for the same, their way of working is really different
Linear Search
Linear search, is to search for a value among a list of values which may be ordered from highest to lowest or vice versa, or may be unordered. What this algorithm does is to search for the expected value, checking value by value in the list until it finds it. This algorithm is easy to understand and can be related to many everyday things.
How to use it
Linear search is really easy to use and understand, here's an exampleLet's say we want to get index 4 (5), the only thing we'll have to do is check every value starting from index 0 until we find the value desired
How we use linear search?
Linear search can be used with a simple code line. But aside of programming, how do we use linear search in our days? Some examples may be, opening a book, looking for someone's name in files and way more.
Questions
Questions
Advantages of linear search
The linear search is a easy tool to find values, easy to write and understand, but it may be a very slow method to find a value, and that is a very big disadvantage as there are more efficient ways to find values in a list.
Binary search
The binary search is the other algorithm for searching a value within a list of value. As in the linear search, the binary search can search for a value in a list sorted from highest to lowest and vice versa, but not like linear search, the binary search only works with ordered list.
But how does it work?
Once we have the value, we will divide it by two, so we can get the "mid" which in this case is 3.5
The way the binary search works is by adding the the first and last values of the array (or list) and dividing them by 2, here's and example.
Lets say that in this array we want to get the value 26
So what we are going to do is add up the first and last value of the list (0 and 7) which will be called "low" and "high"
Once we already have the mid, which is 3.5 we're going to round it to the lowest number which is 3, now we check the value on the index (index is the box in which the value is stored), which is 14, so we see that 26>14 which means that the result is on the right side of the array.
Now we can see that the mid is 5, remember that the number is always rounded to the lowest. The index for 5 is 31, and 31>26. Now we'll get rid of that side
Now we're going to repeat the same process, we'll take the low and high, add them up and divide by two to get the mid
And now we can see that we arrived to the desired value
How is binary search used?
- Binary search is used when we want to find something in a large array of values, like a dictionary.
- Binary search can be used as a building block for more complex algorithms used in machine learning, such as algorithms for training neural networks or finding the optimal hyperparameters for a model.
- It can be used for searching in computer graphics such as algorithms for ray tracing or texture mapping.
- It can be used for searching a database.ase.
Advantages of binary search
- Binary search is faster than linear search, especially for large arrays.
- More efficient than other searching algorithms with a similar time complexity, such as interpolation search or exponential search.
- Binary search is well-suited for searching large datasets that are stored in external memory, such as on a hard drive or in the cloud.
Disadvantages
Although the binary search is a really useful tool, it still has its disadvantages such as:
- The array should be sorted.
- Binary search requires that the data structure being searched be stored in contiguous memory locations.
- Binary search requires that the elements of the array be comparable, meaning that they must be able to be ordered.
Questions
Questions
Questions
Binary or linear?
To determine which one is better we must compare their characteristics
Binary Linear
FasterUseful in large arrays Not so eays to understand
SlowerUseful in shorter arrays Easy to understand
VS
Final statement
Although both have their pros and cons, is not possible to determine which one is better over the other, as different situations may present and depending, linear or binary maybe be more useful
Thank you!
We hope you understand our topic "Linear and binary search"
Feel free to ask any questions
Mauricio Ruiz & Adrian Chaidez
Linear and binary presentation
Miniluis 21
Created on February 6, 2024
By Mauricio Ruiz & Adrian Chaidez
Start designing with a free template
Discover more than 1500 professional designs like these:
View
Psychedelic Presentation
View
Modern Presentation
View
Relaxing Presentation
View
Chalkboard Presentation
View
Visual Presentation
View
Terrazzo Presentation
View
Halloween Presentation
Explore all templates
Transcript
Linear and
Binary search
Título 1
Título 2
Subtítulo
What is linear and binary search?
Both linear and binary search are used for finding a value within a list. Although they are used for the same, their way of working is really different
Linear Search
Linear search, is to search for a value among a list of values which may be ordered from highest to lowest or vice versa, or may be unordered. What this algorithm does is to search for the expected value, checking value by value in the list until it finds it. This algorithm is easy to understand and can be related to many everyday things.
How to use it
Linear search is really easy to use and understand, here's an exampleLet's say we want to get index 4 (5), the only thing we'll have to do is check every value starting from index 0 until we find the value desired
How we use linear search?
Linear search can be used with a simple code line. But aside of programming, how do we use linear search in our days? Some examples may be, opening a book, looking for someone's name in files and way more.
Questions
Questions
Advantages of linear search
The linear search is a easy tool to find values, easy to write and understand, but it may be a very slow method to find a value, and that is a very big disadvantage as there are more efficient ways to find values in a list.
Binary search
The binary search is the other algorithm for searching a value within a list of value. As in the linear search, the binary search can search for a value in a list sorted from highest to lowest and vice versa, but not like linear search, the binary search only works with ordered list.
But how does it work?
Once we have the value, we will divide it by two, so we can get the "mid" which in this case is 3.5
The way the binary search works is by adding the the first and last values of the array (or list) and dividing them by 2, here's and example.
Lets say that in this array we want to get the value 26
So what we are going to do is add up the first and last value of the list (0 and 7) which will be called "low" and "high"
Once we already have the mid, which is 3.5 we're going to round it to the lowest number which is 3, now we check the value on the index (index is the box in which the value is stored), which is 14, so we see that 26>14 which means that the result is on the right side of the array.
Now we can see that the mid is 5, remember that the number is always rounded to the lowest. The index for 5 is 31, and 31>26. Now we'll get rid of that side
Now we're going to repeat the same process, we'll take the low and high, add them up and divide by two to get the mid
And now we can see that we arrived to the desired value
How is binary search used?
Advantages of binary search
Disadvantages
Although the binary search is a really useful tool, it still has its disadvantages such as:
Questions
Questions
Questions
Binary or linear?
To determine which one is better we must compare their characteristics
Binary Linear
FasterUseful in large arrays Not so eays to understand
SlowerUseful in shorter arrays Easy to understand
VS
Final statement
Although both have their pros and cons, is not possible to determine which one is better over the other, as different situations may present and depending, linear or binary maybe be more useful
Thank you!
We hope you understand our topic "Linear and binary search"
Feel free to ask any questions
Mauricio Ruiz & Adrian Chaidez