I have been staring at this problem for an hour havent figured it out. Any help would be appreciated
古いコメントを表示
Write a script to compare the respective times tq(n) and tb(n) that it takes to sort a random vector of length n as a function of n for n ranging from 1 to numbers as large as 100000 or more. Prepare a well labelled plot of the ratio of tb(n)/tq(n) versus n, where tb is time for the bubble sort and tq is the time for the quicksort employed by MATLAB. On the same plot, plot the ratio of the averages mean(tb(:))/mean(tq(:)) versus n.
採用された回答
その他の回答 (1 件)
Seth
2014 年 12 月 14 日
0 投票
3 件のコメント
Star Strider
2014 年 12 月 14 日
I’ve been there myself.
There are probably a number of ways to do this.
This is one:
L = 250; % Length Of Random Vector
N = 100; % # Iterations
for k1 = 1:N
rv = randi(100,1,L);
tic % Start Timer
qks = sort(rv);
qst(k1) = toc; % Stop Timer, Record Quicksort Time
tic
bls = sin(log(rv)); % Insert Bubble Sort Call Here
bst(k1) = toc; % Stop Timer, Record Bubblesort Time
end
I used a made-up function (that does no sorting) for the bubblesort call, to be certain the code works.
You may need to change the code to do your assignment, since your instructor may have specific requirements. Nevertheless, this should get you started.
Seth
2014 年 12 月 15 日
Star Strider
2014 年 12 月 15 日
My pleasure!
カテゴリ
ヘルプ センター および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!