Calculating function time

For an upcoming final I know theres going to be questions about how to calculate how long a function takes. I was never really able to understand it, and the prof is unavailable until the exam which is obviously too late. Does anyone know how to explain it? or at least very clear websites/tutorials? All of my google searches came up empty.
For instance, here is a question that has been given and I have no idea how to calculate it at all.
To within a constant factor, how much time does the following
Java method take, as a function of the length n of string s?
(reverse(s) produces the reversal of s. For example, reverse("abc")
= "cba".)
public static String reverse(String s)
int n = s.length();
int k = 0;
String result = "";
while(k < n)
result = s.charAt(k).toString() + result;
k = k + 1;
return result;
}Also, if you are able to explain how to write more efficient functions, that would be greatly appreciated as well.
Thanks

That's not phrased well. When he says "how much time", what he really means (if he's not insane) is how many steps are taken to run through the algorithm. This more-or-less maps to time spent running the algorithm, because the steps all take roughly the same amount of time to do.
This is often also called "complexity".
It's usually described in terms of "big-O notation", such as "O(nlogn)". O(nlogn) means that for an input data set of size n, the algorithm performs on the order of n * log(n) steps, times some constant.
I'm glossing over the details here myself. Look up "big-O notation" or "algorithm analysis" on wikipedia.

Similar Messages

  • Calculating over time

    Hi I am making up a time sheet calculator (example below), and need help figuring out how to calculate overtime.
    I figured out how to calculate total time for the day ( SUM=(B2-A2)+(D2-C2) )
    and calculating over time is simple if the total time is greater then 8. as in row 2 or 3. ( SUM=(E2-8) )
    My problem comes when Total Time is less then 8hrs, I start getting negative Over Time. as in row 4.
    I know that I need to tell Numbers that if total time is less then 8 Over Time needs to Equal 0. I just don't know how to do that.
    The only Function I know how to use is the SUM function.
    Any help would be greatly appreciated.
    Thanks
    Example
    A
    B
    C
    D
    E
    F
    G
    1
    In
    Out
    In
    Out
    Total Time
    Regular Time
    Over Time
    2
    8.02
    12.99
    13.97
    17.04
    8.04
    8
    0.04
    3
    8
    13
    14
    17
    8
    8
    0
    4
    8.1
    12.94
    14.03
    16.94
    7.75
    8
    -0.25

    Sam,
    OT = MAX(totaltime - 8hours, 0)
    With that expression, Overtime will never go negative.
    Jerry

  • HT1338 In order to some calculator functions on the "Bankrate" website I need to enable the Java Browser function.  I can I accomplished that task?

    In order to some calculator functions on the "Bankrate" website I need to enable the Java Browser function.  I can I accomplished that task?

    In recent versions of Lion, Java is automatically disabled (for security reasons) if it goes unused for a certain amount of time.  You can re-enable it in the General pane of the Java Preferences app, found in /Applications/Utilities.  (Check the box at the top of that pane.)  If trying to open Java Preferences results in a message asking if you want to install Java, you don't actually have Java yet.  Click the install button to install it.
    Note that having Java turned on in your web browser is dangerous, due to recent proliferation of malware that uses Java to install itself.

  • How to perform calculations on time? (e.g., time x 26.2?)

    I need to do various calculations on time, such as:
    (1) Marathon finish time is 3:39:00 (h:mm:ss). Divide by 26.2 to get the pace (minutes per mile).
    (2) I run 0.935 miles in 6:57 (m:ss). Divide 6:57/0.935 to get the pace.
    These were dead-simple in AppleWorks. My formulas were simply =A1/26.2 and =A2/0.935 respectively. But I'm having a sinking feeling that I can't do it in Numbers, at least not easily. I did find the TIMEVALUE() function, so for the first problem I can use the more cumbersome =TIMEVALUE(A2)/26.22460, but then my result is in decimal form (8.35878), and I can't find a way to get it back into time format (8:22).

    Michael Bluejay wrote:
    I need to do various calculations on time, such as:
    (1) Marathon finish time is 3:39:00 (h:mm:ss). Divide by 26.2 to get the pace (minutes per mile).
    (2) I run 0.935 miles in 6:57 (m:ss). Divide 6:57/0.935 to get the pace.
    These were dead-simple in AppleWorks. My formulas were simply =A1/26.2 and =A2/0.935 >respectively. But I'm having a sinking feeling that I can't do it in Numbers, at least not easily.
    The original premise of your question was incorrect. You can most definitely divide a duration by a number and avoid having to convert from a decimal back to a duration.
    You may be using the wrong format for your data (what you are calling "time") and that is probably the root of the problem. Time and duration are two different things. TIMEVALUE works on the date&time data type, not durations. If TIMEVALUE is not giving you an error, your durations are not durations but are, instead, the date and time of day.
    Here are two equations that work just fine in Numbers if the 3h 39m is a duration value.
    3h 39m/26.2 = 0h 8m 21s 527ms (hms format)
    3:39/26.2 = 0:08:21.527 (colon format)
    If you want to convert a decimal value to a duration, use the DURATION function. That is not necessary for what you are trying to do but I present it because you asked. If you want to convert 3:39:00 to 8:22, make sure the 3:39:00 is a duration and not "January 25, 2010 3:39:00AM" then divide the 3:39:00 by 26.2

  • Why are calculation functions lost from Reader Extended PDF when downloaded from website?

    I am creating PDF forms with most fields performing calculations. I am saving the forms out as Reader Extended PDF> Enable Additional Features. When I email the form there is no problem with the person using the form, all calculations work. The person is able to save the form and all info is present.
    However, when the same file is posted on a website with a clickable link to download, once downloaded, all the calculation functions are missing from the fields. Additionally, when the user fills the form out anyway, the info in the fields is invisible.
    I am on a MAC OS 10 using Acrobat X Pro. The majority of the people going to the website and using the forms are on Windows. What am I doing wrong?

    It sounds like you're actually using the Preview application when viewing the form on your Mac. It does not support JavaScript, which is how the automatic calculations are implemented. It also corrupts forms when it saves them. A result of this corruption is when the form is subsequently opened in Acrobat/Reader, the fields are blank unless a field has the focus. For more information, see: http://kb2.adobe.com/community/publishing/885/cpsid_88564.html

  • How to do calculation on time value?

    I have "Duration" as a column in a source excel file which contain data like 00:00:06,00:01:10  when i connect this excel to lumira i am getting the column data as [$-5400]12:00:06\AM 
    please specify how to perform certain calculation on time value like sum or avg. 

    I'm struggling to think of examples of this kind of data 00:00:06,00:01:10
    so i suspect this formatting will be troublesome..if Lumira can't handle this using advanced acquisition properties, then it might be an idea to split it before coming into lumira . 
    regards,
    H

  • Calculating total time.

    I'm somewhat new to using spreadsheets. Basically I just want to keep track of the time I spend doing a particular job. So I'm tracking my start time, end time, and then I want to calculate the total time spent. Thanks.

    Yes, I thought about that. But if you start at say
    9pm and end at 2am you would get the incorrect result
    of 7 hours. I think I have to convert the time to
    something else before the math takes place. But I'm
    not sure how that would work.
    I'm not sure how you managed to subtract 9pm from 2pm and get 7 hours. When I try 2am - 9pm, I get #VALUE!, as AppleWorks reads both 'times' as text, and cannot use Text values in a formula that requires numbers. AppleWorks is a bit fussy on what it considers to be a number.
    Using the default alignment, you can recognize what AppleWorks thinks is a number—it will be aligned to the right of the cell—and what AW considers to be Text—it will be aligned to the left of the cell. In the case of Time, you're better off using the 24 hour clock, and entering one minute betore 2pm as 13:59.
    The Mac clock's unit of time is the (24 hour) Day, and all times entered are regarded as the portion of one day that has elapsed up to that time. When you do the subtraction, the result is also a time of day. For start and end times within the same calendar day, simply doing the subtraction will give a result that can be read as the (correct) elapsed time. For the example times you gave, the 'correct' result is also visible:
    02:00 - 21:00 = 05:00
    But the actual numbers behind that 05:00 result and the two times used to get it are the portion of the current day that has passed up to each of the times entered, and the difference obtained when you do the subtraction:
    0.0833 - 0.8750 = -0.7917
    If you only want the (readable) result for a single day, that's not a problem. But if you want to add the results to get a total time for a week, you need to (make AppleWorks) do some additional math. In simplest terms, you need to add 1 to the end time if the end time is on the calendar day after the start time. There's an explanation of this below, which you should read for a better understanding of Time and the Mac, but which isn't necessary to use the formula.
    The formula assumes your start time is in column B, your end time in column C, your formula reporting time worked is in column D, and that you will enter times in rows 2..6, and calculate the week's sum in D7
    Enter in D2, and fill down to D6: =IF(C2,C2-B2+(C2<B2),"")
    Format these cells to display as Time.
    Enter in D7: =24(SUM(D2..D6)) —to report the result in hours (eg. 25.678)
    Format the cell to display as Number, General.
    or
    Enter in D7: =INT(24(SUM(D2..D6))&":"MINUTE(SUM(D2..D6)) —to report the result as hours and minutes
    Note that the second option for D7 produces a text string which will not be useable in further calculations.
    This is Text, so no Number formatting is necessary.
    Regards,
    Barry
    Time and the Mac
    The Mac clock tracks time in Days and Fractions of a Day, starting at midnight, January 1, 1904.
    Nine PM today, May 8, 2006, represented as a decimal number, is 37383.875. Two AM tomorrow, May 9, 2006, is 37384.0833333333.
    An AppleWorks spreadsheet cell (or database field) formatted to display as Time will ignore the whole number part of those numbers, and interpret the decimal fraction part as Time of Day, and display the result in the Time format you have chosen for the cell.
    A cell (or field) formatted to display as a Date will ignore the fractional part of the number, and display the whole number part in the Date format you have chosen.
    When you enter a time, the result is the time of day on January 1, 1904. When calculating elapsed times where start and end times cross the midnight boundary, you need to add 1 (day) to the result to compensate for the change in day and get a result that can be used in further calculations. That's what the "+(C2<B2)" part of the first formula above does—adds 1 if "(C2<B2)" is TRUE or adds 0 it it's false.
    If you add times, the result is 'correct', but if the total reaches 24 hours, the displayed result will appear incorrect as a Time formatted cell ignores the whole number part of the actual result (eg. 27 hours, or 1.25 days), will display as 03:00, the same as 3 hours, or 0.25 days. You can convert the result to hours and fractions of hours by simply multiplying the result by 24, and displaying it as a Number rather than as Time.
    B

  • What is included in the calculation functionality of the database?

    Hi there,
    I have read that - as SAP BW has to support several database products - the set of calculation functionality has been reduced to the lowest common denominator. Is that correct?
    What are the calculation commands that are processed by the database and what operations are left for the OLAP engine in terms of GROUP BY, SUM, MIN, MAX, COUNT, DISTINCT COUNT....
    Are there papers where this functionality is written down?
    Thanks & Regards,
    Pascal

    The "other" is normally <1 GB, and includes the iOS, app data, messages and email.  If it expands, this usually means ther is either corrupted data or metadat (file system errors) in the phone.
    To fix, Restore the phone, first using a backup and if needed as new (without using a backup)
    iOS: How to back up and restore your content

  • Apple TV Export Calculating Estimated Time Lockup

    Looking for some help here... I am exporting video from QTPro to Apple TV. Just recently, when I go to FILE/EXPORT choose Apple TV then OK, the export dialog comes up but says "Exporting -- Calculating Estimated Time" and just sits there for a short 100MB HDV - Apple Intermediate Codec file.
    Any thoughts? This work fine since upgrading to 7.1.5 until just today. Tried repairing permissions, re-installing QT 7.1.5, reboot, did not help.

    I found that if I copy and paste the original file into a new QuickTime movie, the export worked as it should. I wanted to post a followup in case anyone else encounted this issue.

  • Searching for Calculation function like "@TONUMBER()" (Business Rules)

    Hello,
    I am searching for a calculation function like "@TO_NUMBER()" or a workaround.
    My current problem is as follows:
    @CONCATENATE("AAA_",(@SUBSTRING("BBB_2010",4) - 1) doesnt work --> SUBSTRING function returns "2010" (as STRING value, but then I cannot substract 1).
    Besides I am missing another function like @TO_STRING(), too, because @CONCATENATE("AAA_",2010) doesnt work - @CONCATENATE expects STRING and not NUMBER.
    Can anybody help?
    Thanks & kind regards
    André

    Hi Krish,
    thanks, but I would like to avoid using cdfs...
    I have another idea, but it doesnt work, too (I opened another thread):
    calculating with temporary variables doesnt work - does anybody knows the reason (and have a workaround for me)?
    Herewith my code:
    VAR varLoopAmount = 15;
    VAR varShiftValue = 1;
    LOOP(varLoopAmount)
    "Schadenquote BOZ" = "Schadenquote BOZ" + @SHIFT(&GCS_SchwaRue_Historie,varShiftValue,@ICHILDREN(&GCS_SchwaRue_Historie));
    varShiftValue = varShiftValue + 1;
    ENDLOOP;
    error message: Detail:(1012004): Invalid member name [varShiftValue]
    Thanks for help
    André
    Edited by: user10660408 on 04.06.2010 12:25

  • Sequence of steps n Material quantity calculation functionality

    Hi, Pls advise the sequence of steps involved in MQC functionality in Master Recipe? Thank You.

    Hi Raju,
    Below are the steps you can explore.
    1. Assign Classification to component if you are using any batch classification values for calculation of other components. This you can do it in BOM section of Master recipe.
    2. Now goto calculation tab for the component of which quantity calculation is required.
    3. In this screen you can see the characteristic assigned for calculation in batch classification as per step 1.
    4. You can insert simple calculation formula using reference of these cells. The reference is simple like the references we have in excel. For example (001; 002) this given you value in 1st column & 2nd row.
    5. At the time of batch determination or quantity change in Process order please make sure to click on Calculation tab & then save. This is required to get the quantity calculated as per formula.
    Hope this will help you.
    Please let us know the industry you are working in. This will help all to help you better.
    Regards,

  • Variation calculation without time series?

    Hi all.
    I've got a pivot table like the one below. Time series is not implemented in the rpd, due to performance reasons. Is there a way to calculate the variation between two measures on two different dates in a pivot table (Difference column below), similar to what we achieve using the AGO() timeseries function. The dates are chosen by the user from a dashboard prompt, so I am not sure if calculated item would apply here and dynamic items ($1, $2) does not work too. The pivot table has more columns and rows than the example below.
    _________________Dates
    Product___01/10/11____02/10/11____Difference
    A__________10_________15___________5
    B___________8__________6___________-2
    C___________8__________8___________0
    Thank you.
    Regards,
    Edited by: user10634835 on 03-Oct-2011 01:54
    Edited by: user10634835 on 03-Oct-2011 02:06
    Edited by: user10634835 on 03-Oct-2011 02:08

    Hi,
    By using $2 - $1 in the new calculated item under pivot table view.
    Ex:
    Name 3-10-2011 1-10-2011 diff
    dev 423 400 23
    let say from date =1-10-2011 refer as $1
    to date =3-10-2011 referd as $2
    *$2-$1 will get any two date difference..fully automatically*
    *100% it will work...i have also implemented the same*
    Thanks
    Deva
    Edited by: Devarasu on Oct 3, 2011 5:18 PM

  • How do I reference multiple tables in SSAS Data Source View Named Calculation functionality?

    Hi SSASers - 
    On the Data Source View node of SSAS Visual Studio Interface, I want to create a named calculation that references multiple tables. Something like: CASE WHEN tableA.Column1 = 'Y' Then tableB.Column1 ELSE tableB.Column2 End, but the compiler throws an error
    here "Deferred prepare could not be completed". 
    What is the syntax for referencing multiple tables on this node or how else can multiple tables be used to create a calculated value in SSAS? I'm new to SSAS and so far have been building big views and building calculations this way. Another option is the
    Calculation tab off the cube node but this calculation will need to be based off of dimensions AND measures so please provide a syntax example here also. 
    Thanks in advance!
    Carl

    Thanks Jiri! The named query functionality off the Data Source View node is exactly what I was looking for - it's just a view on the SSAS side of things instead of the relational dbase.
    Sorry for the delayed answer verification - got pulled into something else last week. Carl 
    Carl

  • Using variables in a calculation function in Diadem script

    Hey guys,
    I'm new to working with Diadem Scripts.  I have tried the two different ways below to make the values of a channel equal to the results of a formula containing created variables.  I can do it if the formula contains values in place of the variables using the calculator method.  I would appreciate any guidance on how to correct the syntax in the below scripts.
    Option Explicit 'Forces the explicit declaration of all the variables in a script.
    dim a, b, c
    a = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef1").Value
    b = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef2").Value
    c = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef3").Value
    Ch ("[2]/ROP (ft/hr)") = a + b* Ch("[2]/Backhead Pressure (psi)") + c* Ch("[2]/Backhead Pressure (psi)")^2
    Or
    Option Explicit 'Forces the explicit declaration of all the variables in a script.
    dim a, b, c
    a = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef1").Value
    b = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef2").Value
    c = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef3").Value
    call ChnCalculate("Ch(""[2]/ROP (ft/hr)"")="&a+&b"*Ch(""[2]/Backhead Pressure (psi)"")+"&c"*Ch(""[2]/Backhead Pressure (psi)"")^2")

    I think you need to use channel name strings of the format "Group Name/Channel Name" in your ChnCalculate function.  I usually use a formula, a symbol array, and a value array to get this done:
    Dim a, b ,c, sFormula, aSymbols, aValues
    Redim aSymbols(6), aValues(6)
    aSymbols(0) = "a"
    aSymbols(1) = "b"
    aSymbols(2) = "c"
    aSymbols(3) = "A"
    aSymbols(4) = "B"
    aValues(0) = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef1").Va
    lue
    aValues(1) = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef2").Value
    aValues(2) = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef3").Value
    aValues(3) = Data.Root.ChannelGroiups(2).Channels("ROP (ft/hr)").GetReference('ref type')
    aValues(4) = Data.Root.ChannelGroiups(2).Channels("Backhead Pressure (psi)").GetReference('ref type')
    sFormula = "Ch(A) = a + b*Ch(B) + c*(Ch(B))^2"
    Call ChnCalculate(sFormula,aSymbols,aValues)
    CLAD

  • Problem in VAT Calculation @ the time of MIRO

    Dear All,
    We are using the Tax Procedure TAXINN.
    When we create a LIV document with ref to a PO using the transaction MIRO & when I check the calculate tax button, the tax amount which is displayed in the Basic data is more than the amount which is displayed in the taxes tab.
    For Ex:
    Created a PO with the following details.
    Total Qty in PO -  10
    Base Price - 1000/qty.
    BED - 14% - 1400.00
    ECS - 2% -      28.00
    VAT - 4% - (4% on 11428) - 457.12
    So my total Tax = 1885.12 (Including Excise & VAT).
    Now when I create a MIRO document the tax amount which gets calculated when I check the Calculate button is 1885.12 (Same as above) in the Taxes tab of MIRO.
    But the tax amount which is displayed in the Basic data tab is 1,942.24
    Also when I simulated the MIRO entrys the VAT amount which was simulated was - 514.24  & not 457.12 as in PO.
    Can anyone please advice on the reason for this mismatch in VAT calculation during the time of MIRO?
    Is there any specific settings for VAT in TAXINN ??
    Note :
    The Excise & VAT are calculated correctly during the time of PO creation. Also I havent maintained any additional VAT condition types for my VAT in the tax procedure.
    Awaiting helpful replies.
    Regards,
    Edited by: SAP FC on Dec 5, 2008 3:44 PM

    Hi All,
    Please note that when I removed the VAT condition type JVRD from the Classify condition types settings in IMG  then the VAT amount which is calculated in the Basic data tab of MIRO is equal to the actual Tax amount as in PO (Excise + VAT ), but the amount which is displayed in the tax tab of MIRO is less.
    Now if I maintain the Classify condition types settings in IMG for my VAT condtn type JVRD then the VAT amount which is calculated in basic data is more than both the PO as well as tax tab in MIRO.
    Please note  as you all have suggested I tried this after creating a new material & with the newly maintained condition records in FV11.
    But still the issue persists..
    If anyone have any idea. plz revert.
    Regards,
    Edited by: SAP FC on Dec 9, 2008 10:23 AM

Maybe you are looking for

  • How to execute or call other application

    I have doubt in executing or calling any exe file using java application. For example: i have a button. If i click on that button, then any application (eg. any exe file, any program file, etc) will execute and come out in the different frame. Now, i

  • Ess career and age iview problem

    Hi I have implemented ess. and when executing career and age following error is coming Business Server Page (BSP) error What happened? Calling the BSP page was terminated due to an error. SAP Note The following error text was processed in the system:

  • HR ABAP Learning.

    Hi Friends,       Iam working as an ABAP Consultant.       I want to enhance it to HR ABAP. <removed - requesting copyrighted material is prohibited > regards, phaneendra p Edited by: Arun Varadarajan on Apr 7, 2009 3:35 PM

  • Oracle 10g grid - Job details

    Hi, I logged into the Grid as SYSMAN and added 2 targets(A and B). I created 2 jobs related to target A and 2 jobs related to target B. 1. Where can I find the details of these 4 jobs? i.e., which system tables have these information like job name, e

  • A low-level exception occurred in Adobe Player (Player)? no playback

    Help! I start premiere and playback wont work at all - It gives me the error "A low-level exception occurred in Adobe Player (Player) I tried cleaning the cache and duplicating the sequence - nada Premiere Pro CC 7.2.1 (4) Recent updates installed Ma