CS 501  Foundations of Computer Science
Spring2010
Classes: MW 6:45 pm  8:00 pm, Maria Sanford Hall 310
Instructor: Dr. Zdravko Markov, 30307 Maria Sanford Hall, (860)8322711,
http://www.cs.ccsu.edu/~markov/,
email: markovz at ccsu dot edu
Office hours: MW 10:00am  12:30pm, or by appointment
Catalog description: Software design for structuring and manipulating
data. Topics include stacks, queues, hash tables, trees, graphs, advanced
sorting, and analysis of algorithms.
Prerequisites: CS 500 or CS 153 or permission of instructor
Course objectives: Upon successful completion of the course the
student will be able to:

Demonstrate the ability to plan, design, execute and document sophisticated
programs and to handle various sorts of data structures.

Understand the benefits of information hiding, modularity and abstraction
in the design of large software systems.

Consider alternative implementations using differing data structures and
understand the significance of choosing a particular data structure in
a realworld setting.

Analyze algorithms, transform and optimize programs to achieve better efficiency.
Required textbook: Robert LaFore, Data Structures and Algorithms
in Java, 2nd Edition, Sams Publishing, 2002, ISBN:0672324539.
Required software: BlueJ  an integrated Java programming environment
(http://www.bluej.org/).
Class Participation: Regular attendance and active class participation
is expected from all students. If you must miss a test, try to inform the
instructor of this in advance.
Assignments and tests: Reading and problem assignments are listed
under the schedule of classes. Some of the problems will be worked in class.
There will be 2 tests and a final exam. They will include
material from the textbook, the lectures, and the programming projects.
Programming projects: There will be 6 projects requiring
the use of BlueJ to write and run Java programs. The projects with their
due dates are listed below (the project descriptions are given on separate
pages). All projects must be submitted through the Blackboard Vista course
management system available through CentralPipeline
(Student > Blackboard Vista Courses > CS 501) or directly at https://vista.csus.ct.edu/webct/logon/1731901082031
Honesty policy: The CCSU honor code for Academic Integrity is
in effect in this class. It is expected that all students will conduct
themselves in an honest manner and NEVER claim work which is not their
own. Violating this policy will result in a substantial grade penalty,
and may lead to expulsion from the University. You may find it online at
http://web.ccsu.edu/academicintegrity/UndergradAcadMisconductPolicy.htm.
Please read it carefully.
Grading: The final grade will be based on projects (60%),
tests
(20%), and the final exam (20%), and will be affected by classroom
participation, conduct and attendance. The letter grades will be calculated
according to the following table:
A 
A 
B+ 
B 
B 
C+ 
C 
C 
D+ 
D 
D 
F 
95100 
9094 
8789 
8486 
8083 
7779 
7476 
7073 
6769 
6466 
6063 
059 
Unexcused late submission policy: Projects submitted more than
two days after the due date will be graded one letter grade down. Projects
submitted more than a week late will receive two letter grades down. No
submissions will be accepted more than two weeks after the due date.
Tentative schedule of classes, assignments, projects and tests (by week)
Note: Dates will be assigned for all projects due days and tests.
Check the schedule regularly for updates!

Overview of Algorithms, Data Structures, and ObjectOriented Programming

Topics:

Programs/Exercises

Hello.java
(first program)

Print "This is my first Java program" on the next line by adding another
print statement,

or (2) by including the message in the same print statement (escape sequence).

PlusOperator.java
(numbers and strings, output)

Remove the parentheses enclosing the arithmetic addition and explain what
happens and why.

Try other parenthesizings and explain the results.

Print strings and arithmetic expressions with different statements.

Modify the program to compute the celsius equivalent of today's temperature
(use the formula C=(F32)*5/9).

Arithmetic.java
(note the difference between integer division and floating point division,
explain the modulo operation)

PrimitiveTypes.java
(primitive data types)

Explain the output

Print the values of the variables (combine them in the string)

Fix the overflow problem (two's complement representation) with long, float,
and double types and explain the difference

Try 2.147483647E9 instead of 2147483647 and explain what happens and why
(narrowing conversion)

Explain the boolean expresions, why (a > b) == !(a < b) is false, and
how to fix it (make a not equal to b, or change expression)

Write a program from scratch to compute the celsius equivalent of today's
temperature (use the formula C=(F32)*5/9). Use BlueJ to create a new project
and a new class, then add the code for the main method.

BankApp.java
(classes, "uses" relation)

Which class shows in the BlueJ main window, BankAccount or BankApp? How
can we run the main method?

Move the BankAccount class into a separate file. Note the class structure
in BlueJ.

For each transaction print its type and the balance after the transaction

Add a method to class BankAccount that retruns the balance. Use it to print
the current balance instead of using display().

Create a second bank account and move the entire balance of the first account
to the second one

GasMileage.java
(input, the use of Scanner class to read numeric data)

What happens if you enter 20.5 for miles? Fix the problem in two ways.

What happens if enter miles and gallons on the same line?

Modify the program so that it reads two lines of inputs with car, miles,
and gallons (separated by blanks) and prints mpg for each car.

Student.java,
Students.java,
students.txt
(text files, loops, decision making, access modifiers)

Add public/private to the declaration of student names and print students
with System.out.println(st.lname), explain.

Change the whileloop with a forloop

Use grade to determine the type of the student: excellent (> 89), ok [60,89],
and failure (< 60)

Do counting and averaging within each student type (excellent, ok, and
failure)

Assignments:

Read Chapter 1

Download, install and get familiar with BlueJ

Run the programs and do the exercises above

Arrays, efficiency of algorithms, big O notation

Topics:

Arrays and operations with arrays: find, insert, delete

Ordered arrays, binary search

Implementing arrays is Java

Arrays of objects

Efficiency of aray operations, big O notation

Workshop
Applets: Chap02\Array\Array.html, Chap02\OrderedArray\Ordered.html

Programs/Exercises:

ArrayApp.java

Read the array items from a text fle (see Students.java)
and read the item to find from user input (see GasMileage.java)

Generate random numbers ([0,99]) to fill the aray with 100 items (see Guess.java
for random numbers) and find and delete a random item ([0,99]). Explain
and fix the run time error that occurs in some cases.

Print the number of comparisons to find an item and the number of memory
moves to delete an item.

Change the range of random numbers (use nextInt()) and explain the change
in the number of comparisons.

ClassDataApp.java

Move class Person and class ClassDataArray in separate files and explain
the class diagram shown by BlueJ

LowArrayApp.java

Explain the difference between LowArrayApp and ArrayApp

HighArrayApp.java

Insert 100 random items (generated with nextInt()) and find one of them
chosen at random. Print the number of comparisons (add a counter of comparisons
in class HighArray and set it in the find method).

Compute and print the average number of comparisons to find a random item
over 100 trials.

Print the average number of comparisons to find a random item in arrays
with 100, 200, 300,...,1000 items. Analyze the trend.

Guess.java

Change the range of numbers. What is the optimal strategy?

Include a counter to count the number of guesses

Change the doloop with a whileloop

OrderedApp.java

Insert 100 random items (generated with nextInt()) and find one of them
chosen at random. Print the number of comparisons (add a counter of comparisons
in class HighArray and set it in the find method).

Compute and print the average number of comparisons to find a random item
over 100 trials.

Print the average number of comparisons to find a random item in arrays
with 100, 200, 300,...,1000 items. Analyze the trend.

Compare the complexity of linear (HighArrayApp.java)
and binary (OrderedApp.java)
search.

ClassDataApp.java

Move class Person and class ClassDataArray in separate files and explain
the class diagram shown by BlueJ

Add another insert method to create an ordered array by last name (use
the insert method from OrderedApp.java and the compareTo() method to compare
strings). Print the number of comparisons needed to get the array sorted.

Add another find method for binary search. Compare the complexity of linear
and binary search.

Assignments:

Read Chapter 2

Run the programs and do the exercises above

March 1: Submit Project
1: Comparing linear and binary search in an array of objects

Simple sorting algorithms

Topics:

Bubble sort

Selecetion sort

Insertion sort

Sorting objects

Workshop
Applets: Chap03\Bubble\BubbleSort.html, Chap03\Selection\SelectSort.html,
Chap03\Insertion\InsertSort.html

Programs/Exercises:

BubbleSortApp.java

Trace the algorithm (display the array inside the inner or outer loop)

Display the number of swaps after the inner loop

Optimize the algorithm (break the outer loop if swaps==0)

Display the number of comparisons after the inner loop and the total number
of comparisons, and estimate the algorithms' complexity (n*(n1)/2, O(n^2))

SelectSortApp.java

Trace the algorithm (display the array after the inner loop)

Print the items that are swapped. Are swaps always needed?

Display the number of comparisons after the inner loop and the total number
of comparisons, and estimate the algorithms' complexity (n*(n1)/2, O(n^2))

InsertSortApp.java

Trace the algorithm (display the array after each pass of the outer loop)

Display the number of passes of the inner loop and total number of passes,
and estimate the algorithms' complexity (n*(n1)/4, O(n^2))

Fill the arrays with random data and print the number of comparisons made
for sorting 100,200,300,...,1000 items. Analyze the trend for the
three different algorithms.

ObjectSortApp.java
(sort the array by first name or by age)

Assignment:

Read Chapter 3

Run the programs and do the exercises above

March 810: Stacks and Queues

Topics:

Stack

Queue

Priority queue

Workshop
Applets: Chap04\Stack\Stack.html, Chap04\Queue\Queue.html, Chap04\PriorityQ\PriorityQ.html

Programs/Exercises:

QueueApp.java

Write a method to display the queue array and the front and rear indices.
Explain how wraparound works.

Write a method to display the queue (loop from 1 to nItems and use a temporary
front for wraparound).

Display the aray, the queue, and the front and rear indices.

Insert fewer items or remove fewer items and investigate what happens when
the queue is empty or full.

Extend the insert and remove methods to deal with a full and empty queue.

Add processing time to the queue. Create a new remove method that removes
item N after N calls to the method.

Simulate a queue of customers each one served for a random amount of time.
Investigate how simulation is affected by:

the size of the queue

the range of time for wich each customer is served

the rate at which customers arrive at the queue

StackApp.java

Write methods to display the stack array and the stack itself. Use them
to trace the stack operation.

Extend the push and pop methods to deal with a full and empty stack.

ReverseApp.java

Create a stack of objects of class Person and use to reverse a list of
persons.

PriorityQApp.java

Write a method to display the queue and use to trace the queue operation.

Modify the insert method to insert the new item at the rear. Compare this
queue with QueueApp.java. Which one is more efficient?

Use a priority queue instead of an ordinary one in the simulation experiments
described above.

Assignments:

Read Chapter 4

Run the programs and do the exercises above

March 17: Submit Project
2

March 2931: Linked lists

Topics:

Linked list implementation and operations

Linked list efficiency

Abstract Data Types (ADT)

Stack and Queue as linked lists

Sorted lists

Doubly linked lists

Workshop
Applets: Chap05\LinkList\LinkList.html

Programs/Exercises:

LinkListApp.java
(add methods to access the first and the last element of the list, add
toString() methods for easy printing elements and lists)

LinkList2App.java
(add a method insertAfter to insert after a particular item in the list)

LinkStackApp.java
(write an application to reverse a list using a stack)

SortedListApp.java

LinkQueueApp.java

Put different classes in separate files and see the class structure in
BlueJ.

Create a new remove() method that removes item N after N calls to the method.

Simulate a queue of customers each one served for a random amount of time.

Add a size() method and investigate how simulation is affected by the time
needed to serve a customer and the rate at which customers join the queue.

DoublyLinkedApp.java

Assignments:

Read Chapter 5

Run the programs and do the exercises above

April 7: Submit Project
3

April 57: Recursion

Topics:

Recursive programming

Recursion versus iteration

Recursive functions

List processing

Recursive binary search

Mergesort

Problem solving

Workshop
Applets: Chap06\MergeSort\MergeSort.html, Chap06\Towers\Towers.html

Programs/Exercises:

Assignments:

Read Chapter 6

Run the programs and do the exercises above

April 7: Test 1

April 12, 14: Advanced Sorting

Topics:

Workshop
Applets:

Programs/Exercises:

PartitionApp.java

Add counters for the number of comparisons and swaps and display them after
partitioning.

Investigate the relationship between the index of partitioning, the number
of comparison, and the number of swaps.

Do the previous exercise with different pivots:

beginning, end, or middle of the interval;

selected at random from the interval or from a larger interval;

last item in the array.

Compute the average number of comparisons and swaps over 100 runs.

QuickSort1App.java

Add counters for the number of comparisons, swaps, and recursive calls,
and display them after sorting.

Compute the average number of comparisons, swaps, and recursive calls over
100 runs.

Change the range of the items in the array and investigate how it affects
the performance. Is it also affected by the size of the array?

Analyze the complexity of the algortihm by varying the size of the array
(e.g. 16, 32, 64, 128, 256) and examining the performance parameters.

QuickSort2App.java

Add counters for the number of comparisons, swaps, and recursive calls,
and display them after sorting.

Compute the average number of comparisons, swaps, and recursive calls over
100 runs.

Analyze the complexity of the algortihm by varying the size of the array
(e.g. 16, 32, 64, 128, 256) and examining the performance parameters.

QuickSort3App.java

Add counters for the number of comparisons, swaps, and recursive calls,
and display them after sorting.

Compute the average number of comparisons, swaps, and recursive calls over
100 runs.

Analyze the complexity of the algortihm by varying the size of the array
(e.g. 16, 32, 64, 128, 256) and examining the performance parameters.

Compare the performance with insertion sort.

Experiment with different cutoff value and find the best one for different
sizes of the array.

Assignments:

Read Chapter 7

Run the programs and do the exercises above

April 21: Submit Project
4

April 19, 21: Binary trees

Topics:

Binary trees

Representing arithmetic expressions

Operations with binary tree

Workshop
Applets:

Programs/Exercises:

Tree.java
(create different arithmetic expressions, write a method to read prefix
notation and create a tree)

TreeApp.java

Count the number of comparisons in find(), insert(), and delete() and evaluate
their efficiency.

Create an option to clear the tree.

Create an option to insert random items and examine the resulting trees.

Create methods for finding the minimal and maximal item.

Save the items in an array using traversal and then reinsert them in the
tree. How does the tree change with different traversals?

Assignments:

Read Chapter 8

Run the programs and do the exercises above

May 3: Submit Project
5

April 26, 28: Hash tables

Topics:

Workshop
Applets:

Programs/Exercises:

HashTableApp.java

Display the key sequence for the initial filling of the table

Display the hash value and the probe sequence for insert and find.

Display the probe length for each find and insert

Display the average probe length for the initial filling of the table

Investigate how the load factor affects the average probe length

Implement quadratic probing and compare the average proble length

HashDoubleApp

Display the key sequence for the initial filling of the table

Display the hash value, the step, and the probe sequence for insert and
find.

Display the probe length for each find and insert

Display the average probe length for the initial filling of the table

Investigate how the load factor affects the average probe length

Demonstrate the importance of using a prime number for the table size

HashChainApp

Display the key sequence for the initial filling of the table

Display the probe length for each find and insert

Display the average probe length for the initial filling of the table

Investigate how the load factor affects the average probe length

Assignments:

Read Chapters 11

Run the programs and do the exercises above

April 28May 2: Test 2 (Chapters 7, 8, and 11)

May 3, 5: Graphs

Topics:

Workshop
Applets:

Programs/Exercises:

Assignments:

Read Chapters 13

Run the programs and do the exercises above

May 21: Submit Project
6

May 10, 12: Weighted Graphs

Topics:

Minimum Spanning Trees

Shortest path algorithms

Workshop
Applets:

Programs/Exercises:

Assignments:

Read Chapters 14

Run the programs and do the exercises above

May 1923: Final Exam
Project 1
Not available at this time.
Project 2
Not available at this time.
Project 3
Not available at this time.
Project 4
Not available at this time.
Project 5
Not available at this time.
Project 6
Not available at this time.
Test 1
Not available at this time.
Test 2
Not available at this time.
Final Exam
Not available at this time.