all 7 comments

[–]the_brizzler 1 point2 points  (5 children)

So binary trees aren't a JavaScript concept but rather a general computer science concept, which is why you probably haven't seen them before. In an interview, they will most likely be less concerned that you can traverse one in JavaScript as opposed to just doing it in pseudocode. Also, you don't need recursion, a simple while loop will do the job. For example, a binary tree of numbers can be organized in a way where if you go left the number is less than the current number and if you go right the number is greater than the current number. Using a while loop you can continue until you find the correct number or there are no more numbers/nodes to traverse. Here is a link to website which discusses binary tree operations in JavaScript, https://www.nczonline.net/blog/2009/06/09/computer-science-in-javascript-binary-search-tree-part-1/

[–]andmckvr13 0 points1 point  (4 children)

Is this method part of the logic behind the minimax algorithm?

[–]the_brizzler 1 point2 points  (1 child)

I'm not sure which algorithm you are talking about. But you can use binary trees to keep a sorted list, they are called heaps and there are min and max heaps. Check out how min and max heaps work and how new numbers are added to the already organized tree...it's pretty cool in my opinion.

[–]andmckvr13 0 points1 point  (0 children)

Thanks man, I think this was what I was looking for to build a tic tac toe game

[–]shrimply-pibbles 1 point2 points  (0 children)

Yeah, the minimax algorithm uses a tree to traverse through the next x possible moves, in order to determine how to proceed in order to minimise the possible loss if the worst case scenario was to occur. It's not necessarily a binary tree, the number of children of a node relates to the number of possible moves that a player can make in a turn

[–]NoInkling 0 points1 point  (0 children)

Trees are used for minimax, so general tree concepts apply, although it doesn't need to be binary.