Google Answers Logo
View Question
 
Q: Data structure and algorithm ( No Answer,   1 Comment )
Question  
Subject: Data structure and algorithm
Category: Computers > Algorithms
Asked by: math01-ga
List Price: $3.00
Posted: 16 Jul 2003 08:09 PDT
Expires: 20 Jul 2003 23:53 PDT
Question ID: 231628
Analyze the complexity (in big-O terms) of the following
selection-sort routine. The routine picks out the largest element in
the current list and exchanges it with the last element. It continues
until the list has only one element:

for (i = n-1; i > 0; i--) {
        MaxPosition = i;
        for (j = 0; j < i; j++) {
                if (a[j] > a[MaxPosition])
                        MaxPosition = j;
        }
        exchange(i, MaxPosition);
}
Answer  
There is no answer at this time.

Comments  
Subject: Re: Data structure and algorithm
From: stephenvakil-ga on 17 Jul 2003 09:44 PDT
 
Shouldn't this be the same order as a bubble sort, as it is basically
a reversed bubble sort?  Bubble sort has a worst case and average case
O(n)^2

There are several analyses of bubble sort that you can find by
searching google for "Bubble Sort Complexity"

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy