BFS Algorithm | Breadth First Search in Graph | BFS Traversal | BFS Graph | DSA-One Course #75

  Рет қаралды 89,736

Anuj Bhaiya

Anuj Bhaiya

Күн бұрын

Hey guys, In this video, We're going to learn how the Breadth-First Search Algorithm works and is Implemented.
Practice: www.geeksforge...
💸 Use coupon code ANUJBHAIYA on GeeksforGeeks to avail discounts on courses!
🥳 Join our Telegram Community:
Telegram channel: telegram.me/re...
Telegram group: telegram.me/ds...
🚀 Follow me on:
Instagram: / anuj.kumar.sharma
Linkedin: / sharma-kumar-anuj
Twitter: / realanujbhaiya
📚 Complete DSA Playlist: • DSA-One Course - The C...
Complete Android Development Playlist: • Android Development Tu...
Hashtags:
#anujbhaiya #dsaone
Tags:
bfs
bfs algorithm
breadth first search
bfs traversal
bfs graph
bfs and dfs
bfs dfs
breadth first search algorithm
bfs dfs in data structure
bfs in graph
bfs algoritması
bfs and dfs algorithm
dfs and bfs
dfs and bfs algorithm
graph bfs
bfs of graph
graph traversal in data structure
bfs in data structure
dfs bfs
graph data structure
graph traversal
dsa
bfs in java
anuj bhaiya java
breadth first traversal
bfs java
breadth first search algoritması
breath first search
dfs
bfs code
graph dsa
breadth first search in data structure
graph
graphs dsa
bfs algo
bfs algoritması in hindi
java anuj bhaiya
bfs in c
breadth-first search
dfs algoritması
graph in java
bfs implementation
breadth first search graph
bfs and dfs in graph
bfs in python
breadth first search java
anuj bhaiya dsa
anuj kumar sharma
dfs algorithm
dfs traversal
bfs c++
bfs in daa
bfs in graphs
breadth first search c++
depth first search algorithm
dsa one
graph in data structure
graphs
graphs in c++
bfs and dfs graph
bfs and dfs in data structure
bfs daa
bfs dsa
bfs traversal graph
bfs traversal of graph
breadth first search in artificial intelligence
data structures and algorithms
depth first search
dfs in graph
dsa by anuj bhaiya
graph in dsa
graphs in java
graphs java
anuj
anuj bhai
anuj dsa
bfs algoritm
bfs and dfs in data structures
bfs and dfs traversal
bfs in c++
bfs in ds
bfs in dsa
bfs of a graph
bfs python
bfs search
bfs traversal in graph
bfs tree
bfs vs dfs
breadth
breadth first search python
bredth first search
brute force
code with harry
codehelp
data structures
depth first search and breadth first search
depth-first search
dfs graph
dfs java
dijkstra's algorithm java
dsa anuj bhaiya
dsa course
dsa graph
dsa playlist
dsp anuj bhaiya
graph algorithms
graph bfs dfs
graph data structure java
graph dfs bfs
graph playlist
graph traversal bfs and dfs
graph traversals
hash table
internal working of hashmap in java
java brains
java collections
java dsa

Пікірлер: 70
@MithleshKumar-xq3qo
@MithleshKumar-xq3qo 2 жыл бұрын
First of all I am so sorry if I am wrong, but I have confusions, if your community accepts this comment . Then I would like to point out that there are some mistakes in this video. First your graph 123456 in this video that is not matching with first loop. First loop is initialised with 0 and graph is starts from 1 means adjancey List not confirm. Second in second loop get(u) where is "u" sir I think src will be there.
@MithleshKumar-xq3qo
@MithleshKumar-xq3qo 2 жыл бұрын
Sorry not "src" there will be "cur"
@manglaram2589
@manglaram2589 Жыл бұрын
@@MithleshKumar-xq3qo right
@RaviPatel-oe2yj
@RaviPatel-oe2yj 2 жыл бұрын
What is u??.. Function return value bhoolen and storing ans in int!!??
@inspirationinyou2811
@inspirationinyou2811 Жыл бұрын
Same doubt merko bhi hai bhai
@rahulsinghshekhawat2487
@rahulsinghshekhawat2487 Жыл бұрын
The Best playlist for DSA on KZbin. Thank you very much.
@himanshujakhmola5960
@himanshujakhmola5960 2 жыл бұрын
Anuj Bhaiya- kya always graph 1 se start hoga like 1,2,3,4,5,6 ya random or agar random no honge toh upr jo apne btaya dist[neibor] = dist[cur] + 1; toh agar cur is 15 hai or next 43 hai toh + 1 ka kya logic hoga means use kya hoga?? Anser krna Anuj Bhiya wrna Confusion rh jayega
@ayushdwivedi8309
@ayushdwivedi8309 2 жыл бұрын
Thank You So Much Bhayia for this awesome DSA playlist.. can you please complete it little quickly... totally dependent on this...
@Shruti-dj8zs
@Shruti-dj8zs 2 жыл бұрын
what is u in adj.get(u).get(i) ?
@aakashraj4142
@aakashraj4142 4 ай бұрын
Tell me too if u know
@RaviPrajapati-uy1wm
@RaviPrajapati-uy1wm 22 күн бұрын
@@aakashraj4142 in place of 'u' you can replace with 'cur'
@sekharsamanta6266
@sekharsamanta6266 3 ай бұрын
One question Anuj Bhaiya-- What is this 'u' in the code, not defined before
@RaviPrajapati-uy1wm
@RaviPrajapati-uy1wm 22 күн бұрын
in place of 'u' you can replace with 'cur'
@tech_wizard9315
@tech_wizard9315 2 жыл бұрын
Please make a 60day roadmap for DSA beginner who is working professional, a 60day roadmap to crack Microsoft linkedin level companies
@tejaskatkade6785
@tejaskatkade6785 2 жыл бұрын
graph ke component more than 1 honge to dist[] and pred[] array harbar set honge na to code fail karega shayad??
@manglaram2589
@manglaram2589 Жыл бұрын
bhaiya yha apne method bfs mnaya h and call dfs krre ho confusing hora h ye and wo boolean type h and ap int m return kra re ho
@sureshpathak2008
@sureshpathak2008 2 жыл бұрын
bfs code: public static boolean bfs(ArrayList adj, int src, int dest, int v, int pred[], int dist[]) { LinkedList queue = new LinkedList(); boolean visited[] = new boolean[v + 1]; for (int i = 0; i < v; i++) { visited[i] = false; dist[i] = Integer.MAX_VALUE; pred[i] = -1; } visited[src] = true; dist[src] = 0; queue.add(src); while (!queue.isEmpty()) { int cur = queue.remove(); for (int i = 0; i < adj.get(cur).size(); i++) { int neighbour = adj.get(cur).get(i); if (visited[neighbour] == false) { visited[neighbour] = true; dist[neighbour] = dist[cur] + 1; pred[neighbour] = cur; queue.add(neighbour); if (neighbour == dest) { System.out.println("Distance between source & destination: " + dist[dest]); return true; } } } } return false; }
@dooduboodu8416
@dooduboodu8416 2 жыл бұрын
thnx bro this cleared my doubt :- from did tht "u" variable come from
@ruchikabhandari2768
@ruchikabhandari2768 2 жыл бұрын
For loop should have i
@Riteshkumar-ih7fj
@Riteshkumar-ih7fj Жыл бұрын
@@ruchikabhandari2768 error... index out of bounds exception
@RajSingh-bb5uj
@RajSingh-bb5uj 2 жыл бұрын
really helpful thanks a lot bhaiya
@raishasingh8130
@raishasingh8130 2 жыл бұрын
thanks for this video.. can you please make one on flipkart runway competition? It is exclusively for females and will give internship opportunities to the winners.. I am in my 2nd year and really want to try my best for this competition.. plz guide
@yashi5698
@yashi5698 2 жыл бұрын
Bhaiya when will video on data analytics will come as I am from computer science background I have tried my best from last 1.5 years and still not get coding 🥲 I think I have not interest in it kindly make a video on what is carrier option other than coding in CS and roadmap to get it
@rownabdasgupta6006
@rownabdasgupta6006 2 жыл бұрын
code is wrong and we need bfs traversal not only dist[]
@Swabhimanc
@Swabhimanc Жыл бұрын
But sir. What is 'u'... Shouldn't it be adj.get(curr).get(i)
@aishwaryshukla8880
@aishwaryshukla8880 Жыл бұрын
yes its 'cur'. Bhaiya replied in one of the comments
@Swabhimanc
@Swabhimanc Жыл бұрын
Thanks Bhai.
@gamegem574
@gamegem574 2 жыл бұрын
Out of bound exception aaraha he bhaiya
@gitanjalikumari9262
@gitanjalikumari9262 2 жыл бұрын
please also show code in c++ if possible..it will be more helpful..but awesome explanation..thanks!
@meetsoni1938
@meetsoni1938 2 жыл бұрын
If we get the destination before going through each node in one component of graph then how can we find the no. Of components??
@rakshitraushan1650
@rakshitraushan1650 Жыл бұрын
u kidhar se aaya bhaiya
@angelaroy946
@angelaroy946 13 күн бұрын
can someone please clarify what is u here @Anuj Bhaiya
@Jv_Singh37
@Jv_Singh37 3 ай бұрын
i think ' u ' should be replace with ' cur '
@akshaygade7882
@akshaygade7882 2 жыл бұрын
pls run the code at end
@neelsheth7706
@neelsheth7706 2 жыл бұрын
Nahi hoga run.. Wrong code he.. Errors he
@ahariomangle4084
@ahariomangle4084 2 жыл бұрын
1st
@toyabali5262
@toyabali5262 2 жыл бұрын
Great explain... thanks bhaiya..
@prachikumari5574
@prachikumari5574 Жыл бұрын
Sharma wo v Anuj "the best" . Thankyou bhaiya easily smjhane k liye.☺️
@jayaswalrajp
@jayaswalrajp 2 жыл бұрын
Very nice video.. maza aa gya bhaiya
@pranalivekhande4450
@pranalivekhande4450 Жыл бұрын
Bahut fast padha rahe ho...confusion ho raha hai😢
@mandeepkaur749
@mandeepkaur749 2 жыл бұрын
Great Explanation !
@psycho_gaming2422
@psycho_gaming2422 Жыл бұрын
you made graph so easy, awesome!!
@samrat8413
@samrat8413 2 жыл бұрын
Well explained.
@chandnibhatia1211
@chandnibhatia1211 Жыл бұрын
why do we keep predecessor array ..
@ManikChakraborty
@ManikChakraborty 2 жыл бұрын
Really helpful
@643kanavguleria9
@643kanavguleria9 8 ай бұрын
if we remove "vis[neighbour] == false" if statement from the while loop and add a condition that "if the new distance in lesser than previous distance only than we will add something in queue" by this can we find the shortest distance to reach from point a to point b
@souravu5121
@souravu5121 12 күн бұрын
Thank you so much
@643kanavguleria9
@643kanavguleria9 8 ай бұрын
as we are using predecesor array to track back the whole path , can we find multiple paths to reach from point "a" to "b" point b if they are present
@ml9421
@ml9421 11 ай бұрын
bhayia it is so well explained please make a video on BFS , dfs , dls, uniform cost search, and greedy best-first search in python
@girlysh09
@girlysh09 Жыл бұрын
whenever the pop out of like is appear i pause the video first and go to like, thanks for the pop out ;p
@gamegem574
@gamegem574 2 жыл бұрын
In for loop what is 'u'
@AnujBhaiya
@AnujBhaiya 2 жыл бұрын
It's cur. Misspelt
@gamegem574
@gamegem574 2 жыл бұрын
@@AnujBhaiya i have written but showing out of bound
@ruchikabhandari2768
@ruchikabhandari2768 2 жыл бұрын
@@gamegem574 this is because I think the for loop need to be from 1 to v+1
@gamegem574
@gamegem574 2 жыл бұрын
Yup i have solved that thing
@dipakpatil-hz6mg
@dipakpatil-hz6mg Жыл бұрын
@Anuj For 2nd question finding the total connected component. Your using same fun BFS and passing last parameter as Vis wht is that? Also as per declaration of bfs fun it has 6 arguments and your passing 7 argument while finding the total component in the graph
@anket_singh9003
@anket_singh9003 11 ай бұрын
Samjh me nhi aaya kuch bhi
@deepakdas6423
@deepakdas6423 2 жыл бұрын
What is "u" variable?
@neelsheth7706
@neelsheth7706 2 жыл бұрын
same question
@varunkhulbey1351
@varunkhulbey1351 2 жыл бұрын
It was a typo. It's 'cur' actually instead of 'u'.
@ashishsingh3850
@ashishsingh3850 2 жыл бұрын
Badhiya hai bhaiya
@realityvirtuality1231
@realityvirtuality1231 Жыл бұрын
agar hme graph 1 2 and 1000 ka banana pde tb visited array size will be 1000 lagegi kya
@the_nishantsourav9331
@the_nishantsourav9331 Жыл бұрын
so many mistajes found in ur code
@sarangavadiya7087
@sarangavadiya7087 2 жыл бұрын
really helpful thank for your awesome work
@sekharsamanta6561
@sekharsamanta6561 3 ай бұрын
Spectacular!
@643kanavguleria9
@643kanavguleria9 Жыл бұрын
what is (u) in adj.get(u).size() at line 24 ------> 9:09
@manglaram2589
@manglaram2589 Жыл бұрын
it is cur instead of u
@ayanchakraborty1931
@ayanchakraborty1931 10 ай бұрын
bhaiya int neighbour = adj.get(u).get(i) isme u kya hai? i think wo cur hoga
@time-to-rise3900
@time-to-rise3900 Жыл бұрын
while fetching element from adjency list you kept adj.get(u).get(i), it should be adj.get(cur).get(i)
WORLD BEST MAGIC SECRETS
00:50
MasomkaMagic
Рет қаралды 54 МЛН
The day of the sea 😂 #shorts by Leisi Crazy
00:22
Leisi Crazy
Рет қаралды 2,2 МЛН
哈莉奎因怎么变骷髅了#小丑 #shorts
00:19
好人小丑
Рет қаралды 54 МЛН
Graph Search Visualization in Python (BFS and DFS)
19:12
NeuralNine
Рет қаралды 20 М.
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Codebagel
Рет қаралды 395 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 374 М.
What's The Longest Word You Can Write With Seven-Segment Displays?
8:56
Hashing Algorithms and Security - Computerphile
8:12
Computerphile
Рет қаралды 1,5 МЛН
Breadth-first search in 4 minutes
3:59
Michael Sambol
Рет қаралды 286 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 656 М.