Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 16, Problem 8PC
Program Plan Intro

Sorting Benchmarks

Program plan:

  • Create the class “SortingBenchmarks”,
    • Declare the required variables.
    • Define the method “bubbleSort()”,
      • Use “for” loop to sort the elements in the ascending order.
      • Increment the count of bubble sort by 2 on each comparison and swaps on the elements.
      • Return the count of bubble sort.
    • Define the method “selectionSort()”,
      • Use “for” loop to find the smallest value in the array and continue the process until the array becomes sorted.
      • Increment the count of selection sort by 2 on each comparison and swaps on the elements.
      • Return the count of selection sort.
    • Define the method “insertionSort()”,
      • Use “for” loop to insert the elements at the correct position and swap the elements based on comparisons.
      • Increment the insertion sort by 1.
      • Return the count of insertion sort.
    • Define the method “quicksort()”,
      • Call the method “doquicksort()” to sort the elements using the pivot value.
      • Increment the quick sort by 1.
    • Define the method “doquick_sort()”,
      • Call the method “partition()” to partition the array values into two halves.
      • Call the method “doquick_sort()” recursively to sort the left half of the values in the array.
      • Call the method “doquick_sort()” recursively to sort the right half of the values in the array.
    • Define the method “partition()”,
      • Calculate the pivot value.
      • Call the “swap()” method to swap the array values.
      • Use “for” loop to scan the entire array and based on pivot value, call the “swap()” method to swap and arrange the values in order.
    • Define the method “swap()”,
      • Swap the values and increment the quick sort count by 2.
  • Create the class “SortingBenchmarkTest”,
    • Define the “main()” function,
      • Use “for” loop to insert random of at least 20 integers for each sorting.
      • Create the object for the “SortingBenhcmarkTest” class,
      • Call the method “bubbleSort()” to sort the values in order.
      • Call the method “selectionSort()” to sort the values in order.
      • Call the method “insertionSort()” to sort the values in order.
      • Call the method “quickSort()” to sort the values in order.
      • Print the sorted elements of each sorting and then print the number of comparisons made by each sorting.

Blurred answer
Students have asked these similar questions
8. Repetition Use Python Language Write a method that takes in an array as a parameter and counts the repetition of each element. That is, if an element has appeared in the array more than once, then its 'repetition' is its number of occurrences. The method returns true if there are at least two elements with the same number of 'repetition'. Otherwise, return false. Input: {4,5,6,6,4,3,6,4} Output: True Explanation: Two numbers repeat in this array: 4 and 6. 4 has a repetition of 3, 6 has a repetition of 3. Since two numbers have the same repetition output is True. Input: {3,4,6,3,4,7,4,6,8,6,6} Output: False Explanation: Three numbers repeat in this array:3,4 and 6 .3 has a repetition of 2, 4 has a repetition of 3, 6 has a repetition of 4. Since no two numbers have the same repetition output is False.
Median Function – In statistics, the median of a set of values is the value that lies in the middle when the values are arranged in sorted order.   If the set has an even number of values, the median is the average of the two middle values.  Your program should start with two arrays of integers containing the following values: Even numbered array:  17 32 45 68 99 101 67 89 22 27 Odd numbered array:   17 32 45 68 99 101 67 89 22 Using a sort function of your choice, first sort the arrays.  NOTE:  you may use the Standard Template Library sort function or your own sort function. Then, write a function that determines the median of a sorted array.   The function should take an array of numbers and an integer indicating the size of the array and return the median of the values in the array.   The same function should be called twice – once for the even array and once for the odd array. Your program should also have a printArray function that can be used to print the sorted array. (It…
Task 3: Statistics using arrays: by java programming With the spread of COVID 19, the HR department in a company has decided to conduct some statistics among the employees in order to determine the number of infections according to some conditions. For each employee, they have to record the code, name, age, whether he/she was infected or no and the remaining days of leaves for him/her. You are requested to write the program that maintains the lists of details for the employees as mentioned above using the concept of arrays. The program repeats the display of a menu of services until the user decides to exit. 1. Start by initializing the employee details by reading them from the keyboard. 2. Repeat the display of a menu of 4 services, perform the required task according to the user’s choice and asks the user whether he/she wants to repeat or no. You need to choose one service from each category (‘A’,’B’,’C’,’D’) a. A. Display the total number of employees that were infected b. B.…

Chapter 16 Solutions

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage