Thursday, September 16, 2010

Finding K in a sea of N's

Don't really know how I would write this in code so I'll do it in plain english and mix in some C++ if I can.

My algorithm for finding 'k' in a list of numbers (a1,a2,....an) is as follows:

First define 'k' as whichever number you want to find. Say you want to see if 23 is in the list just do : int k = 23;
Then let 'i' equal your current number and go through the list using n (i+1).

Next the program compares 'i' to 'k' in an if/else statement.

if (i == k) {

      cout << "YES!";
}

else if ( i != k) {
      move to the next number
}

This algorithm could just run in a loop until it goes though all the numbers or finds a match to 'k'.
If it goes through the whole list and never finds a match then: cout << "NO!";

This algorithm is finite because it either finds 'k' or doesn't and has a statement to print to the screen in either situation.  It is also correct because the relational operators ( == ) and ( != ) confirm if any values are equal to or not equal to 'k'.

Wednesday, September 8, 2010

Algorithm

I think to best way to solve this problem is basically the reverse of what we did in class.  The algorithm would look at the first two numbers, and if the one of the right was greater than the one on the left, then it would switch them, but if the one of the right was less, it would move on to the next two numbers.  This would be a very efficient way to solving this problem.

Wednesday, September 1, 2010

Transitioning

     So for me, the transition from high school to college was super easy.  High school got me prepared to wake up nice and early which is a huge help for Air Force ROTC.  That is probably the hardest part of college I've had to deal with, waking up at 5:30, then going to do back-breaking physical training for the Air Force.
     I wasn't nervous at all coming to college which surprised me.  I just kind of came and did everything I had to without any resistance or second-thoughts.  I did everything myself without parents, like orientation (for both ASU and ROTC), and move-in.  It made me feel like I had really moved out and was finally in the real world and on my own.  But yeah, the transition was pretty much seamless.