Тёмный

Graph - Data Structures in Javascript 

Подписаться
Просмотров 14 тыс.
% 302

An introduction to Graph data structure.
We will cover:
0:00 The definition of Graph
1:08 Types of graphs
2:35 Common problems with graphs
4:30 Graph representations with an adjacency matrix and adjacency list
6:07 Main and additional graph methods
6:33 BFS and DFS traversal illustration
8:19 Big O for adjacency list implementation of a graph
9:26 Implementation of a graph and BFS in Javascript
(!) There is a tricky mistake with calling 'shift()'. In Javascript it will be O(N) because you need to reindex the entire array. So it is not acceptable and shouldn't be used. I'll fix that in the upcoming video about the BFS.

Хобби

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

 

10 авг 2020

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 25   
@rajapavithraselvaraj5937
@rajapavithraselvaraj5937 Год назад
If allowed, i would have given 1k+ likes to this video. Clear. Nutshell. Exactly what i was searching for. Thanks.
@dominikamalinowska6395
@dominikamalinowska6395 2 года назад
Love the video! Clear explanation of graphs and seeing the implementation in JS is a bonus. Thanks so much!
@95Shoo
@95Shoo 3 года назад
Thank you, very insightful, it helped to watch this video with a javascript implementation
@garikmelqonyan6011
@garikmelqonyan6011 Год назад
Thanks for the tutorial. An awesome example of graph implementation.
@sandeepaksingh9248
@sandeepaksingh9248 3 года назад
Fabulous explaination ......... Have proud dude
@jwolfe890
@jwolfe890 Год назад
Great introduction to the subject. Thank you.
@shubhamsagar9153
@shubhamsagar9153 3 года назад
Awesome explaination thanks
@rick7242
@rick7242 3 года назад
Very nice video, thanks
@prathmeshfutane1287
@prathmeshfutane1287 3 года назад
Please keep it up Love from India
@artur7017
@artur7017 2 года назад
Хорошее видео, спасибо)
@nocathedral
@nocathedral 3 года назад
Great demonstration.. thanks! I took a bit of time to think about how to return the route that was found. My solution was to keep a list of visited edges, so an array of arrays. Once the destination node was found it triggers a buildRoute() function that constructs the route from this array. Basically it'll take the last edge in the array (which is obviously part of the solution) and then unshifts the first edge that has that edge's source as its destination.. this then loops until we get back to the original source node. Flatten the array and return the unique values and you will have an array representing the route. Not sure this is the most efficient way of doing things but i was pretty proud to work this one out myself!
@QuestionableCoding
@QuestionableCoding 3 года назад
Can you please provide a code snippet so we could discuss it in more details? Sounds like a very interesting topic :)
@nocathedral
@nocathedral 3 года назад
@@QuestionableCoding it's a bit messy but here is my buildPath function: function buildPath(listOfEdges, source, destination) { let path = []; let currentNode = destination while (currentNode !== source) { for (let i = 0; i < listOfEdges.length; i++) { // find first instance of current node as an edge destination if (listOfEdges[i][1] === currentNode) { // add edge to route path.unshift(listOfEdges[i]); // re-assign current node currentNode = listOfEdges[i][0]; // remove rest of edge list and jump out of loop listOfEdges.pop(listOfEdges.length - i) break; } } } // flatten array and remove duplicates return [...new Set([].concat(...path))]; } to initially build the list of edges in the main bfs function i did: listOfEdges.push([current, neigbour[i]]) at each iteration.
@minzhu5521
@minzhu5521 3 года назад
I hope u can do more leetcode js solutions videos, they are very helpful and I like your coding pattern(clean and modularized)
@jaeseongjoo119
@jaeseongjoo119 3 года назад
Thanks for helpful explanation and Code! how do you think about adding "visited[neighbor[i]] != true" before pushing neighbor[i] on queue at BFS? In undirected graph, I think this can save a little bit of memory in queue. Or there is no big difference?
@QuestionableCoding
@QuestionableCoding 3 года назад
That will be an improvement but it won't affect our time complexity because the worst case is still there - we can expect up to N elements in our queue since our first element can be a neighbor of every other element. But still, for the sake of not doing redundant work, I would use your improvement and more to that, reorganise the code a bit not to have the first check for 'visited'. We'll need to mark our first node as visited before starting the while loop. All together it will be a more logical and optimised solution. Also there is a significant and tricky mistake with calling 'shift()'. In Javascript it will be O(N) because you need to reindex the entire array. So it is not acceptable and shouldn't be used. I'll fix that in the upcoming video about the BFS.
@jz319
@jz319 2 года назад
can you post the link for the tool you used to draw the graphs ?? thnx !!
@shahadhussein9708
@shahadhussein9708 Год назад
The way you're printing the nodes comes out different than mine, why is that?
@arun7232
@arun7232 2 года назад
Thanks for creating content datastructure in javascript.Internent is full with c++ and java and little bit of python not javascript
@user-mx7mc7sv2q
@user-mx7mc7sv2q 3 года назад
Nice tutorial, but it's not very clear why matrix should be faster on traversal than adjacency variant - yo find if two nodes are connected you traverse through all nodes once O(N) and then traverse adjacent sibling within that node O(N) worst case, which gives the same O(N) + O(N) for matrix trax traversal (lengthwise and depthwise). Unless you use hashmap for storing thing in matrix, which gives O(1) for accessing nodes.
@QuestionableCoding
@QuestionableCoding 3 года назад
I think I didn't mention traversing the graph. I found a place where I was stating that the lookup operation is faster for the matrix. And by that I mean finding that one node has an edge with another which is O(1) for the matrix and O(N) for the adjacency list implementation.
@lifeisgames2237
@lifeisgames2237 Год назад
11 thousand views and only 778 subscribers come on guys(at the time i was writing this)😲
@jiren8991
@jiren8991 2 года назад
9:41
@jiren8991
@jiren8991 2 года назад
12:22
@jiren8991
@jiren8991 2 года назад
9:26