Learn Breadth First Search in 6 minutes ↔️

  Рет қаралды 38,428

Bro Code

Bro Code

Күн бұрын

Пікірлер: 41
@BroCodez
@BroCodez 2 жыл бұрын
public class Main { public static void main(String[] args) { // Breadth FS = Traverse a graph level by level // Utilizes a Queue // Better if destination is on average close to start // Siblings are visited before children // Depth FS = Traverse a graph branch by branch // Utilizes a Stack // Better if destination is on average far from the start // Children are visited before siblings // More popular for games/puzzles Graph graph = new Graph(5); graph.addNode(new Node('A')); graph.addNode(new Node('B')); graph.addNode(new Node('C')); graph.addNode(new Node('D')); graph.addNode(new Node('E')); graph.addEdge(0, 1); graph.addEdge(1, 2); graph.addEdge(1, 4); graph.addEdge(2, 3); graph.addEdge(2, 4); graph.addEdge(4, 0); graph.addEdge(4, 2); graph.print(); graph.breadthFirstSearch(0); } } import java.util.*; public class Graph { ArrayList nodes; int[][] matrix; Graph(int size){ nodes = new ArrayList(); matrix = new int[size][size]; } public void addNode(Node node) { nodes.add(node); } public void addEdge(int src, int dst) { matrix[src][dst] = 1; } public boolean checkEdge(int src, int dst) { if(matrix[src][dst] == 1) { return true; } else { return false; } } public void print() { System.out.print(" "); for(Node node : nodes) { System.out.print(node.data + " "); } System.out.println(); for(int i = 0; i < matrix.length; i++) { System.out.print(nodes.get(i).data + " "); for(int j = 0; j < matrix[i].length; j++) { System.out.print(matrix[i][j] + " "); } System.out.println(); } System.out.println(); } public void breadthFirstSearch(int src) { Queue queue = new LinkedList(); boolean[] visited = new boolean[matrix.length]; queue.offer(src); visited[src] = true; while(queue.size() != 0) { src = queue.poll(); System.out.println(nodes.get(src).data + " = visited"); for(int i = 0; i < matrix[src].length; i++) { if(matrix[src][i] == 1 && !visited[i]) { queue.offer(i); visited[i] = true; } } } } } public class Node { char data; Node(char data){ this.data = data; } }
@doublemand3078
@doublemand3078 2 жыл бұрын
F
@joyceasante8292
@joyceasante8292 Жыл бұрын
Practicing(Coding line by line) public class Main { public static void main (String[]args) { Graph graph = new Graph (5); graph.addNode (new Node ('1')); graph.addNode (new Node ('2')); graph.addNode (new Node ('3')); graph.addNode (new Node ('4')); graph.addNode (new Node ('5')); graph.addEdge (0, 1); graph.addEdge (1, 2); graph.addEdge (2, 3); graph.addEdge (2, 4); graph.addEdge (4, 0); graph.addEdge (4, 2); graph.print (); graph.breadthFirstSearch(2); } } *************************** import java.util.*; public class Graph { ArrayList < Node > nodes; int[][] matrix; Graph (int size) { nodes = new ArrayList (); matrix = new int[size][size]; } public void addNode (Node node) { nodes.add (node); } public void addEdge (int src, int dst) { matrix[src][dst] = 1; } public boolean checkEdge (int src, int dst) { if (matrix[src][dst] == 1) { return true; } else { return false; } } public void print () { System.out.print (" "); for (Node node:nodes) { System.out.print (node.data + " "); } System.out.println (); for (int i = 0; i < matrix.length; i++) { System.out.print (nodes.get (i).data + " "); for (int j = 0; j < matrix[i].length; j++) { System.out.print (matrix[i][j] + " "); } System.out.println (); } System.out.println (); } public void breadthFirstSearch(int src){ Queuequeue = new LinkedList(); boolean[] visited = new boolean[matrix.length]; queue.offer(src); visited[src] = true; while(queue.size() != 0) { src = queue.poll(); System.out.println(nodes.get(src).data + "= visited"); for(int i = 0; i < matrix[src].length; i++){ if(matrix[src][i]== 1 && !visited[i]){ queue.offer(src); visited[i] = true; } } } } } *********************************** public class Node{ char data; Node(char data){ this.data = data; } }
@Naufalmlns
@Naufalmlns 4 ай бұрын
@@joyceasante8292 can u make for list adj?
@MarshGames
@MarshGames 2 жыл бұрын
Most underrated coding channel on KZbin
@dotanon
@dotanon Жыл бұрын
I've been trying to figure out how to implement this for a couple of days now until your video popped up, thank you so much. So many explanations are incredibly technical and don't really explain the practicality of it very well
@micahjacobson8533
@micahjacobson8533 9 ай бұрын
Been watching your videos all year and now you're really saving me from my Discrete math class.
@LukaS-uu4vv
@LukaS-uu4vv 9 ай бұрын
Informative and easy to understand! Good points in the end too
@chootajezu4476
@chootajezu4476 Жыл бұрын
Bro please make a design and analysis of algorithms, playlist
@ihateorangecat
@ihateorangecat 2 жыл бұрын
thanks bro 🙏 waiting for more & more turtorials !!
@pranavithape
@pranavithape 2 жыл бұрын
Hey Make React Js Course bro with node js backend
@yeshuwasuhail1290
@yeshuwasuhail1290 2 жыл бұрын
my bro your student is here
@harishgunasekera
@harishgunasekera 9 ай бұрын
Can you do a tutorial for Dijkstra's Algorithm
@r66112d
@r66112d 2 жыл бұрын
Hey Bro can you do some more C# videos? For example LINQ queries ?
@eugenezuev7349
@eugenezuev7349 14 күн бұрын
sweeeet
@scottzeta3067
@scottzeta3067 2 жыл бұрын
I am confused with why does my lecture needs 40minutes to explain this and I could not understand anything he talked about.
@hermansiisengbae
@hermansiisengbae 2 жыл бұрын
Good 👍👍
@flammabletfm3405
@flammabletfm3405 2 жыл бұрын
Thanks for the tutorial bro. 😇
@robinsonlanda9364
@robinsonlanda9364 2 жыл бұрын
You are the best:)
@siraj522
@siraj522 2 жыл бұрын
Hey bro, can you make a guide for JPackage (making an installable .exe out of a .jar) I've seen many tutorials and docs but still have problems with it
@Snowmanver2
@Snowmanver2 2 жыл бұрын
great vid!
@nonconsensualopinion
@nonconsensualopinion 2 жыл бұрын
I'm a bit heartbroken. This video didn't start with "Hey everyone, it's your bro". :(
@smallstiki1197
@smallstiki1197 2 жыл бұрын
Hey bro, what's your microphone by chance
@preraksemwal8768
@preraksemwal8768 2 жыл бұрын
you're really good !!
@PhongNguyenCS
@PhongNguyenCS 2 жыл бұрын
Hello bro, really appreciate what you are doing. I want to ask if you have any knowledge about machine learning field, please make video about it. Thank you
@gameGXT
@gameGXT 2 жыл бұрын
Super
@doublemand3078
@doublemand3078 2 жыл бұрын
Bro code, I'm learning python ( watching your 12h course) and I got an idea to do a brute force attack on a website, I searched on github and youtube but when I try the code it doesn't work. Can you do a video on how to do a brute force attack and what are python libraries and how they work?
@BroCodez
@BroCodez 2 жыл бұрын
I don't know anything about hacking, unfortunately xD
@doublemand3078
@doublemand3078 2 жыл бұрын
@@BroCodez can you do a video on python libraries
@doublemand3078
@doublemand3078 2 жыл бұрын
@@BroCodez Also, im 15 and I want to learn a programming language but I dont what language and should I learn multiple languages? Am i too late to learn programming
@doublemand3078
@doublemand3078 2 жыл бұрын
@@adheesh2secondsago630 Thank you, it means a lot!
@justinenanas5482
@justinenanas5482 2 жыл бұрын
I'm early today
@MrLoser-ks2xn
@MrLoser-ks2xn Жыл бұрын
Thanks!
@gerdsfargen6687
@gerdsfargen6687 2 жыл бұрын
Another session with the Brofessor. Class is in Session.
@ngstudentsvlog113
@ngstudentsvlog113 2 жыл бұрын
Hello
@doublemand3078
@doublemand3078 2 жыл бұрын
Where did my comment go?
@ngstudentsvlog113
@ngstudentsvlog113 2 жыл бұрын
ഒരു ഹലോ തരാമോ 🌚
@lemokami
@lemokami 2 жыл бұрын
Nop
@fyrukmcoo100
@fyrukmcoo100 2 жыл бұрын
:((
@BroCodez
@BroCodez 2 жыл бұрын
:))
Tree data structures in 2 minutes 🌳
2:55
Bro Code
Рет қаралды 48 М.
🍉😋 #shorts
00:24
Денис Кукояка
Рет қаралды 1 МЛН
Depth-first search in 4 minutes
4:01
Michael Sambol
Рет қаралды 255 М.
Breadth First Search (BFS): Visualized and Explained
10:41
Reducible
Рет қаралды 204 М.
Breadth First Search grid shortest path | Graph Theory
16:51
WilliamFiset
Рет қаралды 332 М.
Learn Binary search trees in 20 minutes 🔍
20:25
Bro Code
Рет қаралды 160 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 171 М.
How To Think Like A Programmer
1:00:07
Coding Tech
Рет қаралды 2 МЛН