Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

hay look at my recursive pow

Name: Anonymous 2009-03-04 20:14


#include <stdio.h>
#include <stdlib.h>

unsigned long long rpow(int n, int p) {
  return p ? p==1 ? n : n * rpow(n,p-1) : 1;
}

int main(int argc, char **argv) {
  if(argv[1])
    if(argv[2]) {
      int n = atoi(argv[1]);
      int p = atoi(argv[2]);
      printf("%llu\n",rpow(n,p));
    }
  return 0;
}

Name: Anonymous 2009-03-12 18:34

>>134
That isn't how time complexity works.
For example, time complexity taken to solve a maze does not include the time taken to generate the maze you are solving or the time taken to read the maze structure from an input file if that is the case. In a similar way, fetching a value from a lookup table (which is what needs to be done inside the pow() function in this case) is a constant time operation, where as generating and making said table usable may not be.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List