<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.lensovet.net/~sysadmin/w/index.php?action=history&amp;feed=atom&amp;title=Computer_Science%2F61b%2FHomework%2Fhw10</id>
	<title>Computer Science/61b/Homework/hw10 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://www.lensovet.net/~sysadmin/w/index.php?action=history&amp;feed=atom&amp;title=Computer_Science%2F61b%2FHomework%2Fhw10"/>
	<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw10&amp;action=history"/>
	<updated>2026-05-04T12:11:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.16</generator>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw10&amp;diff=24293&amp;oldid=prev</id>
		<title>Lensovet: Lensovet moved page CS/61b/Homework/hw10 to Computer Science/61b/Homework/hw10</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw10&amp;diff=24293&amp;oldid=prev"/>
		<updated>2023-02-20T03:51:34Z</updated>

		<summary type="html">&lt;p&gt;Lensovet moved page &lt;a href=&quot;/~sysadmin/w/CS/61b/Homework/hw10&quot; class=&quot;mw-redirect&quot; title=&quot;CS/61b/Homework/hw10&quot;&gt;CS/61b/Homework/hw10&lt;/a&gt; to &lt;a href=&quot;/~sysadmin/w/Computer_Science/61b/Homework/hw10&quot; title=&quot;Computer Science/61b/Homework/hw10&quot;&gt;Computer Science/61b/Homework/hw10&lt;/a&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 03:51, 20 February 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Lensovet</name></author>
		
	</entry>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw10&amp;diff=3981&amp;oldid=prev</id>
		<title>Lensovet: moved CS 61b/Homework/hw10 to CS/61b/Homework/hw10:&amp;#32;fix cs 61b hierarchy</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw10&amp;diff=3981&amp;oldid=prev"/>
		<updated>2010-11-14T06:00:19Z</updated>

		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/~sysadmin/w/CS_61b/Homework/hw10&quot; class=&quot;mw-redirect&quot; title=&quot;CS 61b/Homework/hw10&quot;&gt;CS 61b/Homework/hw10&lt;/a&gt; to &lt;a href=&quot;/~sysadmin/w/CS/61b/Homework/hw10&quot; class=&quot;mw-redirect&quot; title=&quot;CS/61b/Homework/hw10&quot;&gt;CS/61b/Homework/hw10&lt;/a&gt;: fix cs 61b hierarchy&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 06:00, 14 November 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Lensovet</name></author>
		
	</entry>
	<entry>
		<id>http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw10&amp;diff=3247&amp;oldid=prev</id>
		<title>Lensovet at 06:50, 22 September 2007</title>
		<link rel="alternate" type="text/html" href="http://www.lensovet.net/~sysadmin/w/index.php?title=Computer_Science/61b/Homework/hw10&amp;diff=3247&amp;oldid=prev"/>
		<updated>2007-09-22T06:50:09Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Files==&lt;br /&gt;
*[[/sort]] package&lt;br /&gt;
&lt;br /&gt;
==Grade==&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
                              CS 61B Homework 10&lt;br /&gt;
                       Due 4pm Friday, December 8, 2006&lt;br /&gt;
&lt;br /&gt;
This homework will give you practice implementing linear-time sorting&lt;br /&gt;
algorithms.  This is an individual assignment; you may not share code with&lt;br /&gt;
other students.&lt;br /&gt;
&lt;br /&gt;
Copy the Homework 10 directory by doing the following, starting from your home&lt;br /&gt;
directory.  Don't forget the &amp;quot;-r&amp;quot; switch in the cp command.&lt;br /&gt;
&lt;br /&gt;
    cp -r $master/hw/hw10 .&lt;br /&gt;
&lt;br /&gt;
Your job is to implement counting sort and radix sort for arrays of ints.  All&lt;br /&gt;
your code should appear in the file [[/sort/Sorts.java]].  A skeleton is provided&lt;br /&gt;
for you.&lt;br /&gt;
&lt;br /&gt;
===Part I  (8 points)===&lt;br /&gt;
Implement counting sort on int arrays.&lt;br /&gt;
&lt;br /&gt;
  public static int[] countingSort(int[] keys, int whichDigit);&lt;br /&gt;
&lt;br /&gt;
The most important difference between the counting sort you will implement here&lt;br /&gt;
and the one presented in lecture is that this counting sort uses one base-16&lt;br /&gt;
digit in each int as its sort key, and ignores all the other digits.  That way,&lt;br /&gt;
your counting sort can be used as one pass of radix sort.  (Make sure that your&lt;br /&gt;
counting sort is stable!)&lt;br /&gt;
&lt;br /&gt;
The parameter &amp;quot;whichDigit&amp;quot; tells the method which base-16 digit of each int to&lt;br /&gt;
use as a sort key.  If whichDigit is zero, sort on the least significant (ones)&lt;br /&gt;
digit; if whichDigit is one, sort on the second least significant (sixteens)&lt;br /&gt;
digit; and so on.  An int is 32 bits long, so it has eight digits of four bits&lt;br /&gt;
each.&lt;br /&gt;
&lt;br /&gt;
The high bit of each int is a sign bit.  To keep life simple, we will assume&lt;br /&gt;
that all the numbers are positive, so the high bit is always zero.  Don't try&lt;br /&gt;
to create an int whose most significant base-16 digit is greater than 7.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Hexadecimal Primer:  Hexadecimal is a way of expressing a number in base-16.&lt;br /&gt;
We use the usual digits 0...9, plus the additional digits a...f to represent&lt;br /&gt;
ten through fifteen.  You can convert back and forth between an int and&lt;br /&gt;
a hexadecimal string by using the Integer.toString(int, int) and&lt;br /&gt;
Integer.parseInt(String, int) methods.  (Look them up in the online Java API,&lt;br /&gt;
and/or look at how they are used in Sorts.java.)&lt;br /&gt;
&lt;br /&gt;
One of the best reasons to use base-16 digits is because they can be extracted&lt;br /&gt;
very quickly from a key by using bit operations.  This means that, in your&lt;br /&gt;
countingSort method, you should use bit operations to extract the digits, and&lt;br /&gt;
not throw away the speed advantage by using something silly like toString() to&lt;br /&gt;
extract each digit.  The bit operation that will serve you best is Java's &amp;quot;&amp;amp;&amp;quot;&lt;br /&gt;
operator.  If you write &amp;quot;x &amp;amp; 15&amp;quot;, it masks the int x against the bit pattern&lt;br /&gt;
&amp;quot;0000...00001111&amp;quot;, so only the least significant base-16 digit survives, and&lt;br /&gt;
the others are set to zero.  This allows you to extract the least significant&lt;br /&gt;
digit.&lt;br /&gt;
&lt;br /&gt;
Want to extract a different digit?  Divide the int by some appropriate divisor&lt;br /&gt;
first.  Recall that integer division always rounds down, so you can eliminate&lt;br /&gt;
low-order digits this way if you choose the right divisor.  This moves the&lt;br /&gt;
digit you're looking for down to the least significant position, so you can&lt;br /&gt;
mask it against a 15.  (For faster performance, shift the bits to the right,&lt;br /&gt;
if you know how to do so.)&lt;br /&gt;
&lt;br /&gt;
Warning:  Do not confuse &amp;amp; with &amp;amp;&amp;amp;.  &amp;amp;&amp;amp; will not do bit masking.&lt;br /&gt;
&lt;br /&gt;
===Part II  (2 points)===&lt;br /&gt;
Implement radix sort on int arrays.  Your radix sort should use your counting&lt;br /&gt;
sort to do each pass.&lt;br /&gt;
&lt;br /&gt;
  public static int[] radixSort(int[] keys);&lt;br /&gt;
&lt;br /&gt;
A small test is provided in Sorts.main, which you can run by typing&lt;br /&gt;
&amp;quot;java sort.Sorts&amp;quot;.  We recommend you add more test code of your own.&lt;br /&gt;
Your main method and other test code will not be graded.&lt;/div&gt;</summary>
		<author><name>Lensovet</name></author>
		
	</entry>
</feed>