Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ question

  • 17-05-2009 7:19pm
    #1
    Registered Users, Registered Users 2 Posts: 929 ✭✭✭


    I have an exam tomorrow, and one of my lectures was inept...didnt know how to teach. This here is a question from his sample paper and I have no clue how to do it. Can anyone help??


    Given a series of n daily price quotes for a share, the span of a
    shares price on a certain day is the maximum number of
    consecutive days up to the current day that the price of the
    stock has been less than or equal to its price on that day. Write
    down in pseudo code a quadratic time algorithm which takes an
    n-element array P of share prices and calculates an n-element
    array S of spans.


Comments

  • Registered Users, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    Basically, you have an array of share prices.
    You want to traverse the array backwards for each price in the array, until you determine the span for the day, checking if the current value of P is greater or equal to the days before it. Insert this value into the Span array.

    You want an answer like this...
    P = { 0, 1, 2, 1 }
    S = { 0 ,1, 2, 0 }

    A Quadratic time algorithm for doing this should give you a bit of leeway
    ie: You can use a nested loop.

    So basically, start with an Array of size N to hold your share values, and create an Array of size N to hold your spans.


Advertisement