由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教一个binary tree问题
相关主题
有没有觉得这个面试问题有点膈应?Unique Binary Search Trees的变形
贴一道老算法题Binary Tree Maximum Path Sum
How many full binary trees?[leetcode] Maximum Depth of Binary Tree
初始化binary tree[leetcode] Minimum Depth of Binary Tree 我的这个答案说wrong answer,但是我在本地跑就是对的.
问个Binary Search Tree定义的问题cc150上面binary tree找所有sum==target的path,不一定从root出发
Careercup 4.9解释一下?关于检查Binary tree是否balanced
请问根节点的parent是根节点本身么?serialize n-ary tree 一问
Test if two binary tree are equalWrite an iterative method that finds depth of a (non-balanced) binary tree.
相关话题的讨论汇总
话题: tree话题: 节点话题: binary话题: sum话题: max
进入JobHunting版参与讨论
1 (共1页)
t**g
发帖数: 1164
1
一个unbalanced binary tree
每个节点记录一个整数
对每个节点值
左边的child小于当前节点
右边的child大于当前节点
所以你插入1,2,3,4,5...n,会得到一个depth=n的树
可是插入6,4,8,3,5,7,9,就会得到一个well balanced tree
问题:
What is the average asymptotic depth of a simple unbalanced search tree of
integers? Use O(n) notation and provide proof
g*******y
发帖数: 1930
2
h(n) = 1 + 1/n * SUM{ max(h(i), h(n-1-i) } where i=0....n-1
max( h(i) , h(n-1-i) ) = h(max(i , n-1-i))
=>
h(n) = 1 + 2/n * SUM{ h(n/2+i) } where i=0...n/2-1
= 1 + < h(x) > where x = n/2 ... n with uniform distribution
then I am not quite sure about a strict math proof, but you can definitely "
try" the solution to prove it is O(logn)
1 (共1页)
进入JobHunting版参与讨论
相关主题
Write an iterative method that finds depth of a (non-balanced) binary tree.问个Binary Search Tree定义的问题
Amazon 3rd phone interview (software engineer intern)Careercup 4.9解释一下?
问个amazon面试题请问根节点的parent是根节点本身么?
报个Uber电面面经Test if two binary tree are equal
有没有觉得这个面试问题有点膈应?Unique Binary Search Trees的变形
贴一道老算法题Binary Tree Maximum Path Sum
How many full binary trees?[leetcode] Maximum Depth of Binary Tree
初始化binary tree[leetcode] Minimum Depth of Binary Tree 我的这个答案说wrong answer,但是我在本地跑就是对的.
相关话题的讨论汇总
话题: tree话题: 节点话题: binary话题: sum话题: max