Question

In: Computer Science

The following submission rules apply: • For those questions requiring programs, the solutions must be implemented...

The following submission rules apply: • For those questions requiring programs, the solutions must be implemented using JavaScript or Java. o Appropriate self-documenting comments in the source code are mandatory, consistent with good programming practices. o Solutions must be provided in plain text so that formatting is not lost. • All answers must be provided in this document. • Sources must be given accurate and complete citations sufficient for the instructor to find and confirm them.

1 Determine and explain whether RadixSort is a stable sorting algorithm

Solutions

Expert Solution

public class PrimitiveTypesMinMax {
   public static void main(String[] args) {
      // int (32-bit signed integer)
      System.out.println("int(min) = " + Integer.MIN_VALUE);
      System.out.println("int(max) = " + Integer.MAX_VALUE);
      System.out.println("int(bit-length) = " + Integer.SIZE);
      // byte (8-bit signed integer)
      System.out.println("byte(min) = " + Byte.MIN_VALUE);
      System.out.println("byte(max) = " + Byte.MAX_VALUE);
      System.out.println("byte(bit-length)=" + Byte.SIZE); 
      // short (16-bit signed integer)
      System.out.println("short(min) = " + Short.MIN_VALUE);
      System.out.println("short(max) = " + Short.MAX_VALUE);
      System.out.println("short(bit-length) = " + Short.SIZE);
      // long (64-bit signed integer)
      System.out.println("long(min) = " + Long.MIN_VALUE); 
      System.out.println("long(max) = " + Long.MAX_VALUE);
      System.out.println("long(bit-length) = " + Long.SIZE);
      // char (16-bit character or 16-bit unsigned integer)
      System.out.println("char(min) = " + (int)Character.MIN_VALUE);
      System.out.println("char(max) = " + (int)Character.MAX_VALUE);
      System.out.println("char(bit-length) = " + Character.SIZE);
      // float (32-bit floating-point)
      System.out.println("float(min) = " + Float.MIN_VALUE);
      System.out.println("float(max) = " + Float.MAX_VALUE);
      System.out.println("float(bit-length) = " + Float.SIZE);
      // double (64-bit floating-point)
      System.out.println("double(min) = " + Double.MIN_VALUE);
      System.out.println("double(max) = " + Double.MAX_VALUE);
      System.out.println("double(bit-length) = " + Double.SIZE);
   }
}
radix sort(L):
    {
    bucket sort by a
    bucket sort by b
    bucket sort by c
    ...
    }

or more simply

    radix sort(L):
    {
    while (some key is nonzero)
    {
        bucket sort(keys mod 10)
        keys = keys / 10
    }
    }

The only possibly strange part: Why do we do the sort least important digit first? For that matter, why do we do more than one bucket sort, since the last one is the one that puts everything into place?

Answer: If we're trying to sort things by hand we tend to do something different: first do a bucket sort, then recursively sort the values sharing a common first digit. This works, but is less efficient since it splits the problem up into many subproblems. By contrast, radix sorting never splits up the list; it just applies bucket sorting several times to the same list.

In radix sorting, the last pass of bucket sorting is the one with the most effect on the overall order. So we want it to be the one using the most important digits. The previous bucket sorting passes are used only to take care of the case in which two items have the same key (mod 10) on the last pass.

Correctness:

We prove that the algorithm is correct by induction. The induction hypothesis is that after i steps, the numbers are sorted by key modulo 10^i. Certainly after no steps, all numbers are the same modulo 1, and are therefore sorted by that value, so the base case is true. Inductively, step i+1 sorts by key / 10^i. If two numbers have the same value of key/10^i, the stability property of bucket sorting leaves them sorted by lower order digits; and if they don't have the same value, the bucket sort on step i+1 puts them in the right order, so in either case the induction hypothesis holds. For i sufficiently large, taking the keys mod 10^i doesn't change them, at which point the list is sorted.

Analysis:

The algorithm takes O(n) time per bucket sort.
There are log_10 k = O(log n) bucket sorts.
So the total time is O(n log k).


Related Solutions

The following submission rules apply: ·    For those questions requiring programs, the solutions must be implemented...
The following submission rules apply: ·    For those questions requiring programs, the solutions must be implemented using JavaScript or Java. o Appropriate self-documenting comments in the source code are mandatory, consistent with good programming practices. o Solutions must be provided in plain text so that formatting is not lost. ·    All answers must be provided in this document. ·    Sources must be given accurate and complete citations sufficient for the instructor to find and confirm them. Does the Principle of...
The following submission rules apply: • For those questions requiring programs, the solutions must be implemented...
The following submission rules apply: • For those questions requiring programs, the solutions must be implemented using JavaScript or Java. o Appropriate self-documenting comments in the source code are mandatory, consistent with good programming practices. o Solutions must be provided in plain text so that formatting is not lost. • All answers must be provided in this document. • Sources must be given accurate and complete citations sufficient for the instructor to find and confirm them. 1. Demonstrate the action...
The following submission rules apply: ·    For those questions requiring programs, the solutions must be implemented...
The following submission rules apply: ·    For those questions requiring programs, the solutions must be implemented using JavaScript or Java. o Appropriate self-documenting comments in the source code are mandatory, consistent with good programming practices. o Solutions must be provided in plain text so that formatting is not lost. ·    All answers must be provided in this document. ·    Sources must be given accurate and complete citations sufficient for the instructor to find and confirm them. 1 Reformulate the Backtrack...
Questions This questions are multiple choice: The lower of cost or market rules apply when: The...
Questions This questions are multiple choice: The lower of cost or market rules apply when: The market value of the inventory is higher than the cost in the books The market value of the inventory is lower than the cost in the books The market value of the inventory is higher than the cost to the consumer The market value of the inventory is lower than the cost to the consumer Special Journals are used to: Increase efficiency Reduce costs...
You are the newly appointed HR Manager and must develop some programs, solutions, or interventions to...
You are the newly appointed HR Manager and must develop some programs, solutions, or interventions to address these issues. Ideally, there should be integration among the various problems. As such, you do not need to address EACH item, point-by-point. 1) The organization is in the decline stage of growth 2) Many of the top leaders on the verge of retirement (i.e., those in the highest leadership positions) 3) Many of the mid-level managers are aggressively pursuing other employment alternatives
    Please answer all questions in question 1 and question 2.     Your submission must include...
    Please answer all questions in question 1 and question 2.     Your submission must include a bibliography.     The word limit for question 1 and 2 combined is 1500 words. Question 1 Angus is a 44-year-old high school teacher who wishes to invest his savings of $100,000 by building up a blue-chip share portfolio. Angus was a keen observer of the Royal Commission into Misconduct in the Banking, Superannuation and Financial Services Industry in 2019 and has strong views...
Due Thursday  (Normal late penalties apply for late submission.) Respond to the following in a minimum of...
Due Thursday  (Normal late penalties apply for late submission.) Respond to the following in a minimum of 175 words (20 points): Today's datacenters are populated with not only physical hardware but systems hosting virtual machines and containers. These systems communicate locally and around the globe over networks. Discuss two different examples of threats to various parts of heterogeneous architectures and how they might manifest. Do not forget about the hardware, operating systems, applications, networks, and other integral parts. Discuss the threats...
Which of the following are characteristics of NeoclassicalEconomics? (Select all that apply)individuals use rules...
Which of the following are characteristics of Neoclassical Economics? (Select all that apply)individuals use rules of thumbindividuals act independently of one anotherreference points matterrational preferencesindividuals use mental accountingfirms maximize profits
Answer each of the following questions in your submission for this part of the project: List...
Answer each of the following questions in your submission for this part of the project: List your 4 variables from the Consensus at School (opens in a new window) and state whether they are qualitative or quantitative. Using your four variables, write your two questions you will analyze based on data from Census at School. What is your population? What type of sampling will you use to gather your data (stratified or simple random)? What is cluster sampling and why...
ALL COMPONENTS / QUESTIONS MUST BE FULLY ANSWERED -- DO NOT USE THE SIMILAR TEXTBOOK SOLUTIONS...
ALL COMPONENTS / QUESTIONS MUST BE FULLY ANSWERED -- DO NOT USE THE SIMILAR TEXTBOOK SOLUTIONS ALREADY IN PLACE IF YOU ARE UNABLE TO ANSWER ALL COMPONENTS, PLEASE DO NOT ANSWER. INCOME STATEMENTS SHOULD BE IN THE MOST BASIC FORM. OPENING AND CLOSING INVENTORY, ETC., ARE NOT TO BE INCLUDED.   Ciroc Company manufactures and sells one specific product. The following information pertains to each of Ciroc's first three years of operations: Variable costs per unit: Manufacturing: Direct materials . ....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT