Natives Daily
  • Home
  • Automotive
  • Business
  • Construction
  • E-commerce
  • Write For Us
  • Contact
No Result
View All Result
  • Home
  • Automotive
  • Business
  • Construction
  • E-commerce
  • Write For Us
  • Contact
No Result
View All Result
Natives Daily
No Result
View All Result
Home Computers and Technology

Binary Search Explained With Simple Examples

Lindsay by Lindsay
December 14, 2021
in Computers and Technology
0
What is binary search?
0
SHARES
31
VIEWS
Share on FacebookShare on Twitter

Binary search is an efficient and quick way to locate a target within a sorted array. It works on the principle “divide and conquer”. In today’s post, algo.monster will guide algorithm beginners to the world of binary search. To help you understand it better, we will explain with easy-to-understand examples.

First of all, as a search algorithm, to understand binary, let’s look at algorithms as a start.

Contents hide
1 How important are algorithms?
2 Introduction to binary search
3 The binary search algorithm
4 How does this search technique work?
5 What is the BST?
6 An example of the binary search algorithm
6.1 What’s the secret to this game?
7 Let’s look at another example of how to use binary search
8 Conclusion

How important are algorithms?

Algorithms are used in all aspects of our lives. Software, applications, frameworks, libraries, etc. All of these algorithms help solve problems and improve performance. These algorithms are often discussed in developer interviews to show developers how they think and handle logic.

For instance, a person who likes to play the guitar knows how to play some songs, but not much about music theory. Although it is not necessary to learn music theory before you can play an instrument, it will help you understand some important concepts. This will help you to understand the music and how to play it.

Also, this is true for developers and algorithms. It is possible to be a software developer without knowing about algorithms. Many people learn to program but don’t know how to use algorithms. However, knowing algorithms can help you think through code and solve problems.

Introduction to binary search

You should first explain that the main problem that we are trying to solve is to quickly search within a set of elements to find an element in a sorted array. Binary search trees are a smart way of representing the data in order to make it easy to perform such fast searches.

The binary search algorithm

Binary search is a simple search method that allows one to eliminate half the input data at each stage as being irrelevant. This helps narrow down the search results quickly. This can only happen if the input data is sorted. With each step, the set that one searches reduce to one-half of what it was, one-quarter, one-eighth, and so on. Using the binary search tree, it’s convenient to represent the data in halves.

What is binary search?

How does this search technique work?

Let’s say we are looking for a specific number among a few integers arranged in increasing order. Take the middle number and determine if it is greater or less than the one you are trying to find. If the number is larger, you can remove all elements from the ‘left’. All elements are guaranteed to be smaller so your number won’t be included in this set. You can also eliminate the right. You now have one-half of the original set to search in. Then, you can continue the search with the reduced set. Continue doing this until you get the number you want.

What is the BST?

This binary search tree (BST) represents these sorted numbers in an arrangement that looks like a tree. Every element stores the data associated with it and points to two branches. The one to the left contains only numbers less than the element while the one to the right contains only numbers greater.

This property applies to every element in the tree representation. In fact, during the binary search process, at each step, you can just move to one half, the right or left. This structure is appropriately named the ‘binary search tree’. It is a ‘tree-shaped structure that can be used to ‘search’ in ‘half’ at a given time.

An example of the binary search algorithm

Suppose we play a game of guessing numbers. I imagine a number between 1 to 80 for you to guess. You guess the number in the shortest number of steps. And I will also tell you to go lower or higher if you don’t get it right.

How can you get the right answer quickly? Simple:

There are 80 possible numbers at the beginning. You can guess the middle number 40 first. If I say “go higher”, that means the target is between 41 and 80.

The middle value of the new range is 60. Pick this one this time.

When I say “go lower”. Then, any number from 41 to 59 could be the number you wrote.

Similarly, you choose 50.

Me: “go higher.” This means that your choices are among the numbers from 50 to 60. So, guess what, your next step is 55, right? Suppose 55 is my number, then it’s the end of the game.

What’s the secret to this game?

You apply this strategy until you reach the desired number. By using this method, you should be able, during each guess, to reduce the range of possible guesses by half. You will eventually narrow it down to one left.

In fact, this is the basic idea of binary search. The name “binary” which means two, refers to how binary searches work. To locate the target, go to the higher half or to the lower half.

 Let’s look at another example of how to use binary search

If you want to look for the word “binary search” in an unlabeled dictionary. Suppose each letter has a section that is exactly the same size.

Although you know the alphabetical order of the dictionary, you don’t know which page it is. Open the dictionary to the middle, at M. Next, you will divide the left section into A-F, G-M, and then continue the process within the B section until “binary search” is found.

In fact, we do it all the time when looking up a new word. You automatically open the dictionary approximately in the middle. Or if the word begins with O, you go the higher half. Which means you don’t go through the lower half.

Conclusion

Algorithms play an important role in our lives. They are responsible for sending instructions to the computers and telling them what to do. Algorithms are a way to improve logic, think more clearly, find the best solution for a particular problem, and consider other approaches. And binary search can be extremely useful and efficient when it comes to a large database.

Tags: binary searchsearch algorithms
Lindsay

Lindsay

Related Posts

Computers and Technology

Amber LED Lights: Creating a Relaxing Ambiance for Any Occasion

September 20, 2023
Computers and Technology

Linear Switches Demystified: How They Work and Why They Matter

September 11, 2023
Computers and Technology

Xcel – The Answer to Your Inquisitive Mind

September 6, 2023
Next Post
The Benefits of Body Lotion

The Benefits of Body Lotion

gifts for girlfriend

Special Gift For Girlfriend: This Is what Lovers Do

Top Food Delivery Apps

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

5 Steps to Start an Online Custom T-shirt Business

2 years ago

Top Reasons That Make Cold-Formed Steel an Ideal Building Material

2 years ago

Rug Cleaning – How to Save Yourself Time and Money With the Right Rug

1 year ago
Flat Glass Market

Global Flat Glass Market To Be Driven By Demand From Increasing Product Demand In Automotive And Construction Industries In The Forecast Period Of 2021-2026

1 year ago

Categories

  • Animals
  • App Development
  • Arts and Entertainment
  • Audio
  • Automotive
  • Business
  • Buy and Sell
  • Celebrities
  • Clothing
  • Communications
  • Computers and Technology
  • Construction
  • Culture
  • Designing
  • Digital Marketing
  • E-commerce
  • Education
  • Electronics
  • Fashion
  • Finance
  • Food and Drink
  • Footwear
  • Gadgets
  • Gaming
  • Graphics Designing
  • Health
  • Home and Family
  • Home Based Business
  • Home Improvement
  • Home Loan
  • Insurance
  • Internet and Businesses Online
  • Jewellery
  • Jobs
  • Kids and Teens
  • Legal
  • Lifestyle
  • Loan
  • Movies
  • National
  • Nature
  • News
  • Opinion
  • politics
  • Products
  • Real Estate
  • Relationships
  • Resorts
  • Reviews
  • Self Improvement
  • SEO
  • Services
  • Social Media
  • Sports
  • Travel
  • Travel and Leisure
  • TV
  • Uncategorized
  • video
  • Web Design
  • Web Hosting
  • Women’s Interests
  • World
  • Writing and Speaking

Topics

12 month loans direct lenders assignment help business cash loans online Cenforce 100 cheap short term loans Construction custom boxes cách làm mặt nạ thiên nhiên cấp ẩm debit card loans digital marketing direct payday loan lenders education Erectile Dysfunction express loans fashion fast loans online fast loans uk Fitness Fleet Management Software GPS Tracking Software Health Healthcare home intsnta cash loans mặt nạ thiên nhiên cấp ẩm mặt nạ xóa thâm quầng mắt payday cash loans payday loan uk quick cash loans quick dission loans real estate same day loans direct lenders same day loans online same day payday loans seo short term loans short term loans direct lenders social media marketing Spirit Airlines Reservations Technology text loans tour travel web design
No Result
View All Result

Highlights

Supporting Causes that Matter: The Benefits of Regular Donating

Making a Case for Dental Implants: 7 Reasons to Bite the Bullet

Amber LED Lights: Creating a Relaxing Ambiance for Any Occasion

From Dated to Dynamic: Revolutionise Your Warehouse with Legacy Systems-WMS Integration

Lucky Cola

Easy Application: DIY Anime Car Decals for Enthusiasts

Trending

Business

How To Resolve business disputes with vendors

by sophiajames
September 24, 2023
0

Disputes with suppliers are almost unavoidable in the fast-paced world of business. These disputes can slow down...

Buy Socks Online: Your Ultimate Guide to Finding the Perfect Pair

September 23, 2023

The Organic Toothpaste Revolution: All-Natural Choices

September 21, 2023

Supporting Causes that Matter: The Benefits of Regular Donating

September 21, 2023

Making a Case for Dental Implants: 7 Reasons to Bite the Bullet

September 21, 2023
  • About
  • Cart
  • Checkout
  • Contact
  • Contact
  • Cookie Policy
  • Embeds
  • Galleries
  • Home 2
  • Home 3
  • Homepage – Big Slide
  • Homepage – Fashion
  • Homepage – Full Post Featured
  • Homepage – Infinite Scroll
  • Homepage – Less Images
  • Homepage – Loop
  • Homepage – Magazine
  • Homepage – Newspaper
  • Homepage – Random
  • Homepage – Sport
  • Homepage – Tech
  • InHype Shortcodes
  • Misc blocks
  • My account
  • Natives Daily
  • Natives Daily
  • Privacy Policy
  • Sample Page
  • Shop
  • Shortcodes
  • Single images
  • Typography
  • World news
  • Write For Us

© 2021 All rights reserved. Natives Daily

No Result
View All Result
  • About
  • Cart
  • Checkout
  • Contact
  • Contact
  • Cookie Policy
  • Embeds
  • Galleries
  • Home 2
  • Home 3
  • Homepage – Big Slide
  • Homepage – Fashion
  • Homepage – Full Post Featured
  • Homepage – Infinite Scroll
  • Homepage – Less Images
  • Homepage – Loop
  • Homepage – Magazine
  • Homepage – Newspaper
  • Homepage – Random
  • Homepage – Sport
  • Homepage – Tech
  • InHype Shortcodes
  • Misc blocks
  • My account
  • Natives Daily
  • Natives Daily
  • Privacy Policy
  • Sample Page
  • Shop
  • Shortcodes
  • Single images
  • Typography
  • World news
  • Write For Us

© 2021 All rights reserved. Natives Daily