G-5. Breadth-First Search (BFS) | C++ and Java | Traversal Technique in Graphs
Vložit
- čas přidán 6. 08. 2022
- GfG-Problem Link: bit.ly/3bn84K8
C++/Java/Codes and Notes Link: takeuforward.org/graph/breadt...
DP Series: • Striver's Dynamic Prog...
SDE Sheet: takeuforward.org/interviews/s...
Check out our Website for curated resources:
Our Second Channel: / @striver_79
In case you are thinking to buy courses, please check below:
Code "takeuforward" for 15% off at GFG: practice.geeksforgeeks.org/co...
Code "takeuforward" for 20% off on sys-design: get.interviewready.io?_aff=takeuforward
Crypto, I use the Wazirx app: wazirx.com/invite/xexnpc4u
Take 750 rs free Amazon Stock from me: indmoney.onelink.me/RmHC/idje...
Earn 100 rs by making a Grow Account for investing: app.groww.in/v3cO/8hu879t0
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
---------------------------------------------------------------------------------------------------------------------------
Let's continue the habit of commenting “understood” if you got the entire video.
Do follow me on Instagram: striver_79
Bhaiya next bideo🥺 pls
US
understood
👍🏻
understood
I can proudly say that this summer I watched more tUf lectures than Netflix episodes.
Because your placement season is here
@@aniket6858 What is placement? Is this india
@@Moch117 no, its pakistan.
what is the result ?
Yoh Netfilix ke hovey?😶🌫️
Hey Striver! Thank you for creating outstanding content and helping people interested in coding problems worldwide! Please don’t stress yourself out, take a break after this one. It’s not easy to work full time and dedicate time for this.
you are great striver.
Explain such a complex topic in very easy manner.
Your method of teaching is unique, a unique lecture by a unique teacher🙏🙏🙏
Are you going to teach leetcode questions just like you did in DP series? It would be very helpful if you can teach commonly asked good questions covering different graph patterns and not just the basic ones.
Yups, this one is going to be 50+ videos.
@@takeUforward bro try to cover as max you can till 15 aug, thnks for helping
Just some simple words! No one can beat your DSA teaching style!!
after seeing your post on LinkedIn that you are launching graph series 2.0 i used to see your CZcams playlist daily now I am very happy thank you very much 💗
17:04 i was still wondering where the heck vis[n] came from. edited like a pro
same bro
this code is not running editor is a pro for sure
I like the way you explain time and space complexities, which actually helps me to analyze my code complexities. Thanks for the explanation.
Understood each and every word♥. Kudos to your hard work and dedication, you are the motivation behind a lot of people. Your hardwork inspires a lot of people to work hard.
Thankyou for providing such a beautiful graph series keep posting such content ♥, we all need this.
understood..awesome..most of the youtuber's don't explain a topic in depth... great video
You are amazing 🤩
Guru wo hota h jo muskil si cheez ko v Asan karde tushi great ho ji striver ❤
Understood! Awesome explanation as always, thank you so much!
What an amazing explanation! Understood! 🤩❤🔥
57 +videos trurly 🇮🇳 biggest graph series Ironically GOAT 🐐 is teaching GRAPH 🤩
a well explained and organised lecture !!!
great content loving this after completing dp series💙💛💙
very well explained with all the minute details
What about Directed Graphs, It applies for them too?
I think yes, because the adjacency list will only have those edges so we only traverse those edges
Awesome Space & Time Analysis 🔥🔥🔥🔥🔥🔥🔥🔥
Your videos never fail to save us anytime :) Undhan rasigaiyee naaum unaken puriyavillai...
Great work. Thanks for doing this.
Thankyou striver bhaiya! ❤️
coded on my own! Got an error, resolved the issue, all TC passed! Note taken
Toh tujhe kya lg rha bada jhanda gaad diya tune saale itne chappal maruga
brilliantly explain thanks sir and neeed complete playlist of DSA from you for cracking google like companies
Nice and crystal clear explanation !!
i loved it sir , what a beautiful explanation
I'm confused on the Time complexity,
If we know the while loop runs N times and the size of the adjacency list is 2E, It is alright to add them to get the time complexity?
like, the while loop runs N times and the for loop overall runs 2E times..??
understood!! Explained beautifully!!
congrats bhaiya for 300k
ek din apan sath me 1m jayenge
Thank you so much stiver. Happy Teachers dayy
brilliant explanation!
Liked the video, notes taken, understood
outstanding explanation!!
Understood, Happy Learning🤗
BEST DSA TEACHER FOR ME
Wonderful bhaiya.....
Ohoo masthhh bhaiyaaaa Woohoo
Understood Sir, Thank you very much
You are amazing striver ❣️
Understood..next please ✌🏻
Great video Loved it
If u r confused about time complexity part, then see the following dry run of the while loop of the qs. he has solved..
This is how nodes are connected(assuming undirected graph) :
0 -> 1 ,2, 3
1 -> 0
2 -> 0, 4
3 -> 0
4 -> 2
So, total no. of edges = E = 4
For first while loop ,
node = 0, edges = 3
Now, before going to the for loop part, u see a constant time operation O(1) --> q.pop( )
This step will be executed every time we enter into while loop.
So, for first while loop how many times for loop will execute ??
It will be equal to the no. of edges , here it will be 3.
Therefore, total = ( 1 + 3 )
Similarly for all other nodes, this is how it will look :
( 1 + 3 ) + ( 1 + 1 ) + ( 1 + 2 ) + ( 1 + 1 ) + ( 1 + 1 )
= 13
= O ( V + 2 * E )
= O ( 5 + 2 * 4 )
Very well explained !
Awesome 👌👌
Thank you
@@mypowerlevelisover9000 🙂
but at the worst case it will be O(n^2) right? since a complete graph have all the vertex with (n-1) edges. which will lead [(1+(n-1))=n] at each while and for loop. since after n times it will become n square. Please confirm this. BTW thanks for the explaination
Thank you very much. You are a genius.
Thank you, Striver
Thanks a lot stiver for putting all these playlists out. i can't imagine getting a job if you were not on youtube. i have a little doubt that in "bfsOfGraph" function the syntax of adj[ ] should be this "Vector> adj [ ]" but it is "vector adj[ ]" instead and this is a 1D vector not a vector of vector.
Here you're creating an array of vector.... basically number of vector is fixed....that is the way to create array of vectors
there is a similar comment in the video number G-2 check that out
Hence, vectoradj[n]
n is no of vertices.(0 based) . adj creates an array where each adj[i] is a vector itself. Array of VECTORS.
Same doubt. if we're storing an array at each index of the vector, shouldn't it be vector adj instead of vectoradj??
@@prachi1112 We are storing vector in array index, i.e array of vectors. Every node of array denotes an array . Eg -> if we write int arr[] , here data type is int , so it is array of integers, but if we write vector arr[] , here data type is vector , so it is array of vector
Thankuu sooo muchhh broooo🤗🤗🤗❤❤❤❤❤
hats off to ur hard work.
Thank You So Much for this wonderful video...........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
Understood bhaiya!
There was some sound glitch for 30 sec.. Was weird but
Loved the way you teach and i am here after conpleting your trees playliat... ❤
understood very well...
how can someone be so perfect in explianing concept
Thank you, understood!
Great explanation
you are the best stiver
here we go !
Understood. Thanks a lot.
This was great, wandering about traversing Graph with starting nodes somewhere in middle. Should that be traversed wrt to levels or some-other way?
Woah nice explanation
please also explain space and time complexities
Great Content
understood, thanks!
Thankyou striver!
Understood, Sire!
Fantastic 🎉 Understood
Hi @TakeUforward, I had a doubt, when the for loop is inside the while loop, shouldn't we multiply the time complexities instead of adding them?
understand with the following explanation (just copy-pasted)
This is how nodes are connected(assuming undirected graph) :
0 -> 1 ,2, 3
1 -> 0
2 -> 0, 4
3 -> 0
4 -> 2
So, total no. of edges = E = 4
For first while loop ,
node = 0, edges = 3
Now, before going to the for loop part, u see a constant time operation O(1) --> q.pop( )
This step will be executed every time we enter into while loop.
So, for first while loop how many times for loop will execute ??
It will be equal to the no. of edges , here it will be 3.
Therefore, total = ( 1 + 3 )
Similarly for all other nodes, this is how it will look :
( 1 + 3 ) + ( 1 + 1 ) + ( 1 + 2 ) + ( 1 + 1 ) + ( 1 + 1 )
= 13
= O ( V + 2 * E )
= O ( 5 + 2 * 4 )
@@IITiansgreat
Thanks sir .... best solutions
Great series
understood striver!!
understood
thankyou very much
bestttt!! understoodddd
thx striver. Understood.
Thanks Bhaiya
all clear thank u bro
Understood sir❤🙏🙇♂
made it simple to understand
Which software and device you are using for your illustration?
striver by bfs we wont visit unconnected componenets?
thank you
Thank you so much.
Sir I have a question how many time we have spent to complete graph ?
Understood Bhaiya
understood thank you
just thank you 🙏
Thanks for the video buddy. I understood everything except the point where you sum the O(N) and O(sum of degrees of nodes) to find the time complexity. why the sum is there? I think the inner loop will be running 2E times which should be the complexity only. can you please elaborate on why the sum of O(N) is also needed here?
You are great Striver, how's it going in Warsaw.?
Brother you forgot to tell why was that code working for directed graph as well? Does anybody here know?
Thank you sir
Understood🌻
Thank you
Understood💯
helllo , i am confused in this line "vis[n]" when i run the program it's saying "n" not declared but when i corrected it with vis[V-1] V being no. of vertices of graph it worked fine , so my question is , what is n here exactly ? number of edges or vertices used for declaring visited array?
i got the same error as well , he did a mistake on declaring visited array first time ,it should be "Visited[V]" not "visited[n]" ,so what you did was correct
Understood.
😊
understood
A Big Thanks!!
UNDERSTOOD!
Hey can someone please help me with this thing --> while initialising queue we are mentioning linkedlist and also the node part
In java you declare like that.
5/56 done(3.12.22)
thank you
can anyone please tell that why same code works for directed and undirected graph for bfs?