Plz Help me! its Urgent!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anadiks
    New Member
    • Oct 2006
    • 4

    Plz Help me! its Urgent!

    plzzz if any 1 give me d solution for the following problem, i'll be really greatful to him/her.


    Problem 1: Optimization

    A C++ class has the following member:

    int status_[75];

    During performance analysis it was found out

    that the class (its object) was performing unsatisfactoril y

    making it a necessary candidate for optimization.

    The following additional information was also found out

    *) Each element of the status_ array assumes only the

    following 4 values: -1, 0, 1, 2

    *) The bulk of the time was spent in loops like:

    for(size_t i=0; i != 75; ++i) {

    if(status_[i] == 1) {

    // do something...

    }

    }

    *) The set of elements of the status_ array that assume a particular

    value is sparse making the above loop inefficient.

    Assume that 0 is the default value.

    *) The status_ array is updated at places scattered throughout the code

    making it difficult to rewrite. However, a particular element

    is updated only through a statement like

    status[i] = -1;



    Task: You can write this in C# or C++ syntax or pseudo code. The idea is to come up with the best and most efficient algorithm, considering the above information.

    Note:

    The optimization should introduce the least bugs possible.

    The “For loop” exists all over the place in the code.

    The solution you send us should not require any change to the existing code.

    Please note that the 4 values: -1, 0, 1, 2, occur in any position across the status_ array.
  • D_C
    Contributor
    • Jun 2006
    • 293

    #2
    I would use four singly linked lists instead of an array. One would be for each corresponding value, -1 through 2. Then you can just iterate through each list. If you modify one, remove it from one list, and insert it into another. Each node should keep an artificial array index.

    Comment

    Working...