Wednesday, October 20, 2010

How To Lose Friends and Influence

Cheating! Its the simplest way to screw yourself over in college!

Cheating is knowingly copying, collaborating on, or stealing materials or work. It may not seem like that big of a deal, but if you and John Doe are caught working together on a non-group project, serious penalties can be levied against you!

For example, you could earn an XE in whatever course you cheated in. An XE is not only a failure in the class, it also indicates Academic Dishonesty. This indication will remain on your record. Permanently.

That is, if that's your first time cheating. Cheat too much, and you'll get kicked out of your major's school. Or ASU. It depends on how egregious your transgression is.

Assuming you don't get kicked out, you'll be put on the AIP watch list that every professor whose course you sign up for will see. Doesn't make for a good first impression...

This AIP list is kept tucked away in an office for 6 years, or until you graduate.

So remember kiddies, if you want to graduate college, and do so in a reputable manner, DON'T CHEAT!

Monday, September 27, 2010

Is Sorted?

Given an array arr that consists of a series of elements, to determine whether the array is sorted the following algorithm can be used.

1. Begin iterating through the array from the first element to the second to last
2. Compare each element to the next one in the array based on whatever criteria you are using to determine order (i.e. greatest to least...)
3. As soon as you find a pair that is not in order (i.e. the greater value is on the left) return false
4. If you finish all the comparisons, your array is sorted.

Here's a sample program written in Python that determines if any list of numbers is sorted by ascending value:

for x in range(len(arr) - 1):
if arr.get(x+1) < arr.get(x):
return false
return true

Regardless of how the numbers are organized or arranged in the list, this algorithm will always be able to tell if the list is sorted, and at most this algorithm makes n-1 comparisons.

Saturday, September 18, 2010

U+0043 U+0051 - Search Algorithm

Given a list a, to determine if a contains element n:
1. Begin iterating through the list
2. Compare each element to n
3. If an element is equal to n, return true
4. If none of the elements in the list is equal to n, return false

Here is a simple example function written in Python

def hasN(n, a):
    for x in a:                    # for each element x in list a
        if x is n:                  # if the element is equal to n, return true
            return True
    return False                # since none of the elements returned true, n is not in list a

This algorithm will always determine if n is in list a since it checks every element in a to see if it is n. Since this algorithm at most makes one comparison per element, this algorithm is finite and will take O(n) time.

For those of you who were wondering what my title means, U+0043 U+0051 are unicode notations for C and Q

Tuesday, September 7, 2010

The Sorting Hat

Or, rather The Merge-Sorting Hat....

To tackle the sorting problem, I decided to write a simple merge-sort program. Basically, a merge-sort takes a list of elements, splits it in two, then recursively splits each of those lists into two, and so on until all that remains are a number of lists with only 2 elements in them. After sorting those lists, the sort then reverses its splitting process by merging lists together, to create the sorted whole.

/*
A Simple Merge Sort
Gabriel Kishi
9/7/2010
 */
import java.util.Random;

public class mergeSortingHat
{

    public static void main(String[] args)
    {
        // seeds the random number generator
        Random r = new Random(System.currentTimeMillis());

        // creates an array of 100 random numbers between 0 and 10000
        // Note: I tested this up to 10000 numbers between -2,147,483,648 to +2,147,483,647
        // which, while it computed rather quickly, crashed my IDE while it was printing!
        int[] a = new int[100];
        for (int x = 0; x < a.length; x++)
        {
         a[x] = r.nextInt(1000);
        }

        // prints the initial array
        for (int y: a)
        {
         System.out.print(y + " ");
        }
        System.out.println("\n");

//prints the sorted array
        for (int y: mergeSort(a))
        {
         System.out.print(y + " ");
        }

    }

    public static int[] mergeSort(int[] arr)
    {
     if (arr.length < 2)
     {
     // if array contains 1 or 0 elements, no need to sort it
     return arr;
     }

     if (arr.length == 2)
     {
     // sorts an array w/ 2 elements
     if (arr[0] > arr[1])
     {
     int temp = arr[0];
     arr[0] = arr[1];
     arr[1] = arr[0];
     return arr;

}
     }

//if array has more than two elements, splits the array into two parts
//and then calls mergeSort recursively to sort the arrays, and finally
//merges the two arrays
     int split = arr.length/2;
     int[] arr1 = new int[split];
     int[] arr2 = new int[arr.length-split];

     for (int x = 0; x < arr.length; x++)
     {
     if (x < split)
     arr1[x] = arr[x];
     else
     arr2[x-split] = arr[x];
     }

     return merge(mergeSort(arr1), mergeSort(arr2));
    }

    public static int[] merge (int[] arr1, int[] arr2)
    {
     //merges two arrays
     int len1 = 0;
     int len2 = 0;
     int[] newArr = new int[arr1.length + arr2.length];

     for (int x = 0; x < newArr.length; x++)
     {
     if (len1 == arr1.length && len2 < arr2.length)
     {
     newArr[x] = arr2[len2];
     len2++;
     }
     else if (len2 == arr2.length && len1 < arr1.length)
     {
     newArr[x] = arr1[len1];
     len1++;
     }
     else if (arr1[len1] < arr2[len2])
     {
     newArr[x] = arr1[len1];
     len1++;
     }
     else
     {
     newArr[x] = arr2[len2];
     len2++;
     }
     }
     return newArr;
    }
}

Wednesday, September 1, 2010

Bloggy Blogger Blog

My first post got eaten by the nether-worms, so I here's take two!

Hey everyone, I'm Gabe Kishi and I am a complete nerd. I'm a native Arizonan from Tucson, where I graduated from Canyon Del Oro High School. I'm glad to be up here at ASU, and look forward to becoming a Computer Scientist.

I've generally avoided things like Twitter or Facebook, but now I have a blog (queue dramatic music)! Maybe I need some mirrors to look at myself while I blog....

So transitioning from High School wasn't too bad. I wasn't really sure I could have prepared for the change. The best thing I did to ease the transition was to get to know people in my dorm. Open your dorm room doors and say hi to people, it really helps.

Classes have been a lot of fun, and the work isn't overwhelming (yet), and I'm really enjoying them so far.

So that's about it for this first post... maybe in the future I'll bore you all with my ramblings about nerdy things ...