Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are going to write a program that is capable of sorting an array of random integers. There are several well known sorting algorithms (

You are going to write a program that is capable of sorting an array of random integers. There are several well known sorting algorithms ( if you don't want to come up with your own ). Shell sort, selection sort, bubble sort, merge sort, quick sort, and counting sort. You can come up with your own idea or use one of these. Here are some other details that might be of interest to you.

When the program starts, the user is asked several questions. The min random number, the max random number, and the total number of random numbers to be sorted. The user is also asked if they would like to see the sorted and unsorted lists printed. NOTE: this is to be done BEFORE you generate the random numbers and before your preform your sort. I will set the rang to be 1-1000, and I will ask for 1 million integers to be sorted. I will also not want to see the unsorted and sorted lists. using nlogn algorithms and 15 points to programs that use 2n algorithms.

Two basic sorting algorithms

In case you have trouble coming up with your own sorting algorithm, allow me to describe two relatively simple algorithms.

The first, and worst, is called Rob Sort. Here is what you do. First, you have an array of random integers as input (lets call it a). Generate two numbers between 0 and the number a.length-1. Lets call these numbers i, and j. Then swap a[i] and a[j]. Then we check to see if the array is sorted. If it is, we are done. If not, then generate two more random numbers and so on. How do you check to see if an array is sorted? First check to see that a[0] < a[1]. Then check to see if a[1] < a[2], and so on, all the way up to a[a.length-2] and a[a.length-1].

I doubt many of you will want to do Rob Sort. So let me suggest bubble sort. Here is what you do. You make a pass through the array. For each pass you check to see if a[0] < a[1]. If not, swap a[0] and a[1]. Then check to see if a[1] < a[2], if not, then swap. Then check a[2] and a[3], and so on. Again, all that is considered one pass through the array. Then if you do a.length passes, you are assured to have a sorted array!

Using Java and two more algo!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

107 MA ammeter 56 resistor ? V voltmeter

Answered: 1 week ago

Question

Generally If Drug A is an inducer of Drug B , Drug B levels will

Answered: 1 week ago