Hi Nam,
Thanks for the comment!
in the bfs implementation you need to utilize a queue and a tree (see my previous article dev.to/konstantinosblatsoukasrepo/...)
there will be a need to mark the visited nodes in case of graph (in order to avoid cycles). In a tree, you don't have that problem (there is no cycle)
if that was a bfs the nodes will be traversed layer by layer, in the above code that doesn't happens
now, a stack is a data structure that is like a stack of plates, possible operatios:
In this case, I used a js array as a stack, I was adding something at the end of the array and removing something from the end of the array
Yes you are right I have not explained the tree object, I will do that! Thanks!
Oops, I’m wrong at some points. Btw, thanks for sharing. Cheers.
Nam, I just added how a tree node looks like! thanks again for your comment
That is a ideal structure, and does not exist in reality world. I believe that we will have adjacency list only.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Nam,
Thanks for the comment!
in the bfs implementation you need to utilize a queue and a tree (see my previous article dev.to/konstantinosblatsoukasrepo/...)
there will be a need to mark the visited nodes in case of graph (in order to avoid cycles). In a tree, you don't have that problem (there is no cycle)
if that was a bfs the nodes will be traversed layer by layer, in the above code that doesn't happens
now, a stack is a data structure that is like a stack of plates, possible operatios:
In this case, I used a js array as a stack, I was adding something at the end of the array and removing something from the end of the array
Yes you are right I have not explained the tree object, I will do that! Thanks!
Oops, I’m wrong at some points. Btw, thanks for sharing.
Cheers.
Nam, I just added how a tree node looks like! thanks again for your comment
That is a ideal structure, and does not exist in reality world. I believe that we will have adjacency list only.