Homework 1
Due Friday, April 21

Make sure to review the procedures for submitting homework. For example, remember that you must use Amaya to submit your mathematical work. And remember to show your work!

Problem I:

Suppose we have two network nodes, each connected to one transmission line. Time is divided into slots named slot 0, slot 1, slot 2, etc. Each node has one message to send, taking one time unit to transmit.

If both nodes attempt to transmit during the same time slot, they will "collide" and neither transmission will be successful. Assume there was a collision in slot 0.

In any given time slot (1, 2, 3, ...), each node which has not yet successfully transmitted either tries to send or not, with probability p and 1-p, respectively. The decision will be done via a random number generator in the NIC at each node. The purpose of the random send/refrain-from-send decision is to prevent perpetual collisions.

After a node has successfully transmitted, it no longer attempts transmission in future slots. Assume, though, that the remaining node does not know that the node has dropped out of contention, and will continue to generate random numbers at each time slot to decide whether to try sending or not, as before.

Let T denote the time slot in which the process completes, i.e. the final successful transmission occurs.

Find the following quantities as functions of p:

(a) P(T is between 2 and 4, inclusive).

(b) P(there is a collision in slot 2 | T = 5).

(c) E(number of transmissions attempted in slot 3).

These problems may seem rather daunting to you at first, but they are actually very easy. Just ask yourself, "How could it happen? Let's list the ways." For instance, what are all the possible scenarios under which T could be equal to 3?

Note: If you wish to check your answer, you may wish to modify my sample simulation program, which calculates some probabilities in our setting here. If you are new to simulation, you may wish to first look at another program which simulates a special case of Problem III.

Problem II:

Suppose in the setting of Problem I each node waits a random amount of time before starting its first transmission. Let T1 and T2 be the two times at which they start. Assume they are independent with density 2e-2t, t > 0. Find the following (your answer must be an exact expression):

(a) P(1 < T1 < 2.5).

(b) P(T1 < T2 - 1).


Problem III:

Suppose we have a coin with probability p of heads, and we keep tossing it until we accumulate k heads. Let X denote the number of tosses needed. Find P(X = r), r=k, k+1, k+2, ... as an expression of p, k and r.



Problem IV:

Here you will write a pair of programs to play "hangman,." the familiar word-guessing game. The client will contact the server. The server will then choose a word at random from a Unix dictionary, and send the client the number of letters. The client will then display that number of underlined blanks on the screen for the user to see. The user will guess a letter, which the client will then forward to the server. The server will then send information back to the client, stating which of the letters in the word, if any, match the letter guessed by the user. The client will display this to the user. This continues until either the user guesses the word, thus winning, or guesses wrong a certain number of times, thus losing.

Name the client hangman and the server hangmand.

The server will choose a word at random from the Unix spelling dictionary on the machine where the server is running. Write your server program so that it gets the dictionary file name from the command line. For example, on the Linux PCs in CSIF, where the dictionary is /usr/dict/words, to start up the server, say on pc12, we would type

pc12% hangmand /usr/dict/words &

Suppose for instance someone then plays the game from hp8. Here is a sample of what will occur:

hp8% hangman pc12
Welcome!  Here is your word:
_ _ _ _ _ _ _
What is your guess? t
Sorry, there is no t.
What is your guess? r
Yes, the word does include r:
_ r _ _ _ _ _
What is your guess? o
Sorry, there is no o.
What is your guess? n
Yes, the word does include n:
_ r _ n n _ n _
What is your guess? i
Yes, the word does include i:
_ r i n n i n _
What is your guess? g
You got it!
g r i n n i n g
But I'll stump you next time!
hp8%

You must use Internet sockets in this assignment. It is up to you whether you use TCP or UDP (since it is just a game, don't worry about errors if you use UDP), but make your choice wisely, in a way that will make it easier to program..

The dictionary file consists of plain text, one word per line. Have the server choose a word at random, by first generating a random number k between 0 and m-1, where m is the number of bytes in the file. Then keep reading words, starting from the beginning of the file (or where you last left off, if you wish) until you reach byte k of the file; then your word is whichever word contains that byte (or the next one, if this byte was an end-of-line character).

In order to determine the value of m, use the stat() system call if you are writing in C/C++ or in perl; if you are writing in Java, use File.length. You can get information on using stat() in C/C++ from my Unix Web page.

Do not use system().

You may assume reasonable limits on word size, number of guesses and so on.

Remember that the client and server programs must be general. You cannot hard-code an address in either one. For example, the client must get the address of the server from the command line, as with wps.

You must write your program to work across different platforms, for at least one cross-platform pair. For example, if you get the pair to work correctly when the client is on a PC and the server is on an HP, then you are finished and will get full credit. If you cannot find the dictionary file on a given platform, then just make your own or copy one from the PCs.