seriously i need help :( can u help me?

Discussion in 'Programming' started by uurcm, May 29, 2009.

  1. #1
    hi my firedns. we'r workink to our "final exams". C++ teacher gave all questions to us. but we cant solve this question. can u help me?

    Here is the question:
    -) Algorithm design steps(sub-optimal desing)
    THis always searches the entire list whether the item was found or not.
    if there are duplicate copies of the search target item, this will find the last occurence of it. (average#iterations=maximum#iterations=list lenght):

    1.Initialize foundindex=-1
    2.loop:int.index=start,while index<=end,increment index by 1
    a) compare list item at [index] position with searchitem
    -) if equal,set foundindex=index
    3.After loop exit,if foundindex > -1, search succeded, otherwise search field. Return foundindex.
    a) execution trace example(sub-optimal design)

    [​IMG]

    -) Algorithm design steps(optimal design)
    this ends the search when the item is found, and only searches the entire list if the item is not the list. if there are duplicate copies of the search target item, this will find the first occurence of it.(average#iterations=list lenght/2,maximum#iterations=list lenght):
    1-) Initialize found = (boolean)
    loop: init.index=start,while index <= end and found == false,increment index by 1.
     
    uurcm, May 29, 2009 IP
  2. uurcm

    uurcm Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if I could solve, I would not write here. thnx for your answer anyway
     
    uurcm, May 29, 2009 IP
  3. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #3
    It appears that you have a solution in mind. How can we assist?
     
    Social.Network, May 29, 2009 IP