Given an array of elements, return the root node of a tree containing in the elements [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|improve this 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
















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.







share|improve this 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












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.







share|improve this question











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.









share|improve this question










share|improve this question




share|improve this question









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












  • 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















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Greedy Best First Search implementation in Rust

Function to Return a JSON Like Objects Using VBA Collections and Arrays

C++11 CLH Lock Implementation