由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Quant版 - one algorithm problem
相关主题
[合集] 面试问题 (转载)要面一个algorithm trader的职位
几道面试题问一下algorithm的书
问编程题若干求推荐C++和programming/算法面试书籍
[合集] A question about two different positions in one company.想做编程方面的金融工作 PhD level的,如何准备
[合集] A brain teaser question[合集] volatility increase,all call option really increase?
[合集] Which math/stat language is most popular on the street?What is the solution of the recursive formula?
[合集] interview question (programming)一个统计问题
来一道题(由 BT question 而想)Multi Demensional Optimisation
相关话题的讨论汇总
话题: num话题: int话题: algorithm话题: each话题: problem
进入Quant版参与讨论
1 (共1页)
g****g
发帖数: 228
1
given an array a of n elements, set a[i] = n!/i (for simplicity, i starts
from 1)
now you have a computer that cannot do division /, how can you set value for
each element of array within o(n) time, assuming each multiplication or
addition is o(1).
g****g
发帖数: 228
2
by the way, I don't know the answer yet. I was thinking to factorize n=i*j,
then a[i]=a[n]*j, a[j]=a[n]*i. but factorization also requires division and
this process cannot be done in 0(n) since I might have to a[n-1], a[n-3] too
if they cannot be factorized.
h*****u
发帖数: 1
3
notice that a_k = b_k * c_k, where
b_k = (k+1)*b_{k+1} and c_k = (k-1)*c_{k-1}, with b_n = 1 and c_1 = 1.
thus the algorithm goes as follows:
(1) a_n <- 1
(2) for k = (n-1) ... 1, a_k <= (k+1)*a_{k+1}
(3) t <- 1
(4) for k = 2 ... n, t <- (k-1)*t then a_k <- t*a_k
in each loop (2) or (4) there are O(n) multiplications/additions, so the total
time complexity is O(n). The temporary variable t is used to make the
algorithm more readable, if temporaries are not allows, we can use a_1 to
replace t a
g****g
发帖数: 228
4
thanks. it would work.
j*******2
发帖数: 18
5
void getArray(int num)
{
int* a = new int[num + 1];
a[0] = 1;
a[1] = 1;
for(int i = 2; i < num + 1; i ++)
a[i] = a[i - 1] * (i - 1);
for(int j = num - 1; j > 0; j --)
{
a[0] = a[0] * (j + 1);
a[j] = a[j] * a[0];
}
for(int k = 1; k < num + 1; k ++)
printf(" %d",a[k]);
delete [] a;
}
1 (共1页)
进入Quant版参与讨论
相关主题
Multi Demensional Optimisation[合集] A brain teaser question
请教一道 hedge fund 电面算法题[合集] Which math/stat language is most popular on the street?
刚刚电话interview完,提供题目[合集] interview question (programming)
[合集] 一道面试c程序题来一道题(由 BT question 而想)
[合集] 面试问题 (转载)要面一个algorithm trader的职位
几道面试题问一下algorithm的书
问编程题若干求推荐C++和programming/算法面试书籍
[合集] A question about two different positions in one company.想做编程方面的金融工作 PhD level的,如何准备
相关话题的讨论汇总
话题: num话题: int话题: algorithm话题: each话题: problem