binary-tree

Leetcode question to finding the longest univalue path [closed]

a 夏天 提交于 2020-04-30 09:14:23
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 8 months ago . Question: Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root. The length of path between two nodes is represented by the number of edges between them. source A solution to this is

Leetcode question to finding the longest univalue path [closed]

纵饮孤独 提交于 2020-04-30 09:12:34
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 8 months ago . Question: Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root. The length of path between two nodes is represented by the number of edges between them. source A solution to this is

Leetcode question to finding the longest univalue path [closed]

不打扰是莪最后的温柔 提交于 2020-04-30 09:12:21
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 8 months ago . Question: Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root. The length of path between two nodes is represented by the number of edges between them. source A solution to this is

Generate all expressions from list of numbers equal to a number [PROLOG]

本小妞迷上赌 提交于 2020-04-11 04:45:31
问题 I am given a list of numbers, for example [22,45,2,6,7,...] . Now I have to insert binary operators: + , - , / , * and parentheses ( , ) between numbers so that expression is equal to given number k . List all possible expressions created by insertions of operators and parentheses that will give sum of k . Position of numbers in resulting expression have to be fixed, i.e. only insertion of operators and parentheses between or around numbers For example : given number k=9 and list [1,2,3] ,

Generate all expressions from list of numbers equal to a number [PROLOG]

陌路散爱 提交于 2020-04-11 04:43:41
问题 I am given a list of numbers, for example [22,45,2,6,7,...] . Now I have to insert binary operators: + , - , / , * and parentheses ( , ) between numbers so that expression is equal to given number k . List all possible expressions created by insertions of operators and parentheses that will give sum of k . Position of numbers in resulting expression have to be fixed, i.e. only insertion of operators and parentheses between or around numbers For example : given number k=9 and list [1,2,3] ,

Binary Trees Count Number of Leaves

放肆的年华 提交于 2020-02-01 09:43:06
问题 Suppose you already have the basic binary tree procedures isempty(bt), root(bt), left(bt), and right(bt). Write a procedure isLeaf(bt) that returns true if the binary tree bt is a leaf node and false if it is not. This is what I have: proc isLeaf(bt) if (isEmpty(bt)) error('The binary tree is empty.'); elseif (left(bt) < right(bt)) return true; else return false; Then write a procedure numLeaves(bt) that returns the number of leaves in the binary tree bt. This is what I have: proc numLeaves

Binary Trees Count Number of Leaves

纵饮孤独 提交于 2020-02-01 09:43:05
问题 Suppose you already have the basic binary tree procedures isempty(bt), root(bt), left(bt), and right(bt). Write a procedure isLeaf(bt) that returns true if the binary tree bt is a leaf node and false if it is not. This is what I have: proc isLeaf(bt) if (isEmpty(bt)) error('The binary tree is empty.'); elseif (left(bt) < right(bt)) return true; else return false; Then write a procedure numLeaves(bt) that returns the number of leaves in the binary tree bt. This is what I have: proc numLeaves

Balanced Binary Search Tree for numbers

拈花ヽ惹草 提交于 2020-01-26 04:45:45
问题 I wanted to draw a balanced binary search tree for numbers from 1 to 20. _______10_______ / \ ___5___ 15 / \ / \ 3 8 13 18 / \ / \ / \ / \ 2 4 7 9 12 14 17 19 / / / / 1 6 11 16 Is the above tree correct and balanced? 回答1: In answer to your original question as to whether or not you need to first calculate the height, no, you don't need to. You just have to understand that a balanced tree is one where the height difference between the tallest and shortest node is zero or one, and the simplest

Deleting the lowest value in a binary search tree

牧云@^-^@ 提交于 2020-01-25 17:26:54
问题 I wrote this and somehow it's ending up deleting all my left side on the tree not only the most left leaf. I can't find my mistake, can someone help? struct Node *delMin(struct Node **root) { struct Node *current = *root; struct Node *b4Current; while ((current->m_ls) == NULL) { b4Current = current; current = current->m_ls; } if ((current->m_rs) == NULL) { b4Current->m_ls = 0; free(current); } else { b4Current->m_ls = current->m_rs; free(current); } return *root; } 回答1: Let's look at your

Deleting the lowest value in a binary search tree

寵の児 提交于 2020-01-25 17:22:21
问题 I wrote this and somehow it's ending up deleting all my left side on the tree not only the most left leaf. I can't find my mistake, can someone help? struct Node *delMin(struct Node **root) { struct Node *current = *root; struct Node *b4Current; while ((current->m_ls) == NULL) { b4Current = current; current = current->m_ls; } if ((current->m_rs) == NULL) { b4Current->m_ls = 0; free(current); } else { b4Current->m_ls = current->m_rs; free(current); } return *root; } 回答1: Let's look at your