What is this asking for?
Now let B(n) be the time it takes to sort n elements for bubbleSort. Let Q(n) be the time it ta开发者_高级运维kes for quickSort to sort n elements. Let M(n) be the time it takes for mergeSort. to sort n elements . In a Word document or in a text file, create a table of the following data which your program(s) will produce using the functions you developed in 1) 2) 3) and 4).
n B(n) B(n)/n^2 ......... etc i just need to know what this is asking for
1000
2000
4000
8000
16000
one question what is B(n) asking for in this ? I already finish coding and it shows me number of comparison and number of swaps. Do i need a stop watch to time it or something?!?!
I just dont get what it is asking for
For what I understand the question asks you to state how many operations would the algorithms need to perform for each of the input sets.
For example, if insertion sort is O(n^2), you'd have
n O(n^2) ...
1000 1000000
2000 2000000
4000 4000000
.
.
.
You could implement a stopwatch, using time related functions.
However, from my experience, such homework assignments usually ask for number of comparisons and not actual time. Actual time will vary from Environment to Environment.
"using the functions you developed in 1) 2) 3) and 4)"
you must have very precise definitions of B(n) if you developed them in 1, 2, 3, 4 -- use those rather than those suggested here. they should look like polynomials over n with integer coefficients and powers.
If you're after a good grade:
Your homework mentions a program you have created, presumably that implements the algorithms you listed. Add some timing code that prints system ticks before and after performing a sort with 1000,2000,4000,8000,16000 items. Then subtract the difference, and put the time taken into your answer table.
Then do what the other guys say, and create a new answer table with the theoretical "Big O" answers.
Ideally you'd overlay both as a graph to highlight the difference between theory and your implementation.
精彩评论