Sort the following numbers using the counting Sort method: 3, 7, 8, 4, 6, 9, 8, 10, 2, 1, 5.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Sort the following numbers using the counting Sort method:
3, 7, 8, 4, 6, 9, 8, 10, 2, 1, 5.
Transcribed Image Text:Sort the following numbers using the counting Sort method: 3, 7, 8, 4, 6, 9, 8, 10, 2, 1, 5.
Expert Solution
Step 1

Step 1:-

Counting sort :-

For simplicity, consider the data in the range 0 to 10

Input data: 3,7,8,4,6,9,8,10,2,1,5

1)count array is

   Index:      0  1  2  3  4  5  6  7  8  9  10
   Count:      0  0  0  0  0  0  0  0  0  0   0

2) Take a count array to store the count of each unique object.


  Index:     0  1   2   3   4   5  6    7   8  9  10
  Count:     0  1  1   1   1   1   1   1   1   1  1

3) Modify the count array such that each element at each index 
  stores the sum of previous counts. 


  Index:      0  1  2  3  4  5  6   7  8  9   10
  Count:     0  1  2  3  4  5   6  7  8  9   10

The modified count array indicates the position of each object in 
the output sequence.
 
4) Output each object from the input sequence followed by 
  decreasing its count by 1.


  Process the input data and Decrease count by 1 to place 
  next data 1 at an index 1 smaller than this index and so on.

 

 

Step 2

Step 2:-

Program Approach:-

1.Declare the array of data type integer and Initialize this array

2.Declare the user-defined function whose name is void countSort(int array[], int size) and void printArray(int array[], int size) . The data type of both the function is void and take two parameters first is an array and second is the size of the array.

A user-defined function is defined as a set of statements that can perform a specific task.

The array is defined as a collection of similar type of data.

For Example:-int A[2]

A is the name of the array and its data type is an integer.

The first element of the array is A[0] and the second element is A[1]

 

 

 

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY