<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Intelligence is a sword... &#187; ALPHA</title>
	<atom:link href="http://www.nick-cash.com/category/alpha/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nick-cash.com</link>
	<description>You will beat those who wield sticks.</description>
	<lastBuildDate>Sat, 24 Jul 2010 02:54:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Quicksort w/ Stacks</title>
		<link>http://www.nick-cash.com/2007/03/01/quicksort-w-stacks/</link>
		<comments>http://www.nick-cash.com/2007/03/01/quicksort-w-stacks/#comments</comments>
		<pubDate>Fri, 02 Mar 2007 01:57:07 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[ALPHA]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Computer Science III]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.nick-cash.com/wp/2007/03/01/quicksort-w-stacks/</guid>
		<description><![CDATA[I finally got around to working on this project/assignment. It was a very interesting way to implement quicksort, though I&#8217;m inclined to think it isn&#8217;t the fastest in many cases. The code picks the first element as the partition point (which works decently for random numbers), but sometimes it is a very poor choice (for [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got around to working on this project/assignment. It was a very interesting way to implement quicksort, though I&#8217;m inclined to think it isn&#8217;t the fastest in many cases. The code picks the first element as the partition point (which works decently for random numbers), but sometimes it is a very poor choice (for example, if the list is nearly sorted already).</p>
<p>The code: <a href="http://www.nick-cash.com/download/cs3/2">http://www.nick-cash.com/download/cs3/2</a></p>
<p>&#8212;-</p>
<p>Here is the algorithm I followed (from Data Structure Techniques by Thomas A. Standish using C++ operators):</p>
<p>Quicksort sorts a sequence of n numbers in Table T into ascending order. The numbers in T are referred to as T[1], T[2], &#8230;, T[n]. The algorithm uses an auxiliary stack S, which is initialized to the empty stack. Algorithm 2.2 is used as a subroutine to partition subsequences of the numbers in T into suitable subproblems. We assume n is at least 2.</p>
<p>1. [Initialize] Set L = 1, R = n, and S = NULL. (L is the leftmost index of the interval (L, R) in Table T, and r is the rightmost index.)</p>
<p>2. [Partition interval.] Call Algorithm 2.2 with input (L, R) to partition interval (L,R) of T into two intervals: an interval (L1,R1) of numbers < T[L] and an interval (L2,R2) of numbers > T[L].</p>
<p>3. [Postpone larger subproblem] If (R1 &#8211; L1) > (R2 &#8211; L2), then perform S < = (L1, R1) (that is, push the interval onto the stack), set L = L2, set R = R2 and go to step 4. Otherwise, perform S <= (L2,R2), set L = L1, set R = R1 and go to step 4. (This puts the larger intervals on the stack to be done later and goes to step 4 to sort the smaller ones).</p>
<p>4. [Interval nontrivial?] If R > L then go to step 2. (Otherwise, R < = L so the interval (L,R) contains at most one number and need not be sorted. Thus, the stack can next be examined at step 5 to see if there are any more postponed subproblems to consider.)</p>
<p>5. [Done?] If S == NULL, the algorithm terminates. Otherwise, perform (L,R) <= S (that is, pop the top interval from the stack) and go back to step 4.</p>
<p>-- Algorithm 2.2 --<br />
Using repeated exchanges, this algorithm partitions the distinct numbers in positions T[L], T[L+1], ..., T[R] into two subintervals: the interval (L1, R1) containing numbers less than T[L] and the interval (L2, R2) containing numbers greater than T[L]. The output consists of the ordered pairs of indices (L1, L2) and (L2, R2) for these two intervals. At termination, the numbers originally in T[L] lies between and separates the two subintervals. It is assumed initially that L < R.</p>
<p>1. [Initialize] Set i = L and set j = R.<br />
2. [Decrease j] If T[j] > T[i], set j = j-1 and repeat this step. (This step finds the greatest j such that T[j] < = T[i].)<br />
3. [Exchange or done?] If j > i, then T[i] < -> T[j] (that is, exchange T[i] and T[j]) and go to step 4. Otherwise, set (L1, R1) to (L, i-1), set (L2,R2) to (i+1, R), and terminate the algorithm.<br />
4. [Increase i] If T[i] < T[j], set i = i -1 and repeat this step. (this step finds the least i such that T[i] >= T[j].)<br />
5. [Exchange or done?] If j > i, then T[i] < -> T[j] (that is, exchange T[i] and T[j]) and go to step 2. Otherwise, set (L1, R1) to (L, j-1), set (L2,R2) to (j+1, R), and terminate the algorithm.</p>
<p>&#8212;&#8211;</p>
<p>The code works really well for smaller vectors. It easily sorts 10k random integers on my crappy machine in less then one second.  This code also had a few quirks to it that I didn&#8217;t see initially. If you tried to sort sufficiently large vectors it would segfault and using GDB I was able to find that j and i would be corrupted in Partition. To fix this I added and statements so that j and i had to be in a realistic range (that is, j could be no less then L and i could be no greater then R).</p>
<p>Also, as the book says, if you have a nondistinct list of integers (that is, a list that contains two or more of the same number) then it would not work. It would find its way into a constant swapping of data. To fix this I changed the loops so that it would be >= for decrementing j and < = for incrementing i. Along with this I changed the swaps to be ( j > i &#038;&#038; (v[j] != v[i])). Thus, if the numbers were equal it would not swap. These changes appear to allow the list to sort a nondistinct list correctly.</p>
<p>Lastly, I figured out the program was taking a crazy long time. It would take me 35 seconds to sort 10k elements. I added a statement to see how fast I was generating random numbers and I was surprised when it came back and showed me 35 seconds of the run time was generating random numbers. I examined my code to see how I could speed it up and I realized I had been adding elements to the <em>front</em> of a vector. This, of course, is a terrible method of doing things since it has to shift up all of the elements constantly. After I changed it to add to the end the time went drastically down, being able to generate 3 million random integers in 2 seconds.</p>
<p>All in all this code works really well and is quite fast. I would love to throw it up on Sidhe and see how fast it sorts compared to my previous qsorts, which could sort 5 million random integers in 14 seconds on Sidhe. On my home machine I ran a sort of 3 million integers (that took 2 seconds to generate) and it sorted in 2061 seconds (34.35 minutes). I ran it a second time and it sorted in 2283 seconds (38.05 minutes). I&#8217;m not sure what it chose for an index on either run, but those are not very good sort times in my opinion. I plan to test it using 499 as the partition point and then see how fast it runs. Of course my machine is several years old, so 34 minutes might not be a bad time. <img src='http://www.nick-cash.com/wordpress/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>Note: The code has two special test cases. If you enter 9 you will get the books sorting example. I did this for bug testing (using the comprehensive output) so I could see step by step what the program was doing. If you enter 11 it gives you the book example (of 9 numbers) and two of the same number at different points in the vector. This was used to test the code against nondistinct number lists.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nick-cash.com/2007/03/01/quicksort-w-stacks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Computer Science At Last, ISR Homework</title>
		<link>http://www.nick-cash.com/2007/02/17/computer-science-at-last-isr-homework/</link>
		<comments>http://www.nick-cash.com/2007/02/17/computer-science-at-last-isr-homework/#comments</comments>
		<pubDate>Sat, 17 Feb 2007 22:41:20 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[ALPHA]]></category>
		<category><![CDATA[College]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[School]]></category>

		<guid isPermaLink="false">http://www.nick-cash.com/wp/2007/02/17/computer-science-at-last-isr-homework/</guid>
		<description><![CDATA[At long last I have an update! A real update. I have been delving ever so slightly into the realm of Information Storage and Retrieval. This wasn&#8217;t my first time writing code to build a dictionary of terms, but other lessons have been interesting. Generating effective stop lists and weighting terms are all very practical [...]]]></description>
			<content:encoded><![CDATA[<p>At long last I have an update! A real update. I have been delving ever so slightly into the realm of Information Storage and Retrieval. This wasn&#8217;t my first time writing code to build a dictionary of terms, but other lessons have been interesting. Generating effective stop lists and weighting terms are all very practical techniques. And our <a href="http://cs.uni.edu/~okane/source/ISR/isr.html">textbook</a> is free!</p>
<p>&#8211;</p>
<p>Assignment 1:</p>
<p>Read the computing abstracts file and generate a dictionary of terms. Convert terms to lower case remove extraneous endings and special characters. Sort the dictionary by frequency and turn in, along with the program, the first page of the sorted results. </p>
<p>The code, library, and related files:<br />
<a href="http://www.nick-cash.com/download/isr/1/">http://www.nick-cash.com/download/isr/1/</a></p>
<p>Notes:<br />
I spent more time on this then it required simply to get a workable namespace going. All classes and related functions will go into the ISR library for use in later homework, and, at the end, I&#8217;ll have a workable Info Storage and Retrieval library with tested code.</p>
<p>&#8212;<br />
Assignment 2:</p>
<p>Using the dictionary from the above, select high frequency and low frequency words and from these build a file that will be a stop list. Write a program that will process the abstracts (title and abstract). Your program will read each word in each title/abstract text and ignore words that are in the stop list. It will build a new dictionary vector giving the total number of times each word occurs and a document frequency vector giving the number of documents in which each term occurs. It will then calculate, for each word, the Inverse Document Frequency weight of the word. Hint: for each document, build the dictionary directly and generate a document-term matrix. Then after all documents have been processed, create the document-frequency vector by going through the document vectors and incrementing the D-F vector for each word found</p>
<p>The code, library, and related files:<br />
<a href="http://www.nick-cash.com/download/isr/2/">http://www.nick-cash.com/download/isr/2/</a></p>
<p>Notes:<br />
This assignment looked daunting, but when I got started it was actually relatively easy. It was just a lot of work. I hit a few spots that proved troublesome, mainly due to the reading of the file (I should have written my own reading routine that processed each character instead of extracting from std::cin) and my being tired. Overall I&#8217;m fairly proud of this code as I didn&#8217;t know how to do any of it when I started. However, as with most code I look back on, I see things I definitely could improve. This code isn&#8217;t particularly efficient in my opinion, but overall it still runs fairly fast.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nick-cash.com/2007/02/17/computer-science-at-last-isr-homework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ALPHA &#8211; An Update At Last</title>
		<link>http://www.nick-cash.com/2006/09/27/alpha-an-update-at-last/</link>
		<comments>http://www.nick-cash.com/2006/09/27/alpha-an-update-at-last/#comments</comments>
		<pubDate>Wed, 27 Sep 2006 16:49:25 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[ALPHA]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.nick-cash.com/wp/2006/09/27/alpha-an-update-at-last/</guid>
		<description><![CDATA[Time: 1 hour Total: 2 hours &#8212;&#8212;&#8212;&#8212;&#8212; So, I realize I&#8217;ve been very relaxed about updating my ALPHA project. This is soon to change, as ALPHA is as much a class as anything else. I&#8217;ll work harder on updating it. That said, I have quite a few assignments from CS III that I will post [...]]]></description>
			<content:encoded><![CDATA[<p>Time: 1 hour<br />
Total: 2 hours<br />
&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>So, I realize I&#8217;ve been very relaxed about updating my ALPHA project. This is soon to change, as ALPHA is as much a class as anything else. I&#8217;ll work harder on updating it.</p>
<p>That said, I have quite a few assignments from CS III that I will post later tonight when I am at home. The teacher has seriously been pulling at some painful nerves for many people, but I must say I&#8217;ve learned a lot of Ada syntax and methodology quite quickly. The techniques are really nothing new (I&#8217;ll be excited if we do talk about newer stuff, I like learning new programming techniques), but we are incrementally learning how to use Ada.</p>
<p>Ada itself is a very lengthy programming language. Printing out text to the screen is no short function call (Ada -> Ada.Text_IO.Put_Line(&#8220;Look, text!&#8221;);     C++ -> cout < < "Look, text!\n";     C -> printf( &#8220;Look, text!\n&#8221;); ) and is generally harder to type because of the capital letters and underscores. However, its strong typing and extreme flexibility (and lack of pointers to keep track of) is pretty nice. Arrays in Ada allow you to specify the index! This is amazing since in C/C++ all index&#8217;s start at 0, and they must be numbers. It is nice in Ada to be able to use any discrete data type for an index.</p>
<p>I still have a feeling I can emulate some of the strong data type features of Ada in C++ using classes and data types. It may not be as pretty, but it will be good none the less. Many errors occur from range checking on integers, so that will be one focal point. The goal here is to have C++ programmers program, but not use -any- built-in data types. Integers, Characters, Floats, Doubles, Shorts, Longs will all be recreated classes. I expect this will slow down just about all programs using it, but I doubt the actual speed loss will be signifcant nor noticable.</p>
<p>There is much planning to do yet. I also need to find a large block of free time to commit to this cause. Supposing this turns out well, I will use it to finally work on Kaladea, which will be a rather large scale test of it. Then again, Kaladea is a long project. Speaking of which, it is techinically part of this project I have some design specs I still need to work out. I&#8217;m also working on updating the KaladeaMUD web site, which will contain most KaladeaMUD developments. Which also reminds me I need to work on a MySQL inteface in C++ for KaladeaMUD. Chances are I need to look into getting Ruby to work with KaladeaMUD as well, or at least design an interface to call the script interpreters.</p>
<p>Since KaladeaMUD will be query for -ALL- information now (very little should be kept in memory) it allows me to leave out interaction between the server and the scripts (apart from calling the scripts) and the sharing of memory. This was a huge problem before (it is incredibly hard to share data between programs), but now it should all be peachy if implemented correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nick-cash.com/2006/09/27/alpha-an-update-at-last/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ALPHA &#8211; Fall &#8217;06 Project</title>
		<link>http://www.nick-cash.com/2006/09/09/alpha-fall-06-project/</link>
		<comments>http://www.nick-cash.com/2006/09/09/alpha-fall-06-project/#comments</comments>
		<pubDate>Sun, 10 Sep 2006 04:42:57 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[ALPHA]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.nick-cash.com/wp/2006/09/09/alpha-fall-06-project/</guid>
		<description><![CDATA[It has been very difficult to determine what I wanted to do this year. I&#8217;ve neglected my computer so much recently I&#8217;m sure it should be something computer related. On that note, two things come to mind. One, my long running interest (and chance to become even minorly famous among computer sciene nerds) , would [...]]]></description>
			<content:encoded><![CDATA[<p>It has been very difficult to determine what I wanted to do this year. I&#8217;ve neglected my computer so much recently I&#8217;m sure it should be something computer related.</p>
<p>On that note, two things come to mind. One, my long running interest (and chance to become even minorly famous among computer sciene nerds) , would be to attempt to speed up or break A*. This would be difficult, but I believe it can be done. Alternatively, I wanted to save such a thing for my undergraduate thesis.</p>
<p>Second, create a basic typing library for C++ to emulate strong typing conventions and subtypes like those used in Ada. This would certainly be helpful, and with a little work and dynamic approach could even become popular. 88% of programming errors come from integers with large domains that end up with unexpected values according to McCormick. Thus, it would be nice to find a way to limit this.</p>
<p>Using  templates, STL, classes and inheritance I think I could create a good library to accomplish the said goals in C++. This would make for less errors and more compiler help (rather than runtime errors). Yay.</p>
<p>The only other option would be to create a very lightweight MySQL library in Ruby for use with Kaladea. And, for that matter, I should finish answerings Gammon&#8217;s questions on Kaladea, and finish reading the material posted in the BabbleMUD wiki. ::sigh:: So much to do, so little time. Further that note, I need to finish reading the script for the play and finding the sounds, and the robotics team starts up this tuesday.</p>
<p>There&#8217;s a thought. Maybe the robots programming can be my project? Chances are it will be like last year: a broad collection of programs of varying degrees of difficulty with the only point being to try new things.</p>
<p>We shall see.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nick-cash.com/2006/09/09/alpha-fall-06-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Computer Science III &#8211; Post Lab #0</title>
		<link>http://www.nick-cash.com/2006/08/22/computer-science-iii-post-lab-0/</link>
		<comments>http://www.nick-cash.com/2006/08/22/computer-science-iii-post-lab-0/#comments</comments>
		<pubDate>Tue, 22 Aug 2006 19:52:39 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[ALPHA]]></category>
		<category><![CDATA[College]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[School]]></category>

		<guid isPermaLink="false">http://www.nick-cash.com/wp/2006/08/22/computer-science-iii-post-lab-0/</guid>
		<description><![CDATA[Time: 1 hour Total: 1 hour &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- I already have homework. ::sigh:: Actually, I&#8217;m posting because I completed one of the tasks. It was an intersting refresher as I haven&#8217;t done much practical programming this crazy summer. The first assignment was very much like the word counter we wrote back in CS I or CS [...]]]></description>
			<content:encoded><![CDATA[<p>Time: 1 hour<br />
Total: 1 hour<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>I already have homework. ::sigh:: Actually, I&#8217;m posting because I completed one of the tasks. It was an intersting refresher as I haven&#8217;t done much practical programming this crazy summer.</p>
<p>The first assignment was very much like the <a href="http://www.nick-cash.com/wp/2006/01/22/avl-balanced-trees-part-2/">word counter</a> we wrote back in CS I or CS II. We had to count the number of occurances of each printable character in a text file with a few other specifications relating to errors, output, etc.</p>
<p>Overall it was a decent way to spend an hour. I enjoy playing with STL maps, and they made this much easier than it would have been otherwise. McCormick seems to want comments on just about everything, so I think half of the code is either white space or comments.</p>
<p>I must admit I am a little wary posting this here. I don&#8217;t think any of the CS majors at UNI read  my blog, but I don&#8217;t want to ruin their homework. Either way, if they copied it then they would all take some heavy hits on their grades.</p>
<p>Code -> <a href="http://www.nick-cash.com/download/cs3/postlab0/">http://www.nick-cash.com/download/cs3/postlab0/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nick-cash.com/2006/08/22/computer-science-iii-post-lab-0/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
