Iは、最初に、私はO(nlogn)実行時間はO(nlogn)と一致しますか?
Collections.sort(アレイ、新しい SortingObjectsWithProbabilityField())を有し、ソート方法を使用したことクラス(貪欲なストラテジ)に書かれています。
、その後、私は別のn
ためO(h)
とh here is the tree height.
を取るbinary search tree
のinsertメソッドを使用し、実行している時間は次のようになります。私は理由高めるために正しくないと思い
n,running time
17,515428
33,783340
65,540572
129,1285080
257,2052216
513,4299709
nでは、実行時間はほとんど増加するはずです。
このメソッドは、実行中の時間がかかります。
Exponent = -1;
for(int n = 2;n<1000;n+=Math.pow(2,exponent){
for (int j = 1; j <= 3; j++) {
Random rand = new Random();
for (int i = 0; i < n; i++) {
Element e = new Element(rand.nextInt(100) + 1, rand.nextInt(100) + 1, 0);
for (int k = 0; k < i; k++) {
if (e.getDigit() == randList.get(k).getDigit()) {
e.setDigit(e.getDigit() + 1);
}
}
randList.add(e);
}
double sum = 0.0;
for (int i = 0; i < randList.size(); i++) {
sum += randList.get(i).getProbability();
}
for (Element i : randList) {
i.setProbability(i.getProbability()/sum);
}
//Get time.
long t2 = System.nanoTime();
GreedyVersion greedy = new GreedyVersion((ArrayList<Element>) randList);
long t3 = System.nanoTime();
timeForGreedy = timeForGreedy + t3 - t2;
}
System.out.println(n + "," + "," + timeForGreedy/3);
exponent++;
}
おかげ
質問は何:参考
は、ここにプロットを生成するために使用gnuplotスクリプトですか? –
質問は何ですか? –
実行時間が間違っていますか?またはそれはO(nlogn)と一致しますか? – user472221