05. Breadth First Search BFS | Graph Traversal Algorithm | Concept + Implementation in C++

  Рет қаралды 66,336

Coding Blocks

Coding Blocks

Күн бұрын

Пікірлер: 50
@gaganb
@gaganb 3 жыл бұрын
Two Corrections: In the range for-loop on line 32, it has to be "T nbr" not "int nbr". This is because we cannot assume the type to be int since we are abstracting it away under the template T. On line 21, the "visited" map should be "map visited" and not "map visited".
@PrashantKumarSharma
@PrashantKumarSharma 3 жыл бұрын
There are too many errors in his code. This is one of them
@lostparadise7028
@lostparadise7028 3 жыл бұрын
map visited will come in bfs function instead of "map visited;"...It works same anyways,But..
@ansumanmishra1757
@ansumanmishra1757 4 жыл бұрын
The slight change in order is because in the input(in main func) there is no edge for (0,3) . After adding an edge you will get the output as 0 1 3 2 4 5
@josejayant94
@josejayant94 4 жыл бұрын
It worked
@piyushbajaj8355
@piyushbajaj8355 4 жыл бұрын
yes
@lydialarina
@lydialarina Жыл бұрын
I was very confused by the topic, and even though I found examples of code online, I really needed a thorough walkthrough. Excellent explanation! Thank you so much!
@arpitkhandelwal6050
@arpitkhandelwal6050 3 жыл бұрын
if we are using generic programming here then why are we writing addEdge(int x, int y) instead of addEgde(t x, t y)? if we pass string to this function this will give us an error.
@mavericmadhav
@mavericmadhav 3 жыл бұрын
Two issues found in this Implementation: 1) addEdge method takes int as arg type instead of Template type T. It needs to be fixed 2) addEdge for 0-3 was Missing due to which the. Order output came different than expected. Thanks for the explanation though. It was very clear.
@praveensingh1711
@praveensingh1711 8 ай бұрын
Explained well.😊 keep it up
@ce050manankadiya7
@ce050manankadiya7 2 жыл бұрын
Nice explanation sir 👍
@-invisibleguest-188
@-invisibleguest-188 3 жыл бұрын
theory part is good enough ,I understand it perfectly . -> but implementation part is little bit tricky and for me it was very hard to understand coz I learned it by using array in my University. -> note: i am seeing this video without maintaining the playlist may be for that it seemed confuse to me .
@imkd4real
@imkd4real 2 жыл бұрын
I will cry u explained it so well
@alishachhabra7995
@alishachhabra7995 4 жыл бұрын
Very well explained!
@rohitmathur9723
@rohitmathur9723 4 жыл бұрын
Amazing Explanation!
@jatinkumar4410
@jatinkumar4410 2 жыл бұрын
nice explanation
@joaovictormelo6442
@joaovictormelo6442 3 жыл бұрын
I would like to know if I can change t in the map visited by bool.
@saurabhsaxena1992
@saurabhsaxena1992 2 жыл бұрын
Thanks sir
@yogeshsarowgi7599
@yogeshsarowgi7599 4 жыл бұрын
in line no. 32 for(int nbr : l[node]) why you are using int?? What if value is string because you make generic class
@gouravgoel2974
@gouravgoel2974 4 жыл бұрын
then you can use string in place of int.
@yogeshsarowgi7599
@yogeshsarowgi7599 4 жыл бұрын
@@gouravgoel2974 then what is the use of generic??....it should be T
@pratyushranjan425
@pratyushranjan425 4 жыл бұрын
@@yogeshsarowgi7599 yepp it should be T
@pr0mero817
@pr0mero817 2 жыл бұрын
You are clouding the namespace by using namespace std. pls try the compiler trick
@akash-lz2dq
@akash-lz2dq 3 жыл бұрын
when you are using map for visited record then you are increasing the time complexity ,because map takes o(logn) to look up and array takes only 1 constant time ,
@akash-lz2dq
@akash-lz2dq 3 жыл бұрын
but if the node is of alphabatic notation or string then we cant use array thanks i got it
@Ben-pb7ct
@Ben-pb7ct 4 жыл бұрын
Could anyone explain what is for(int nbr : l[node])? Does this mean if the integer nbr in l[node] then the loop keeps going down? and where I could find the use about this : ( please help
@thienbinhinh7941
@thienbinhinh7941 4 жыл бұрын
you can search for "advanced loop"
@programmer4042
@programmer4042 4 жыл бұрын
kzbin.info/www/bejne/mYSrYpejbsmLfq8
@tombrady7390
@tombrady7390 3 жыл бұрын
range-based for loop gfg
@helloworld8912
@helloworld8912 3 жыл бұрын
My code is running for infinite "if(! visited [nbr])" is not working. Please help
@sindhumathi9209
@sindhumathi9209 3 жыл бұрын
Can u pls explain the Find Shortest Path using BFS
@giwrgoscy294
@giwrgoscy294 Жыл бұрын
THANKS MOOOOOOM
@ishitasinghal67
@ishitasinghal67 2 жыл бұрын
How can we print levels using this approach?
@090-jellabharath2
@090-jellabharath2 3 жыл бұрын
Tq sir
@uditkotecha2636
@uditkotecha2636 3 жыл бұрын
Nice
@vamshisamineniz5905
@vamshisamineniz5905 4 жыл бұрын
could u please put the source code in the above description
@amitkumar_ara
@amitkumar_ara 2 жыл бұрын
#include using namespace std; template class Graph { private: map l; public: void addEdge(int x, int y) { l[x].push_back(y); l[y].push_back(x); } void bfs(T src) { map visited; queue q; q.push(src); visited[src] = true; while (!q.empty()) { T node = q.front(); q.pop(); cout
@binunath5525
@binunath5525 2 жыл бұрын
In line no 35 error shown that end1 was not declared in this scope
@ashwanikumarsingh8232
@ashwanikumarsingh8232 3 жыл бұрын
sir line no 9 me error aa raha hai error: template argument 2 is invalid
@ayushpandey8633
@ayushpandey8633 4 жыл бұрын
if(!visited[nbr]) its initializing also internally that too false ??? ie nbr:false
@osiris1102
@osiris1102 3 жыл бұрын
I think that would be visited[nbr] = false;
@sakshamp4488
@sakshamp4488 3 жыл бұрын
Can anyone tell me why he gas written Visited(src)=true.just not able to understand:(
@NavneetKaur-vt8kt
@NavneetKaur-vt8kt 2 жыл бұрын
because src is the starting point of traversal, hence we mark it as true
@tanmaychandra9434
@tanmaychandra9434 3 жыл бұрын
Sir will use of unordered_map() perform better than map() ?
@nitinsinghrawat6891
@nitinsinghrawat6891 3 жыл бұрын
yes
@nitinsinghrawat6891
@nitinsinghrawat6891 3 жыл бұрын
But listen in order to avoid the duplicate key in a list we use the map instead of the unordered map
@md.salauddin
@md.salauddin 3 жыл бұрын
how to get user input???
@sagarjain4128
@sagarjain4128 2 жыл бұрын
we get user input by using Adjacency matrix.
@shikharjaiswal6877
@shikharjaiswal6877 2 жыл бұрын
10 | map l ; | ^~~~ BFS_Graph.cpp:3:1: note: 'std::list' is defined in header ''; did you forget to '#include '? 2 | #include +++ |+#include 3 | BFS_Graph.cpp:10:13: error: template argument 2 is invalid 10 | map l ; | ^ BFS_Graph.cpp:10:13: error: template argument 4 is invalid BFS_Graph.cpp:10:14: error: expected unqualified-id before '>' token 10 | map l ; | ^~ BFS_Graph.cpp: In member function 'void BFS_Graph::addEdge(int, int)': BFS_Graph.cpp:14:5: error: 'l' was not declared in this scope 14 | l[x].push_back(y); | ^ BFS_Graph.cpp: In member function 'void BFS_Graph::bfs(T)': BFS_Graph.cpp:21:5: error: 'queue' was not declared in this scope 21 | queue q; | ^~~~~ BFS_Graph.cpp:3:1: note: 'std::queue' is defined in header ''; did you forget to '#include '? 2 | #include +++ |+#include 3 | BFS_Graph.cpp:21:12: error: expected primary-expression before '>' token 21 | queue q; | ^ BFS_Graph.cpp:21:14: error: 'q' was not declared in this scope 21 | queue q; | ^ BFS_Graph.cpp:31:20: error: 'l' was not declared in this scope 31 | for(T nbr: l[node]){ | ^ Please help me with this errror. list in 9th line of the video is showing error.
@lavanyabansod3433
@lavanyabansod3433 2 жыл бұрын
#include
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
Симбочка Пимпочка
Рет қаралды 4,2 МЛН
小路飞和小丑也太帅了#家庭#搞笑 #funny #小丑 #cosplay
00:13
家庭搞笑日记
Рет қаралды 17 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 10 МЛН
Breadth First Search (BFS): Visualized and Explained
10:41
Reducible
Рет қаралды 225 М.
C++ Data Structures: Breadth First Search (BFS)
15:36
Nick
Рет қаралды 29 М.
«Если 50 детей не рожу - ничего не добился»
1:26:17
Саша Сулим
Рет қаралды 1,9 МЛН
Is the C programming language still worth learning?
9:27
Jacob Sorber
Рет қаралды 110 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
Симбочка Пимпочка
Рет қаралды 4,2 МЛН