How to Do a Binary Search in C# (Simple)

  Рет қаралды 3,557

Max O'Didily

Max O'Didily

Күн бұрын

How to Do a Binary Search in C#
Greetings, today I am here with how to code a Binary Search in C#.
A binary search is a search algorithm that is used to find the position of a target value within a sorted array or list. Here's how it works in a simple way:
#1 Start with a sorted array or list of elements.
#2 Set the lower and upper bounds of the search range. Initially, the lower bound is the first element of the array and the upper bound is the last element.
#3 Calculate the midpoint of the search range by taking the average of the lower and upper bounds: midpoint = (lower_bound + upper_bound) / 2.
#4 Compare the target value with the value at the midpoint of the search range.
#5 If the target value is equal to the midpoint value, then the search is successful and the position of the target value in the array is the midpoint index.
#6 If the target value is less than the midpoint value, then update the upper bound to be one less than the midpoint index and repeat steps 3-5 on the new search range.
#7 If the target value is greater than the midpoint value, then update the lower bound to be one more than the midpoint index and repeat steps 3-5 on the new search range.
#8 Repeat steps 3-7 until either the target value is found or the search range becomes empty (i.e., lower bound is greater than upper bound). If the search range becomes empty, then the target value is not present in the array.
Binary search works by repeatedly dividing the search range in half until the target value is found or the search range becomes empty. This makes binary search a very efficient algorithm for searching in large arrays or lists.
Thanks for watchig this C# tutorial on how to do a Binary Search.
Why not subscribe to keep notified when I upload?
tinyurl.com/Su...
How to Do a Binary Search in C#

Пікірлер: 8
@SABX-q9i
@SABX-q9i 11 ай бұрын
Very helpful and straight-to-the-point explanation, thank you!
@LeonTf2
@LeonTf2 6 ай бұрын
Thanks mate, so easy to understand, been struggling with this for a bit but you really made it easy to follow.
@makhmudtojiboev
@makhmudtojiboev 11 ай бұрын
Good explanation, thank you
@sentryicl
@sentryicl 11 ай бұрын
very helpful, thank you for this quick and informative tutorial!
@sibski8527
@sibski8527 10 ай бұрын
good video!
@sauravshrestha1890
@sauravshrestha1890 10 ай бұрын
What if there are even numbers of elements in an array
@Tylendel_
@Tylendel_ 26 күн бұрын
you prob found out, but it rounds down in C#
@Agnotke
@Agnotke 22 күн бұрын
/ returns a whole number.
Binary Search Algorithm in C#
17:06
Milan Jovanović
Рет қаралды 7 М.
Binary Search in Java - Full Simple Coding Tutorial
17:48
Coding with John
Рет қаралды 123 М.
How I Turned a Lolipop Into A New One 🤯🍭
00:19
Wian
Рет қаралды 13 МЛН
UFC 308 : Уиттакер VS Чимаев
01:54
Setanta Sports UFC
Рет қаралды 826 М.
Will A Basketball Boat Hold My Weight?
00:30
MrBeast
Рет қаралды 126 МЛН
Hash Tables in C# - How to use and when to use?
16:13
tutorialsEU
Рет қаралды 25 М.
5 - Binary Search Algorithm Code in C#
16:41
Venkat Marisetty
Рет қаралды 5 М.
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,8 МЛН
Linear Search Array C# 2022 (Step-By-Step Breakdown)
9:49
Teddy Smith
Рет қаралды 11 М.
The Dictionary Data Structure in C# in 10 Minutes or Less
10:20
IAmTimCorey
Рет қаралды 38 М.
Binary Search Tree implemented in C#
30:54
kc70
Рет қаралды 50 М.
Learn Binary Search in 10 minutes 🪓
10:04
Bro Code
Рет қаралды 119 М.
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Codebagel
Рет қаралды 427 М.
Binary Search Algorithm in C# - Learn to Search Collections efficiently!
6:11
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 723 М.
How I Turned a Lolipop Into A New One 🤯🍭
00:19
Wian
Рет қаралды 13 МЛН