Тёмный

Learn Breadth First Search in 6 minutes ↔️ 

Bro Code
Подписаться 2,2 млн
Просмотров 39 тыс.
50% 1

Опубликовано:

 

2 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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 5 месяцев назад
@@joyceasante8292 can u make for list adj?
@micahjacobson8533
@micahjacobson8533 10 месяцев назад
Been watching your videos all year and now you're really saving me from my Discrete math class.
@MarshGames
@MarshGames 2 года назад
Most underrated coding channel on RU-vid
@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.
@pranavithape
@pranavithape 2 года назад
Hey Make React Js Course bro with node js backend
@eugenezuev7349
@eugenezuev7349 27 дней назад
sweeeet
@hermansiisengbae
@hermansiisengbae 2 года назад
Good 👍👍
@harishgunasekera
@harishgunasekera 9 месяцев назад
Can you do a tutorial for Dijkstra's Algorithm
@yeshuwasuhail1290
@yeshuwasuhail1290 2 года назад
my bro your student is here
@chootajezu4476
@chootajezu4476 Год назад
Bro please make a design and analysis of algorithms, playlist
@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
@Snowmanver2
@Snowmanver2 2 года назад
great vid!
@r66112d
@r66112d 2 года назад
Hey Bro can you do some more C# videos? For example LINQ queries ?
@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
@ngstudentsvlog113
@ngstudentsvlog113 2 года назад
Hello
@doublemand3078
@doublemand3078 2 года назад
Where did my comment go?
@smallstiki1197
@smallstiki1197 2 года назад
Hey bro, what's your microphone by chance
@LukaS-uu4vv
@LukaS-uu4vv 10 месяцев назад
Informative and easy to understand! Good points in the end too
@justinenanas5482
@justinenanas5482 2 года назад
I'm early today
@MrLoser-ks2xn
@MrLoser-ks2xn Год назад
Thanks!
@flammabletfm3405
@flammabletfm3405 2 года назад
Thanks for the tutorial bro. 😇
@preraksemwal8768
@preraksemwal8768 2 года назад
you're really good !!
@robinsonlanda9364
@robinsonlanda9364 2 года назад
You are the best:)
@gameGXT
@gameGXT 2 года назад
Super
@gerdsfargen6687
@gerdsfargen6687 2 года назад
Another session with the Brofessor. Class is in Session.
@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!
@ngstudentsvlog113
@ngstudentsvlog113 2 года назад
ഒരു ഹലോ തരാമോ 🌚
@lemokami
@lemokami 2 года назад
Nop
@fyrukmcoo100
@fyrukmcoo100 2 года назад
:((
@BroCodez
@BroCodez 2 года назад
:))
@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
@nonconsensualopinion
@nonconsensualopinion 2 года назад
I'm a bit heartbroken. This video didn't start with "Hey everyone, it's your bro". :(
@ihateorangecat
@ihateorangecat 2 года назад
thanks bro 🙏 waiting for more & more turtorials !!
Далее
Tree data structures in 2 minutes 🌳
2:55
Просмотров 49 тыс.
Лучше одной, чем с такими
00:54
Просмотров 942 тыс.
OYUNCAK DİREKSİYON İLE ARABAYI SÜRDÜ 😱
00:16
小路飞嫁祸姐姐搞破坏 #路飞#海贼王
00:45
Learn Binary search trees in 20 minutes 🔍
20:25
Просмотров 163 тыс.
Learn Depth First Search in 7 minutes ⬇️
7:41
Просмотров 83 тыс.
Breadth-first search in 4 minutes
3:59
Просмотров 287 тыс.
Lecture 14: Depth-First Search (DFS), Topological Sort
50:31
LeetCode was HARD until I Learned these 15 Patterns
13:00
Breadth First Search grid shortest path | Graph Theory
16:51
Making an Algorithm Faster
30:08
Просмотров 99 тыс.