Given an array of elements, return the root node of a tree containing in the elements [closed]
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I was trying to solve the following problem recently online.
My question has to do various ways of solving this problem. I know I can just use breadth-first search traversal to solve the problem, but wondering if there's any other way to do this.
Given an array of elements, return the root node of a tree containing
the elements of the array progressing top down, left to right. ex:
input: [a,b,c,d,e,f,g] result tree:
a
/
b c
/ /
d e f g
here's my implementation of this problem for printing out in
breadth-first search order.
function graphBFS(graph, start)
const queue = new Queue();
const visited = new Set([start]);
queue.enqueue(start);
while (queue.length)
const neighbors = graph.neighbors(queue.dequeue());
for (const neighbor of neighbors)
if (!visited.has(neighbor))
queue.enqueue(neighbor);
visited.add(neighbor);
thanks for your feedback and help.
tree
closed as unclear what you're asking by 200_success, Stephen Rauch, Heslacher, yuri, Ludisposed Jul 31 at 7:51
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |Â
up vote
0
down vote
favorite
I was trying to solve the following problem recently online.
My question has to do various ways of solving this problem. I know I can just use breadth-first search traversal to solve the problem, but wondering if there's any other way to do this.
Given an array of elements, return the root node of a tree containing
the elements of the array progressing top down, left to right. ex:
input: [a,b,c,d,e,f,g] result tree:
a
/
b c
/ /
d e f g
here's my implementation of this problem for printing out in
breadth-first search order.
function graphBFS(graph, start)
const queue = new Queue();
const visited = new Set([start]);
queue.enqueue(start);
while (queue.length)
const neighbors = graph.neighbors(queue.dequeue());
for (const neighbor of neighbors)
if (!visited.has(neighbor))
queue.enqueue(neighbor);
visited.add(neighbor);
thanks for your feedback and help.
tree
closed as unclear what you're asking by 200_success, Stephen Rauch, Heslacher, yuri, Ludisposed Jul 31 at 7:51
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Which language? JavaScript?
â Zeta
Jul 30 at 17:10
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I was trying to solve the following problem recently online.
My question has to do various ways of solving this problem. I know I can just use breadth-first search traversal to solve the problem, but wondering if there's any other way to do this.
Given an array of elements, return the root node of a tree containing
the elements of the array progressing top down, left to right. ex:
input: [a,b,c,d,e,f,g] result tree:
a
/
b c
/ /
d e f g
here's my implementation of this problem for printing out in
breadth-first search order.
function graphBFS(graph, start)
const queue = new Queue();
const visited = new Set([start]);
queue.enqueue(start);
while (queue.length)
const neighbors = graph.neighbors(queue.dequeue());
for (const neighbor of neighbors)
if (!visited.has(neighbor))
queue.enqueue(neighbor);
visited.add(neighbor);
thanks for your feedback and help.
tree
I was trying to solve the following problem recently online.
My question has to do various ways of solving this problem. I know I can just use breadth-first search traversal to solve the problem, but wondering if there's any other way to do this.
Given an array of elements, return the root node of a tree containing
the elements of the array progressing top down, left to right. ex:
input: [a,b,c,d,e,f,g] result tree:
a
/
b c
/ /
d e f g
here's my implementation of this problem for printing out in
breadth-first search order.
function graphBFS(graph, start)
const queue = new Queue();
const visited = new Set([start]);
queue.enqueue(start);
while (queue.length)
const neighbors = graph.neighbors(queue.dequeue());
for (const neighbor of neighbors)
if (!visited.has(neighbor))
queue.enqueue(neighbor);
visited.add(neighbor);
thanks for your feedback and help.
tree
asked Jul 30 at 16:45
NinjaG
634221
634221
closed as unclear what you're asking by 200_success, Stephen Rauch, Heslacher, yuri, Ludisposed Jul 31 at 7:51
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by 200_success, Stephen Rauch, Heslacher, yuri, Ludisposed Jul 31 at 7:51
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Which language? JavaScript?
â Zeta
Jul 30 at 17:10
add a comment |Â
1
Which language? JavaScript?
â Zeta
Jul 30 at 17:10
1
1
Which language? JavaScript?
â Zeta
Jul 30 at 17:10
Which language? JavaScript?
â Zeta
Jul 30 at 17:10
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
Which language? JavaScript?
â Zeta
Jul 30 at 17:10