Learn Binary Search in 10 minutes 🪓

preview_player
Показать описание
binary search algorithm tutorial example explained

#binary #search #algorithm

// binary search = Search algorithm that finds the position
// of a target value within a sorted array.
// Half of the array is eliminated during each "step"

music credits 🎼 :
===========================================================
Creative Commons — Attribution-ShareAlike 3.0 Unported— CC BY-SA 3.0
===========================================================
Рекомендации по теме
Комментарии
Автор

import java.util.Arrays;

public class Main{

// binary search = Search algorithm that finds the position
// of a target value within a sorted array.
// Half of the array is eliminated during each "step"

public static void main(String[] args) {

int array[] = new
int target =

for(int i = 0; i < array.length; i++) {
array[i] = i;
}

//int index = Arrays.binarySearch(array, target);
int index = binarySearch(array, target);

if(index == -1) {
System.out.println(target + " not found");
}
else {
found at: " + index);
}

}

private static int binarySearch(int[] array, int target) {

int low = 0;
int high = array.length - 1;

while(low <= high) {

int middle = low + (high - low) / 2;
int value = array[middle];

" + value);

if(value < target) low = middle + 1;
else if(value > target) high = middle - 1;
else return middle; //target found
}

return -1;
}
}

BroCodez
Автор

I cannot believe how simple you made this. Every other video I saw eventually caused confusion. You clearly stated the concept first, where every thing that followed fell into place. This has been my experience in your other videos learning C#, and Python programming languages. God Bless You.

luismatos
Автор

Had a task with binary search.
Didn't understand -> open Bro Code Data Structures and Algorithms Playlist -> Found Binary Search -> Understood :D

heayyyyyyy
Автор

U are a god. I have used your tutorials since I started programming in april 2022... You have no idea how much you have helped me out man!! all for free!!!!

quinnmurphy
Автор

I hope that you can do some tutorials about every data Structure or techniques... I love they way you teach <3

habboholoful
Автор

Hey, bro. I just wanted to let you know that when it comes to teaching and explaining code, you are the best of this world. I am not exaggerating; I have watched hundreds of channels, and taken tens of paid online courses, no one is as nearly as good as you.

paultvshow
Автор

am officially done with "programming" but I will keep my subscription ❤

ethanalkout
Автор

this was actually really nice. itd be nice if you had even more stuff on datastructures and algos so i can become an algo chad

monemperor
Автор

this channel should have more than a million subscribers!!!

sanjana
Автор

You do an outstanding job of making the content easy to understand. You have helped me get through my class this quarter thank you!

tiavanderyacht
Автор

A hi from "Brazil' Bro, code! You are the guy.

carlosramon
Автор

well, you're an absolute legend
that's all I got to say

simplifiable
Автор

Your way of teaching is just fantastic bro🤩. You are the best. Love from India❤

freakintruder
Автор

Thank you so much for making such a great content <3.

aer
Автор

This example gave me a much better understanding of how searching works.

prizepig
Автор

Thank you so much Lord Bro Code. I was able to finish my Java final semester project thanks to you sir.

theuberman
Автор

commenting for the algorithm
love your stuff my guy 👍

RinInABin
Автор

Amazing video bro, Thank You so much.

sriharivernekar
Автор

Jesus Christ, how such a great content is such an underrated... Horrifically underrated.
P. S. : this English... I'VE BEEN WAITING FOR THE NON INDIAN CODE CONTENT FOR A YEARS...

mykyta
Автор

You saved the day, AGAIN !
Thanks so much bro, take care of you ! :)

Remolhunter