Yahoo India Web Search

Search results

  1. Dec 1, 2023 · The depth (or level) of a node is its distance (i.e. no of edges) from tree's root node. The height is number of edges between root node and furthest leaf. height (node) = 1 + max (height (node.leftSubtree),height (node.rightSubtree)). Keep in mind the following points before reading the example ahead.

  2. May 11, 2021 · the question is:** Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.**

  3. Aug 19, 2020 · This function maxDepth will determine the maximum depth of a binary tree. You would use it like this: let depth = maxDepth(treeRoot); Without the return, the function will determine the depth but you will not get the result when you call the function. answered Aug 19, 2020 at 7:12.

  4. I'm doing the exercise on leetcode using Scala. The problem I'm working on is "Maximum Depth of Binary Tree", which means find the maximum depth of a binary tree. I've passed my code with Intelli...

  5. Oct 25, 2015 · By having two calls to the the depth function in your code for each sub-tree (one for comparing the depths and one for returning the deepest sub-tree), you greatly increase the workload. It would be better to cache the lengths so you could re-use them, something like (pseudo-code):

  6. Jul 3, 2021 · Am I right in understanding that the only purpose of 'depth' is to act as a holder to hold the current maximum depth as we traverse the tree? Yes, that is correct. Maybe it helps clarifying this point when you would replace this line with this equivalent code: if current_depth > depth: depth = current_depth

  7. Aug 31, 2017 · string = str (myTuple) currentDepth = 0 maxDepth = 0 for c in string: if c == ' (': currentDepth += 1 elif c == ')': currentDepth -= 1 maxDepth = max (maxDepth, currentDepth) It gives the depth in a linear time with regards to the number of characters in the string into which the tuple was converted. That number should be more or less ...

  8. The instructions are to implement a method that will check to see if a tree is balanced. In order to do this, you need to compare the minimum depth with the maximum depth, and ensure their difference is no greater than 1. This principal is as straightforward as it gets. The method on line 15 is intended to do just that.

  9. Dec 6, 2023 · I know there are mistakes in my code, but I can't test them out, since I am used to my Tree Nodes input to be like so: test_tree_node = BST (20) test_tree_node.insert (5) test_tree_node.insert (23) The input (test-cases) given in LeetCode are in an array format, which they transform automatically into a TreeNode instance. I used their example ...

  10. Dec 10, 2020 · Why is there such a big difference in memory usage between these two solutions (in Python) to finding the maximum depth of a binary tree? It looks like the first solution uses a helper function for recursive calls but it's doing the same thing as the second solution. Having trouble understanding this. ~5KB used

  1. People also search for