由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Computation版 - Help for an algorithm, Thanks
相关主题
Algorithm 课程及教材选择疑问fft algorithm
Any algorithm for speech recognise?求不等式组是否有解的问题:
[转载] Anybody tried sorting algorithm from NR?[转载] 问一个蠢问题:算法方面的课
问个专业问题,请帮助看看Evolutionary Algorithms
urgent question!Statistical Global Optimization Algorithms
Implementation of Genetic AlgorithmA stupid question
pls help a list of global optimization帮我看看这个C语言错误
问一个关于genetic algorithm 的问题 讨论一下GA算法
相关话题的讨论汇总
话题: algorithm话题: half话题: find话题: first话题: given
进入Computation版参与讨论
1 (共1页)
r****e
发帖数: 9
1
Given an array A with positive numbers, find an efficient algorithm to find
out the Maximum of A[j]-A[i], j>i.
My solution is: Divide the array into two parts, first half and second half.
Then the location of j and i have three possibles. 1) j,i are in the first
half. 2) j, i are in the second half. 3) i is in the first and j in sencond.
For 1) and 2), I can use recursive to find out. For 3) I need to find out the
minimum element in the first half and the maximum element in the second half.
Then
m****e
发帖数: 7
2
Here's an O(n) one: (Given array A[0..(n-1)])
int x=A[0],y=A[1]-x;
for (int i=1;i if (x>A[i]) x=A[i];
if (y }
return y;

【在 r****e 的大作中提到】
: Given an array A with positive numbers, find an efficient algorithm to find
: out the Maximum of A[j]-A[i], j>i.
: My solution is: Divide the array into two parts, first half and second half.
: Then the location of j and i have three possibles. 1) j,i are in the first
: half. 2) j, i are in the second half. 3) i is in the first and j in sencond.
: For 1) and 2), I can use recursive to find out. For 3) I need to find out the
: minimum element in the first half and the maximum element in the second half.
: Then

1 (共1页)
进入Computation版参与讨论
相关主题
讨论一下GA算法urgent question!
introduction to algorithmsImplementation of Genetic Algorithm
请问,这种会议如何pls help a list of global optimization
matlab参数拟合问一个关于genetic algorithm 的问题
Algorithm 课程及教材选择疑问fft algorithm
Any algorithm for speech recognise?求不等式组是否有解的问题:
[转载] Anybody tried sorting algorithm from NR?[转载] 问一个蠢问题:算法方面的课
问个专业问题,请帮助看看Evolutionary Algorithms
相关话题的讨论汇总
话题: algorithm话题: half话题: find话题: first话题: given