CSC 335 Assignments

Assignment16

Due: 4/20, Monday.

1.    What is the primary difference between the B+ tree and the B–tree?

2.    Given a list: 3, 1, 2.5, 3.7, 1.4, 4.5, 3.1, 5.6, 2, 4.2, 7, 3.3, 4, 5.2, 8, 7.4, 4.3, please build a B–tree based on this list.

Bonus Project - Hangman

Due: 4/29, Wednesday

Optional project files: word list (TXT) contains many words; hangman_lib.py (PY) contains helper functions to get a random word and to print a Hangman image; hangman.py (PY) contains example usage of hangman_lib.

Example solution: hangman_soln.py (PY) (needs to be in same directory as above files)

Create a new file hangman.py. We're going to start by storing the state of the game in variables at the top of the program. The state is a complete description of all the information about the game. The state would be:

-The current player

-How many stones are in the pile

For Hangman, we need to store 3 pieces of information:

secret_word: The word they are trying to guess (string).

letters_guessed: The letters that they have guessed so far (list).

mistakes_made: The number of incorrect guesses they've made so far (int).

You can name these something else if you'd like, but use a descriptive name.

For now, set secret_word to be "claptrap." Once we've finished our program and got it working, then we'll add a prompt at the beginning of the program to let a friend of the user choose the word. (This is called incremental programming – instead of trying to get everything right the first time, we'll get the basic program working then incrementally add small portions of code.) "claptrap" was selected because it's reasonably long and has duplicate letters --hopefully that will allow us to catch any bugs we might make.

Assignment15

Due: 4/6, Monday.

Assume a file include letters: a b c d e only, and the probability for them are 0.6, 0.2, 0.15, 0.03, 0.02. 

1). Design Huffman code for above letters.

2). Represent the string ´ababcaed´ with designed Huffman code.

3). Figure out the original string for ´01101111010´.

Assignment14

Due: 4/3, Friday.

Do some research online, describe the principle of Huffman coding.

Assignment13

Due: 3/30, Monday.

Use suppressing repeating sequences to compress the following hexadecimal sequence (assume oxff as run-length code indicator)

1). 00 00 00 05 26 35 35 35 35 35 35 06 07 1C

2). 05 05 05 05 05 05 05 05 05 05 05 05 06 0B 10 06 06 06 07

Assignment12

Due: 3/27, Friday.

1. List the methods for data compression.

2. By using different notation to compress data, we represent week days as 3 bits in binary as in the following table. Then what’s the sequence of “001110111010011101” representing? Hint: Check your class notes for 3/25.

Assignment11

Due: 3/23, Monday.

1. List the methods for organizing field with in records of a file.

2. List the methods for organizing records in a file

Hint: Check your class notes for 3/16.

Bonus Assignment

Due: 3/20, Friday. (need 2 class hours.)

Assume you have a text file containing the following alphanumerals.

aaaaaa22bbbbbbbb55

hhhhhh11dpdpdpdp22

kkkkkkk21lokolkolko33

.....

You need to read the contents as single line, one after the other

and append the sum of digits at the end.

aaaaaa22bbbbbbbb5577

hhhhhh11dpdpdpdp2233

kkkkkkk21lokolkolko3354

....

What would be a simple way to achieve this ?

Hint:

1. Suppose f is the open file. To read it a line at a time:

    for line in f:

    do_something_with(line)

2. To search for a number, try the re module:

    http://docs.python.org/library/re.html

3. To do some calculation with those numbers, remember to convert them to integers first:

    x="12"

    y="34"

    x+y gives "1234"

    int(x)+int(y) gives 46

Assignment10

Due: 2/23, Monday.

Read the content of list, write a python program a10.py:

1. Open the file a10.txt

2. Read the content to a list.

3. Print the content to be:

'Alex'          'Bob'                 

04/25/82     03/17/83

Email Dr. Jiang your a10.py.

Assignment9

Due: 2/20, Friday.

Read the content of list

1. Use list to define the following matrix:

2. Describe how to present element 'Bob'.

Email Dr. Jiang your solution.

Assignment8

Due: 2/16, Monday.

Read the content about list and use list to define the following matrix:

Email Dr. Jiang your solution.

Assignment7

Due: 2/13, Friday, in class.

Type the following commands in python and find out the outputs.

1) type(True)

2) type("Hello, this is new file.")

3) type(98037843907273829071840782197)

4) type(9)

5) type(9.0)

Email Dr. Jiang your solution.

Assignment6

Due: 2/6, Friday, in class.

Check the link for a reference, write a python program a6.py:

1) Create a new file named 'abc';

2) Write string "Hello, this is new file." to the file;

3) Close the file.

4) Reopen the file and insert the string "This is written later. " at the beginning of the file.

5) Close the file;

Email Dr. Jiang your a6.py.

Assignment5

Due: 1/30, Friday, in class.

Check the link for a reference, write a python program a5.py:

1) Create a new file named 'abc';

2) Write string "Hello, this is new file." to the file;

3) Change the file object’s position to the beginning of the file;

4) Write string "This is written later. "

5) Close the file;

6) Reopen the file with module read-only;

7) Read the file and print it to the screen.

Email Dr. Jiang your a5.py.

Assignment4

Due: 1/26, Monday, in class.

Check the link about how to read and write files in Python, summarize:

1) How to open a file?

2) How to read / write?

3) How to seek?

4) How to close a file?

Assignment3

Due: 1/23, Friday, in class.

Write a python program named abc.py which prints odd numbers from 1 to 99 (1 3 5 7 ... 97 99). Email Dr. Jiang the file abc.py (as an attachment).

Assignment2

Due: 1/16, Friday, in class.

1. Install python in Windows and/or Linux. Describe your install experience.

2. Find a program in python, and test your python compiler.  Write down the version of python and operation system, and describe the steps to create and compile a program in python.

Assignment1

Due: 1/14, Wednesday, in class.

Do research on Python and answer the following questions:

        1) What is Python? What is it used for?

        2) How to install Python in a computer system?

        3) List related references (where are your answers from?).