C How to Program (8th Edition)
C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter D, Problem D.6E

(Bucket Sort) A bucket sort begins with a one-dimensional array of positive integers to be sorted, and a two-dimensional array of integers with rows subscripted from 0 to 9 and columns subscripted from 0 to n 1 , where n is the number of values in the array to be sorted. Each row of the two-dimensional array is referred to as a bucket. Write a function bucketsort that takes an integer array and the array size as arguments.

The algorithm is as follows:

  1. Loop through the one-dimensional array and place each of its values in a row of the bucket array based on its ones digit. For example, 97 is placed in row 7, 3 is placed in row 3 and 100 is placed in row 0.
  2. Loop through the bucket array and copy the values back to the original array. The new order of the above values in the one-dimensional array is 100, 3 and 97.
  3. Repeat this process for each subsequent digit position (tens, hundreds, thousands, and so on) and stop when the leftmost digit of the largest number has been processed.

On the second pass of the array, 100 is placed in row 0, 3 is placed in row 0 (it had only one digit so we treat it as 03) and 97 is placed in row 9. The order of the values in the one-dimensional array is 100, 3 and 97. On the third pass, 100 is placed in row 1, 3 (003) is placed in row zero and 97 (097) is placed in row zero (after 3). The bucket sort is guaranteed to have all the values property sorted after processing the leftmost digit of the largest number. The bucket sort knows it’s done when all the values are copied into row zero of the two-dimensional array. The two-dimensional array of buckets is ten times the size of the integer array being sorted. This sorting technique provides far better performance than a bubble sort but requires much larger storage capacity. Bubble sort requires only one additional memory location for the type of data being sorted. Bucket sort is an example of a space—time trade-off. It uses more memory but performs better. This version of the bucket sort requires copying all the data back to the original array on each pass. Another possibility is to create a second two-dimensional bucket array and repeatedly move the data between the two bucket arrays until all the data is copied into row zero of one of the arrays. Row zero then contains the sorted array.

Blurred answer
Students have asked these similar questions
INPUT: Don't CareOUTPUT: Don't CareWrite a function that will combine two arrays of different lengths into another array. Express the function's running time in terms of actual running time and Big-Oh notation. For reference, this is the function declaration:  void combine(int* comb_arr, int* arr1, int n, int* arr2, int m) where comb_arr- the array used to combine arr1 and arr2 arr1 - the first array n - the length of the first array arr2 - the second array m - the length of the second array   INITAL CODE TO BE COMPLETED #include <iostream>using namespace std;void combine(int*, int*, int, int*, int); int main(void) {    // Hey there, start typing your C++ code here...    int size1, size2;    cin >> size1;    int arr1[size1];    for (int i = 0; i < size1; i++) {      cin >> arr1[i];    }    cin >> size2;    int arr2[size2];    for (int i = 0; i < size2; i++) {      cin >> arr2[i];    }    int comb_size = ___;    int comb_arr[comb_size];…
subject: programming Language: C++  Write a program with a function which accepts an array of integers and a key value.The function should return the sum of all the multiples of the key value in the array. For example, for the array {1, 4, 10, 12, 15, 20, 22} and the key value 5, the function should return the sum 10+15+20.
C++ Programming. OVERVIEW OF DATA STRUCTURES. Task: Write a program to process a data array. Execute a custom task as a separate function or method of a custom class. When performing a task, use functional methods for manually entering array elements, generating random numbers, and printing array elements. Given an array of size N. Create a function to determine the element that is furthest from the arithmetic mean of the array elements (that is, the maximum absolute difference).

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License