Question

Hey, I ran Bubble Sort, Merge Sort, and Quick Sort under the following inputs: List of...

Hey, I ran Bubble Sort, Merge Sort, and Quick Sort under the following inputs:

List of 1000 numbers drawn from 0--9.

List of 1000 numbers drawn from 0--99.

List of 1000 numbers drawn from 0--999.

List of 1000 numbers drawn from 0--9999.

List of 1000 numbers drawn from 0--99999.

List of 1000 numbers drawn from 0--999999.

List of 10000 numbers drawn from 0--9.

List of 10000 numbers drawn from 0--99.

List of 10000 numbers drawn from 0--999.

List of 10000 numbers drawn from 0--9999.

List of 10000 numbers drawn from 0--99999.

List of 10000 numbers drawn from 0--999999.

List of 100000 numbers drawn from 0--9.

List of 100000 numbers drawn from 0--99.

List of 100000 numbers drawn from 0--999.

List of 100000 numbers drawn from 0--9999.

List of 100000 numbers drawn from 0--99999.

List of 100000 numbers drawn from 0--999999.

List of 1000000 numbers drawn from 0--9.

List of 1000000 numbers drawn from 0--99.

List of 1000000 numbers drawn from 0--999.

List of 1000000 numbers drawn from 0--9999.

List of 1000000 numbers drawn from 0--99999.

List of 1000000 numbers drawn from 0--999999.

These were my results:

BubbleSort:

[1000]

0-9: 9 ms

0-99: 9 ms

0-999: 9 ms

0-9999: 9 ms

0-99999: 9 ms

0-999999: 9 ms

[10000]

0-9: 156 ms

0-99: 167 ms

0-999: 171 ms

0-9999: 171 ms

0-99999: 173 ms

0-999999: 171 ms

[100000]

0-9: 15967 ms

0-99: 17079 ms

0-999: 17172 ms

0-9999: 17173 ms

0-99999: 17220 ms

0-999999: 17175 ms

[1000000]

0-9: 1664472 ms

0-99: 1740240 ms

0-999: 1759920 ms

0-9999: 1758476 ms

0-99999: 1770420 ms

0-999999: 1761082 ms

MergeSort:

[1000]

0-9: 1 ms

0-99: 1 ms

0-999: 1 ms

0-9999: 1 ms

0-99999: 1 ms

0-999999: 1 ms

[10000]

0-9: 3 ms

0-99: 3 ms

0-999: 3 ms

0-9999: 3 ms

0-99999: 3 ms

0-999999: 3 ms

[100000]

0-9: 17 ms

0-99: 19 ms

0-999: 19 ms

0-9999: 20 ms

0-99999: 21 ms

0-999999: 21 ms

[1000000]

0-9: 128 ms

0-99: 140 ms

0-999: 150 ms

0-9999: 157 ms

0-99999: 167 ms

0-999999: 167 ms

QuickSort:

[1000]

0-9: 1 ms

0-99: 1 ms

0-999: 1 ms

0-9999: 1 ms

0-99999: 1 ms

0-999999: 1 ms

[10000]

0-9: 11 ms

0-99: 5 ms

0-999: 3 ms

0-9999: 3 ms

0-99999: 2 ms

0-999999: 2 ms

[100000]

0-9: 372 ms

0-99: 49 ms

0-999: 17 ms

0-9999: 13 ms

0-99999: 13 ms

0-999999: 13 ms

[1000000]

0-9: Here I get a Stack Overflow, can you please explain why this happens?

0-99: 4190 ms

0-999: 450 ms

0-9999: 118 ms

0-99999: 95 ms

0-999999: 95 ms

My question is, how would I make graphs using this data for:

-Time against size of the list, for each value upper-bound.

-Time against value upper-bound, for each list size.

How many graphs would this total out to?

Also if you can please explain why that stack overflow happens it would be much appreciated.

Here is the source code for QuickSort:

   public static int[] quickSort(int[] numbers) {

       quickSortHelper(numbers, 0, numbers.length - 1);

       return numbers;
   }

   private static void quickSortHelper(int[] numbers, int init, int last) {

       if ((last - init) < 1 || (last < 0)) {
           return;
       }

       int pivotIndex = partitionList(numbers, init, last);

       quickSortHelper(numbers, init, pivotIndex - 1);
       quickSortHelper(numbers, pivotIndex + 1, last);

   }

   private static int partitionList(int[] numbers, int init, int last) {
       int lastAssignedPos = init;

       for (int i = init; i < last; ++i) {
           if (numbers[i] < numbers[last]) {
               swap(numbers, lastAssignedPos, i);
               ++lastAssignedPos;
           }
       }

       swap(numbers, last, lastAssignedPos);
       return lastAssignedPos;
   }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

To make graph for "Time against size of the list, for each value upper-bound", you first figure out all the upper bounds, in this case its 0-9, 0-99, 0-999, 0-9999, 0-99999 and 0-999999, that is 6 upper bounds:

For each of these upper bounds you will have 1 graph, to plot each of this graph you will pick up each of the upper bound and start plotting graph with time in y-axis and list size in x- axis

Example, for all 0-9 results for bubble sort, you have this data:

DATA SIZE TIME TAKEN(ms)
1000 9
10000 156
100000 15967
1000000 1664472

Using this you can lot a graph for data size(x-axis) against time(y-axis)

You will repeat this for all 6 upper bouds. ANd for all 3 sorting algorithms.

You willl thus have 6*3 = 18 such graphs.

To make graphs for "Time against value upper-bound, for each list size", you first figure out different list sizes, which is 4(1000,10000,100000,1000000) in your case.

For each of thse data sizes you can plot a graph for upper bound in x-axis against time in y-axis.

Example for data size 1000 and bubble sord you have this data:

Upper Bound Time Taken(ms)
0-9 9
0-99 9
0-999 9
0-9999 9
0-99999 9
0-999999 9

Using this you can lot a graph for upper bound(x-axis) against time(y-axis)

You will repeat this for all 4 upper bouds. And for all 3 sorting algorithms.

You willl thus have 4*3 = 12 such graphs.

You will have a total of 18 + 12 = 30 such graphs.

---------------------------------------------------------------------------------------------------------------------------------

Now for you question on stack overflow. You have a stack overflow when there are too many one function calls for the processor, more function calls than what the memory can handle.

In your case you have a stack overflow, because the data size here is 1000000 and the spread of elements is not so great, you only have to choose from 0 to 9. Basically even if you have a uniform spread every element will appear 100000 times, which means at some point a sub-array of length 100000 will partition at the first element and you will end up having 100000 open quickSortHelper function calls, which is probably too much for you processor to handle. And hence the stack overflow.

Add a comment
Know the answer?
Add Answer to:
Hey, I ran Bubble Sort, Merge Sort, and Quick Sort under the following inputs: List of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python - Recursive to non-recursive quick sort. What I have at the moment is a recursive...

    Python - Recursive to non-recursive quick sort. What I have at the moment is a recursive quick sort, I need to make it non-recursive, any help is appreciated! def quickSort(list):     quickSortHelper(list, 0, len(list) - 1) def quickSortHelper(list, first, last):     if last > first:         pivotIndex = partition(list, first, last)         quickSortHelper(list, first, pivotIndex - 1)         quickSortHelper(list, pivotIndex + 1, last) # Partition list[first..last] def partition(list, first, last):     pivot = list[first] # Choose the first element as...

  • I really need help with this, please. This is a java programming assignment. Project 1 The first programming project inv...

    I really need help with this, please. This is a java programming assignment. Project 1 The first programming project involves writing a program that computes the salaries for a collection of employees of different types. This program consists of four classes. 1. The first class is the Employee class, which contains the employee's name and monthly salary, which is specified in whole dollars. It should have three methods: a. A constructor that allows the name and monthly salary to be...

  • I want to compare the runtimes and swap operations times among quick Sort, selection Sort and...

    I want to compare the runtimes and swap operations times among quick Sort, selection Sort and shell Sort here is my code: But when I create a 1000,000 size array, I can't get the result of the operations times and runtime. what's wrong with my code? and I also want to copy the array. Because I want to use same array for three sort. And for the shell Sort, I haven't learn it in my class. Can anyone help me...

  • Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. E...

    Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...

  • JAVA- Trace the recursive quick sort and partition methods in Lab6.java for this list of numbers:...

    JAVA- Trace the recursive quick sort and partition methods in Lab6.java for this list of numbers: 47 71 15 35 66 61 44 26 68 56 18 19 36 84 69 55 1. Find the value of pivot 2. Show the result after partitionIt() is called first time 3. Show the value of partition 4. Show the content of the array ///////////////////////////// Lab6.java class ArrayIns { private long[] theArray; // ref to array theArray private int nElems; // number of...

  • Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In...

    Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In this project, we combine the concepts of Recursion and Merge Sorting. Please note that the focus of this project is on Merging and don't forget the following constraint: Programming Steps: 1) Create a class called Art that implements Comparable interface. 2) Read part of the file and use Merge Sort to sort the array of Art and then write them to a file. 3)...

  • I need to program 3 and add to program 2 bellows: Add the merge sort and...

    I need to program 3 and add to program 2 bellows: Add the merge sort and quick sort to program 2 and do the same timings, now with all 5 sorts and a 100,000 element array. Display the timing results from the sorts. DO NOT display the array. ____________________>>>>>>>>>>>>>>>>>>>>___________________________ (This is program 2 code that I did : ) ---->>>>>> code bellow from program 2 java program - Algorithms Write a program that randomly generates 100,000 integers into an array....

  • Can I get some help with this question for c++ if you can add some comments...

    Can I get some help with this question for c++ if you can add some comments too to help understand that will be much appreciated. Code: #include <cstdlib> #include <getopt.h> #include <iostream> #include <string> using namespace std; static long comparisons = 0; static long swaps = 0; void swap(int *a, int *b) {     // add code here } void selectionSort(int *first, int *last) {     // add code here } void insertionSort(int *first, int *last) {     // add code here }...

  • 5.8 Sort Linked List Use mergersort to sort a linked list Do not use the following...

    5.8 Sort Linked List Use mergersort to sort a linked list Do not use the following libraries: algorithm, cmath. Do not load the values into a vector and sort them. The sort must be done with a linked list Example Two lists 6->3->1->2->4->5 will return a list with 1->2->3->4->5->6. Input There will be no input read in anymore. Going forward use the hard-coded input on the template and ensure the program works. There will be one compare output test based...

  • I am currently using eclipse to write in java. A snapshot of the output would be...

    I am currently using eclipse to write in java. A snapshot of the output would be greatly appreciated to verify that the program is indeed working. Thanks in advance for both your time and effort. Here is the previous exercise code: /////////////////////////////////////////////////////Main /******************************************* * Week 5 lab - exercise 1 and exercise 2: * * ArrayList class with search algorithms * ********************************************/ import java.util.*; /** * Class to test sequential search, sorted search, and binary search algorithms * implemented in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT