יום שלישי, 25 בינואר 2011

Wednesday 26/01/11 Two-Dimensional Arrays

Yet again I got most of the multiple choices right, I understand the concepts of this unit. After looking back at my mistakes I understood what I did wrong besides a few which were syntactically confusing (I will try to bring these up in class). Finally, yes, I can pictures two dimensional arrays as arrays of arrays. Overall, I understand the material, there are no big problems/bumps which I have noticed so far.

יום ראשון, 16 בינואר 2011

Sunday 16/01/11 Sorting and Searching

This weeks multiple choice was an improvement of last week's. I got more than the majority of the questions right however I still seem to be struggling. Looking back I manage to figure out what I did wrong however I still have questions which I am hoping to get answered in class if we have time. I had a little difficulty understanding 2 or three specific lines of coding from this segment of multiple choice questions I am hoping to clear in class, but overall I believe I am starting to get the concept of sorting and searching; not as well as I did recursion, but slower. In terms of implementing sorting and searching in the activity we had I had a lot of difficulty, I understand what I'm supposed to do and know how to put it in words but I get stuck when trying to code it.

יום חמישי, 13 בינואר 2011

13/01/11 Linear Data Structures


 import java.util.ArrayList;
 import java.util.Random;
/**
* Class for demonstrating basic array processing
*
* @author (your name)
* @version (a version number or a date)
*/
public class ArrayDemo
{
int [] myArray;

ArrayDemo (int length)
{
    myArray = new int [length];
}

/**
* postcondition: myArray is filled with random int values from 0 to (limit-1)
*/

public void fillRandom(int limit)
{
    if (limit<=9 && limit>=0) {
    Random generator = new Random(limit);
    for(int i = 0; i<myArray.length; i++)
    {
        myArray[i] = generator.nextInt();
    }}
}


/**
* postcondition: writes the array to console
*/

public void writeArray()
{
    for(int i = 0; i<myArray.length; i++)
    {
        System.out.println(myArray[i]);
    }
}



/**
* postcondition: values in MyArray first and second have been swapped

* first < myArray.length, second < myArray.length

*/

public void swap (int first, int second)
{
      int hold = myArray[first];
      myArray[first] = myArray[second];
      myArray[second] = hold;
}

/**
* sorts myArray in ascending order using insertion sort algorithm
*/

public void insertionSort()
{
      int[] newArray = new int [myArray.length];
      for(int i = 0; i<myArray.length; i++)
      {
          for(int x = 0; x<myArray.length-1; x++)
          {
              if(myArray[x] > myArray[x+1])
                    swap(x, x+1);
            }
          newArray[myArray.length-1-i] = myArray[myArray.length-1-i];
        }
      myArray = newArray;
}

/**
* sorts myArray in ascending order using selection sort algorithm
*/

public void selectionSort()
{
     int large = myArray[0];
     int place = 0;
     for(int i = 0; i<myArray.length-1; i++)
     {
         for(int z = i+1; z<myArray.length; z++)
         {
             if(myArray[z] > large) {
                 large = myArray[z];
                 place = z; }
            }
         swap(i, place);
         large = myArray[i+1];
         place = 0;
        }
}


/**
* postcondition: returns the index of the first occurence of target
* returns -1 if target not found
*/

public int sequentialSearch (int target)
{
     for(int i = 0; i<myArray.length; i++)
     {
         if(myArray[i] == target)
             return i;
        }
     return 0;
}

/**
* postcondition: returns true if target found
*
*/

public boolean binarySearch (int target)
{
    int more = myArray.length-1;
    int less = 0;
    int mid;
  
    while(less <= more) {
    mid = (more + less)/2;
    if(myArray[mid]>target)
        less = mid+1;
    if(myArray[mid]<target)
        more = mid-1;
    else return true; }
    return false;
}
}

יום ראשון, 9 בינואר 2011

Sunday 09/01/11 Recursions

I felt like the multiple choice was challenging, I got a little over the majority of the questions right. I know how to approach the easy questions and don't have a problem with them it's the ones with more than 1 call in them that confuse me. Going back after checking I managed to correct a few of my errors and believe it's something that I will just become better at over time.

I have done 10 CodingBat Recursion-1 Problems so far and am having a hard time with 2 other ones. The exercises have helped me understand recursion but I still learn much more in class.

The biggest thing I am having trouble with is trying to follow a recursive method that calls on itself twice at once, it confuses me and I have a hard time following it.