Results 1 to 3 of 3
  1. #1
    JordashTalon is offline Member
    Join Date
    Jan 2009
    Posts
    37
    Rep Power
    0

    Default Calculating the Running time

    I have a problem like this:

    In terms of N, what is the running time of the following algorithm to compute X^N

    Java Code:
    public static double power(double x, int n)
    {
      double result=1.0;
      for(int i=0; i< n; i++)
        result*=n;
      return result;
    }
    How would I go about solving that?

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Running time?

    You mean how long it would take to solve the ecuation? Like how many millisecs it would take? You want to time it?

    CJSL

    EDIT: I forgot to mention that you are not using the "x" variable that's passed as a parameter to the method. I'm pretty sure it has to be used in the method somehow...
    Last edited by CJSLMAN; 02-13-2009 at 11:23 PM.
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    R O C K Y's Avatar
    R O C K Y is offline Member
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default

    just use start_Date = new Date();

    //ur code


    and end_Date = new Date();
    calculate running time as :end_date - start_Date.(in ms)

Similar Threads

  1. Replies: 1
    Last Post: 01-12-2009, 09:59 AM
  2. Need help with calculating the time the user...
    By Smirre in forum New To Java
    Replies: 8
    Last Post: 11-20-2008, 02:15 PM
  3. Calculating per hour statistics
    By vipergt89 in forum New To Java
    Replies: 2
    Last Post: 05-01-2008, 07:25 AM
  4. Calculating the DB connection time
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-20-2008, 09:55 AM
  5. Calculating sin of a double value
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 09:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •