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; } }
@doublemand30783 жыл бұрын
F
@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; } }
@Naufalmlns6 ай бұрын
@@joyceasante8292 can u make for list adj?
@MarshGames2 жыл бұрын
Most underrated coding channel on KZbin
@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
@micahjacobson853311 ай бұрын
Been watching your videos all year and now you're really saving me from my Discrete math class.
@LukaS-uu4vv11 ай бұрын
Informative and easy to understand! Good points in the end too
@chootajezu4476 Жыл бұрын
Bro please make a design and analysis of algorithms, playlist
@flammabletfm34053 жыл бұрын
Thanks for the tutorial bro. 😇
@pranavithape3 жыл бұрын
Hey Make React Js Course bro with node js backend
@yeshuwasuhail12903 жыл бұрын
my bro your student is here
@harishgunasekera11 ай бұрын
Can you do a tutorial for Dijkstra's Algorithm
@robinsonlanda93643 жыл бұрын
You are the best:)
@preraksemwal87683 жыл бұрын
you're really good !!
@eugenezuev73492 ай бұрын
sweeeet
@hermansiisengbae3 жыл бұрын
Good 👍👍
@r66112d3 жыл бұрын
Hey Bro can you do some more C# videos? For example LINQ queries ?
@Snowmanver22 жыл бұрын
great vid!
@gameGXT2 жыл бұрын
Super
@MrLoser-ks2xn Жыл бұрын
Thanks!
@PhongNguyenCS3 жыл бұрын
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
@gerdsfargen66873 жыл бұрын
Another session with the Brofessor. Class is in Session.
@siraj5223 жыл бұрын
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
@scottzeta30673 жыл бұрын
I am confused with why does my lecture needs 40minutes to explain this and I could not understand anything he talked about.
@nonconsensualopinion3 жыл бұрын
I'm a bit heartbroken. This video didn't start with "Hey everyone, it's your bro". :(
@Sh11roe3 жыл бұрын
I'm early today
@doublemand30783 жыл бұрын
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?
@BroCodez3 жыл бұрын
I don't know anything about hacking, unfortunately xD
@doublemand30783 жыл бұрын
@@BroCodez can you do a video on python libraries
@doublemand30783 жыл бұрын
@@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
@doublemand30783 жыл бұрын
@@adheesh2secondsago630 Thank you, it means a lot!