由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Quant版 - 问个算法题
相关主题
[合集] 面试问题 (转载)[合集] 这道C语言问题如何解答?
[合集] interview question (programming)[合集] interview question
问个排列组合题?关于涉及C++的面试,俺的一点总结
[合集] A brain teaser question[ Prob ] 面试题求助~
one statistic interview question[合集] C++: operator new 为啥要是 static的, 不是有啥影响? (
Question on Formula for APRa questiong regarding Structured Finance
[合集] 两个brainteaser questions 求解? 多谢.谁知道答案, 看你算得快马?
[合集] An interview questionAn Excel Test that I failed
相关话题的讨论汇总
话题: variable话题: element话题: search话题: global话题: static
进入Quant版参与讨论
1 (共1页)
f*****s
发帖数: 141
1
Given a Binary Search Tree, write a program to print the kth smallest
element without using any static/global variable.
什么方法最好?
s*******s
发帖数: 1568
2
in-order searching
f*****s
发帖数: 141
3
In-order traverse always generate value-sorted output, right? So, just use
in-order searching, traverse from 1st element until the k-th element. Is
this correct?
d*j
发帖数: 13780
4
肯定是对的, 人家又要问 有没有 better way ?
这也是肯定的

【在 f*****s 的大作中提到】
: In-order traverse always generate value-sorted output, right? So, just use
: in-order searching, traverse from 1st element until the k-th element. Is
: this correct?

b******v
发帖数: 1493
5
如果k<=n/2,可以从最小元开始做k-1次FindNext
如果k>n/2,可以从最大元开始做n-k次FindPrevious
时间复杂度O(k'*log(n)),其中k' = min{k, n-k+1}

【在 f*****s 的大作中提到】
: Given a Binary Search Tree, write a program to print the kth smallest
: element without using any static/global variable.
: 什么方法最好?

k*******d
发帖数: 1340
6
用in-order search能不使用global variable吗?search的时候得用个变量来记录这搜
索到第几个元素了吧?然后当这个变量等于k的时候,停止搜索。这个变量算是global
variable/static variable吗?
我觉得如果要用递归实现这个遍历的话难以避免要用到这个global variable/static
variable吧, 所以这个题的关键应该是不用递归来实现inorder遍历吧,答案可以
google到
f*********g
发帖数: 207
7
isn't it k'+o(log(n))?

【在 b******v 的大作中提到】
: 如果k<=n/2,可以从最小元开始做k-1次FindNext
: 如果k>n/2,可以从最大元开始做n-k次FindPrevious
: 时间复杂度O(k'*log(n)),其中k' = min{k, n-k+1}

1 (共1页)
进入Quant版参与讨论
相关主题
An Excel Test that I failedone statistic interview question
一道概率题Question on Formula for APR
两个面试题[合集] 两个brainteaser questions 求解? 多谢.
求推荐:统计书[合集] An interview question
[合集] 面试问题 (转载)[合集] 这道C语言问题如何解答?
[合集] interview question (programming)[合集] interview question
问个排列组合题?关于涉及C++的面试,俺的一点总结
[合集] A brain teaser question[ Prob ] 面试题求助~
相关话题的讨论汇总
话题: variable话题: element话题: search话题: global话题: static