Skip to content

Conversation

100mya
Copy link

@100mya 100mya commented Oct 13, 2023

javascript code for minmax problem using backtracking

Copy link
Collaborator

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Needs a doc comment, esp. given the odd interface (expects a binary tree in array format + height; height is technically redundant).
  • Needs proper tests rather than an example at the end of the file.
  • Formatting seems off (we use prettier now, there should be no semicolons).
  • Why is this in "backtracking"? It's just recursive as far as I can see.
  • Why limit minimax to full binary trees stored in an array format?
  • The code in the two branches of if (isMax) - else is unnecessarily duplicated. It should instead just do recursive calls of minimax(depth + 1, <child index>, !isMax, scores, height). You can do return (isMax ? Math.max : Math.min)(leftValue, rightValue) then.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants