ArkhamWarfare
ArkhamWarfare

Reputation: 121

How to compare time complexity performance of two programs

I have two programs, and I need to compare the time complexity/performance of these two programs where n is in millions. How do I do that? I'm lost. Perhaps I am overthinking it. For both programs, running it only returns the nth value, so what data do I use?

Upvotes: 1

Views: 682

Answers (2)

ArkhamWarfare
ArkhamWarfare

Reputation: 121

I just figured it out how. I've been overthinking it way too much. I do fib(1) graph value and time
Then fib(5)
Then
Fib(10)
Fib(100)
Fib(1000)
Fib(10000)
Fib(100000)
Fib(1000000)
And then graph the seconds and nth value

Upvotes: 1

krpra
krpra

Reputation: 474

suppose you have to sort a million number of elements stored in array. You use any two different algorithm for sorting like- bubble sort and merge sort.

If you have 10^7 elements then bubble sort will sort in maximum 10^14 steps and merge sort will sort in maximum 4 x 10^8 steps. you can count the number of steps taken by both sorting algorithm.

EDIT: to generate and store random numbers

  #include <time.h>
  #include <stdlib.h>
  #define SIZE 1000000
  int numbers[SIZE]

  void generate()
  {      
  srand(time(NULL));   // should only be called once
  for(int i=0;i<SIZE;i++)
   numbers[i]= rand();      // returns a pseudo-random integer between 0 and RAND_MAX
  }

Upvotes: 0

Related Questions