1
$\begingroup$

I am currently studying computer science and we were given assignment to implement two algorithm(Insertion sort and Merge sort) and run them in order to track their running times across different input arrays. And ask us to do: "Your task is to run each algorithm 3 times on 5 input arrays with 5, 50, 500, 5000, and 50000 random integers each, and report their running times both as a table and "n vs. time" plots"

I have already implemented algorithm but I am not sure how to calculate runtime of both algorithm. Any help would be appreciated. Thank you.

$\endgroup$

closed as off-topic by Yuval Filmus, Evil, David Richerby, Juho, Rick Decker Mar 3 '17 at 13:51

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development or programming tools are off-topic here, but can be asked on Stack Overflow." – Yuval Filmus, Evil, David Richerby, Juho, Rick Decker
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ The running time of an algorithm in this context just means how many seconds passed from the moment the algorithm started to the moment it finished. You can measure this from within your program by querying the system clock. This is a programming question, so off-topic here. $\endgroup$ – Yuval Filmus Mar 2 '17 at 2:48
  • $\begingroup$ You are not supposed to calculate the running time. You are supposed to run the code and measure the time. $\endgroup$ – gnasher729 Mar 3 '17 at 0:13
  • $\begingroup$ yeah I mean to ask in that way. Can you please tell me how to do that. $\endgroup$ – pooja gajera Mar 3 '17 at 1:12
0
$\begingroup$

In sorting algorithms you can count the number of comparsions and consider it as run time of worst case. Just add one static counter in your code it will reflect the time complexity in a better form. Otherwise the general approach of calculating run time works fine always. Most language has a function that gives system time.

$\endgroup$
  • $\begingroup$ Hi may I know which function to use to calculate time in java ? $\endgroup$ – pooja gajera Mar 2 '17 at 20:16
  • $\begingroup$ System.currentTimeMillis() ; $\endgroup$ – Deep Joshi Mar 3 '17 at 6:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.