Thursday, February 24, 2011

Do you speak Tajik?

If so, please contact me. This is for Natural Language Processing (computer science) work.

Thanks,
Josh

Wednesday, February 23, 2011

lecture

HW 2
2.1: Open a ASCII text file, count the frequency of each symbol. Store those frequencies in an array freq. Print out that array.

a cab am i.

a, b = b, a

def foo():
return 1, 3

def main():
x, y = foo()

Wednesday, February 16, 2011

System.nanoTime()

Read all about it at StackOverflow. I suppose that, if it works with enough accuracy, we could use it to time even much fewer pushes.

Homework #1.4

Modify your code from 1.3 to make use of the Queue<T> interface.

Unfortunately, there does not seem to be a Stack<T> interface, just a Stack<T> class. They recommend using the Deque interface and calling the associated stack methods instead of this Stack class. However, I don't want you to have to implement every single method associated with a Deque interface. Instead, implement the superinterface to Deque, which is java.util.Queue<T>.

Certain inherited methods from the superinterface Collection it does not make sense to implement. For example, why get an iterator? The rules for a stack are such that we can only see the top element. The same for the contains method. Therefore, only focus on the ones that are directly mentioned in the documentation for Queue, except, mentally substitute stack for queue:


Method Summary
 booleanadd(E e)
          Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.
 Eelement()
          Retrieves, but does not remove, the head of this queue.
 booleanoffer(E e)
          Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
 Epeek()
          Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
 Epoll()
          Retrieves and removes the head of this queue, or returns null if this queue is empty.
 Eremove()
          Retrieves and removes the head of this queue.


In addition, the following from the superinterface Collection makes sense to implement:


Methods inherited from interface java.util.Collection
addAllclearequalsisEmptysizetoArraytoArray

Monday, February 14, 2011

A sample chart

based on one student's output. I used an X Y Scatter chart with smooth lines:

Another one, inserting even more data:

Sunday, February 13, 2011

Generics in Java

Here are a few good websites which discuss them, especially as they interact with interfaces:
  1. At Wikipedia
  2. At Oracle
  3. At Java2s
See also the comment thread on the previous post.

Wednesday, February 9, 2011

lecture #4

// array-based stack
class JArrayStack
{
int capacity = 100;
int a[] = new int [100];
int i = 0;

public void push(int x) { a[i++] = x; }
public void pop() { i++; }
public int top() { return a[i-1]; }
public boolean isFull() { return i == capacity; }
public boolean isEmpty() { return i == 0; }
public int size() { return i; }
}

int [] temp = new int [capacity * 2];
copy from a into temp using for loop or memcopy
a = temp
capacity *= 2

debugger
you shouldn't use venus if you have a bug in your program
printf debugging

*setting breakpoints
*stepping thru code
*using the watch window

hw 1.3:
Templatize it! Use generics.
also, modify your driver to insert varying sizes, 0, 100, 200, 300, 400, 500 all the way to 20000. Plot the results in Excel.
Tell me, is it O(1)? O(n)? O(n^2)?