Learn Breadth First Search in 6 minutes ↔️

  Рет қаралды 42,827

Bro Code

Bro Code

Күн бұрын

Пікірлер: 41
@BroCodez
@BroCodez 3 жыл бұрын
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 3 жыл бұрын
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 6 ай бұрын
@@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 11 ай бұрын
Been watching your videos all year and now you're really saving me from my Discrete math class.
@LukaS-uu4vv
@LukaS-uu4vv 11 ай бұрын
Informative and easy to understand! Good points in the end too
@chootajezu4476
@chootajezu4476 Жыл бұрын
Bro please make a design and analysis of algorithms, playlist
@flammabletfm3405
@flammabletfm3405 3 жыл бұрын
Thanks for the tutorial bro. 😇
@pranavithape
@pranavithape 3 жыл бұрын
Hey Make React Js Course bro with node js backend
@yeshuwasuhail1290
@yeshuwasuhail1290 3 жыл бұрын
my bro your student is here
@harishgunasekera
@harishgunasekera 11 ай бұрын
Can you do a tutorial for Dijkstra's Algorithm
@robinsonlanda9364
@robinsonlanda9364 3 жыл бұрын
You are the best:)
@preraksemwal8768
@preraksemwal8768 3 жыл бұрын
you're really good !!
@eugenezuev7349
@eugenezuev7349 2 ай бұрын
sweeeet
@hermansiisengbae
@hermansiisengbae 3 жыл бұрын
Good 👍👍
@r66112d
@r66112d 3 жыл бұрын
Hey Bro can you do some more C# videos? For example LINQ queries ?
@Snowmanver2
@Snowmanver2 2 жыл бұрын
great vid!
@gameGXT
@gameGXT 2 жыл бұрын
Super
@MrLoser-ks2xn
@MrLoser-ks2xn Жыл бұрын
Thanks!
@PhongNguyenCS
@PhongNguyenCS 3 жыл бұрын
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
@gerdsfargen6687
@gerdsfargen6687 3 жыл бұрын
Another session with the Brofessor. Class is in Session.
@siraj522
@siraj522 3 жыл бұрын
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
@scottzeta3067
@scottzeta3067 3 жыл бұрын
I am confused with why does my lecture needs 40minutes to explain this and I could not understand anything he talked about.
@nonconsensualopinion
@nonconsensualopinion 3 жыл бұрын
I'm a bit heartbroken. This video didn't start with "Hey everyone, it's your bro". :(
@Sh11roe
@Sh11roe 3 жыл бұрын
I'm early today
@doublemand3078
@doublemand3078 3 жыл бұрын
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 3 жыл бұрын
I don't know anything about hacking, unfortunately xD
@doublemand3078
@doublemand3078 3 жыл бұрын
@@BroCodez can you do a video on python libraries
@doublemand3078
@doublemand3078 3 жыл бұрын
@@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 3 жыл бұрын
@@adheesh2secondsago630 Thank you, it means a lot!
@ngstudentsvlog113
@ngstudentsvlog113 3 жыл бұрын
Hello
@doublemand3078
@doublemand3078 3 жыл бұрын
Where did my comment go?
@ngstudentsvlog113
@ngstudentsvlog113 3 жыл бұрын
ഒരു ഹലോ തരാമോ 🌚
@lemokami
@lemokami 3 жыл бұрын
Nop
@fyrukmcoo100
@fyrukmcoo100 3 жыл бұрын
:((
@BroCodez
@BroCodez 3 жыл бұрын
:))
Tree data structures in 2 minutes 🌳
2:55
Bro Code
Рет қаралды 58 М.
Learn Depth First Search in 7 minutes ⬇️
7:41
Bro Code
Рет қаралды 92 М.
Do you love Blackpink?🖤🩷
00:23
Karina
Рет қаралды 20 МЛН
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 145 МЛН
Breadth First Search grid shortest path | Graph Theory
16:51
WilliamFiset
Рет қаралды 339 М.
Learn Binary search trees in 20 minutes 🔍
20:25
Bro Code
Рет қаралды 184 М.
you will never ask about pointers again after watching this video
8:03
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 501 М.
Breadth First Search (BFS): Visualized and Explained
10:41
Reducible
Рет қаралды 221 М.
Learn Adjacency Matrix in 10 minutes ⬜
9:52
Bro Code
Рет қаралды 57 М.
Learn Binary Search in 10 minutes 🪓
10:04
Bro Code
Рет қаралды 125 М.
Graph Search Algorithms in 100 Seconds - And Beyond with JS
10:30