我试图推导出确定性线性搜索算法的平均案例运行时间.该算法按照A [1],A [2],A [3] ...... A [n]的顺序搜索未排序数组A中的元素x.它在找到元素x时停止或继续直到它到达数组的末尾.我在维基百科上搜索,给出的答案是(n + 1)/(k + 1),其中k是数组中x的存在次数.我以另一种方式接近并得到了不同的答案.任何人都可以给我正确的证据,也让我知道我的方法有什么问题吗?
E(T)= 1*P(1) + 2*P(2) + 3*P(3) ....+ n*P(n) where P(i) is the probability that
the algorithm runs for 'i' time (i.e. compares 'i' elements).
P(i)= (n-i)C(k-1) * (n-k)! / n!
Here, (n-i)C(k-1) is (n-i) Choose (k-1). As the algorithm has reached the ith
step, the rest of k-1 x's must be in the last n-i elements. Hence (n-i)C(k-i).
(n-k)! is the total number of ways of arranging …Run Code Online (Sandbox Code Playgroud) 我试图在matlab中找到图像的傅里叶变换.我这样做没有库函数的功能.代码是:
clc;
clear;
N=128;
a=imread('lena128','bmp');
zeros(N,N);
for m=1:N
for n=1:N
w(m,n)=(exp(-1i*2*pi/N))^((m-1)*(n-1));
end
end
af1=(w*a);
af=((w*(af1.')).');
Run Code Online (Sandbox Code Playgroud)
编译此程序时,会发生以下错误:
??? Error using ==> mtimes
Complex integer arithmetic is not supported.
Error in ==> qn4 at 12
af1=(w*a);
Run Code Online (Sandbox Code Playgroud)
当我使用a = rand(1,128)而不是a = imread('lena128','bmp')时,我没有得到那个错误.我在网上搜索,发现了类似的问题.但没有解决方案.任何人都可以为我指出错误吗?
我在第三方服务器中有一个 MySQL 数据库。我正在尝试使用 Dreamweaver 中的 PHP 从本地计算机访问它。但是,我收到以下错误:
MySQL 错误#2002:连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接的主机未能响应而建立的连接失败。
谢谢。
我是Perl的新手,我正在尝试写一个单词频率计数器作为学习练习.
但是,在我处理之后,我无法在下面的代码中找出错误.这是我的代码:
$wa = "A word frequency counter.";
@wordArray = split("",$wa);
$num = length($wa);
$word = "";
$flag = 1; # 0 if previous character was an alphabet and 1 if it was a blank.
%wordCount = ("null" => 0);
if ($num == -1) {
print "There are no words.\n";
} else {
print "$length";
for $i (0 .. $num) {
if(($wordArray[$i]!=' ') && ($flag==1)) { # start of a new word.
print "here";
$word = $wordArray[$i];
$flag = 0; …Run Code Online (Sandbox Code Playgroud)
我有这门课:
public class Friend {
private String name;
private String location;
private String temp;
private String humidity;
public String getTemp() {
return temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
public String getHumidity() {
return humidity;
}
public void setHumidity(String humidity) {
this.humidity = humidity;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location; …Run Code Online (Sandbox Code Playgroud) string ×2
algorithm ×1
collections ×1
comparable ×1
comparison ×1
dreamweaver ×1
fft ×1
java ×1
matlab ×1
mysql ×1
performance ×1
perl ×1
php ×1
search ×1
sorting ×1