# Sorting in Java

Not what you're looking for?

Part (A) Sort the array 15 80 35 25 60 30 into descending order using

a) the selection sort.

b) the buble sort.

Part (B) A first year student attempted to write mergesort in pseudocode as follows.

mergesort(theArray, n) {

if (n > 1){ // more than one item to sort

mergesort(left half of theArray, n/2)

mergesort(right half of theArray, n/2)

}

}

a) The above algorithm has a fundamental flaw. As written, how does it change theArray?

b) What is the worst-case runtime of this incorrect algorithm? Give as tight an asymptotic upper bound as possible, using Big-Oh notation as a function of n. Justify your answer.

The original course website where the problem comes from is here, I think it will be helpful if you take a look at it first: www.student.math.uwaterloo.ca/~cs134

##### Purchase this Solution

##### Solution Summary

Sorting in Java is emphasized. The selection sort and bubble sort functions are examined.

##### Solution Preview

Part (A) Sort the array 15 80 35 25 60 30 into descending order using

a) the selection sort.

Answer:

The selection sort (in descending order) is described as: performs sorting by repeatedly putting the largest element in the unprocessed portion of the array to the head of this unprocessed portion until the whole array is sorted. To sort array 15 80 35 25 60 30 into descending order, the following steps will be taken:

• Find the largest element in the unsorted portion of the array which is the original array. The element found is 80, exchange it with the head of the unsorted array which is ...

##### Purchase this Solution

##### Free BrainMass Quizzes

##### C++ Operators

This quiz tests a student's knowledge about C++ operators.

##### Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

##### Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

##### Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

##### Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.