Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Questions on Data Structure and Algorithms - Assignment 1 | CS 245, Assignments of Data Structures and Algorithms

Material Type: Assignment; Class: Data Struct & Algorithms; Subject: Computer Science; University: University of San Francisco (CA); Term: Spring 2005;

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-9op
koofers-user-9op 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Department of Computer Science Intro to Parallel Computing
Programming Assignment 1
Due Wednesday, February 9 at 3 pm
Modify the linked list implementation of the “Student Database” program as follows.
1. In the online version, the head node is an ordinary node: when the list is nonempty,
it stores the record of a student. This results in relatively complex logic for the
deleteStudent method. This method can be greatly simplified if the head node is
a “dummy” node, i.e., a node that does not store information on an actual student.
Rather, if the list is nonempty, head.next stores the first actual student record. For
Homework Assignment 2, you should modify the online version so that all of the public
methods, except deleteStudent, use the dummy node. For the first part of program-
ming assignment 1, you should complete this modification so that the entire class uses
a dummy head node.
2. The array implementation of the student database inserts new student records at the
end of the list. The online linked list implementation inserts new student records at
the head of the list. Modify the program so that in addition to a dummy head node,
there’s a dummy tail node reference, whose next member refers to the last node in the
list. Then modify the insertStudent method to use this node to insert new student
records at the end of the list. There are a variety of ways to implement an empty list.
One possibility is to make the next member of both head and tail null.
3. Execution of new is quite an expensive and time-consuming operation. One way to
reduce the cost of this part of the student database is to store a free list. Each time
a node is deleted, it is added to the free list. Each time a node is added to the list,
the free list is first checked to see if there’s an available node. If there is, the first
node in the free list is used. If there isn’t, the program executes new. The free list
can be implemented as a stack: there’s a dummy head node; insertions occur at the
head or top of the list; and deletions from the free list can also occur at the top. Note
that for this part, you should not bother trying to reuse Student objects: only reuse
StudentNode objects.
In general, it will be much easier to implement, test, and debug these parts in order.
Complete part 1 before starting part 2, and complete part 2 before starting part 3. It will
also be much easier to design these on paper before writing any code. Test your design for
all the special cases you can think of, e.g., insert into empty list, attempt to delete from
empty list, etc.
The StudentDB class should link with the online StudentDBMain and Student classes.
So it should accept the same input that the existing online program accepts.
1
pf2

Partial preview of the text

Download Questions on Data Structure and Algorithms - Assignment 1 | CS 245 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

Department of Computer Science Intro to Parallel Computing

Programming Assignment 1

Due Wednesday, February 9 at 3 pm

Modify the linked list implementation of the “Student Database” program as follows.

  1. In the online version, the head node is an ordinary node: when the list is nonempty, it stores the record of a student. This results in relatively complex logic for the deleteStudent method. This method can be greatly simplified if the head node is a “dummy” node, i.e., a node that does not store information on an actual student. Rather, if the list is nonempty, head.next stores the first actual student record. For Homework Assignment 2, you should modify the online version so that all of the public methods, except deleteStudent, use the dummy node. For the first part of program- ming assignment 1, you should complete this modification so that the entire class uses a dummy head node.
  2. The array implementation of the student database inserts new student records at the end of the list. The online linked list implementation inserts new student records at the head of the list. Modify the program so that in addition to a dummy head node, there’s a dummy tail node reference, whose next member refers to the last node in the list. Then modify the insertStudent method to use this node to insert new student records at the end of the list. There are a variety of ways to implement an empty list. One possibility is to make the next member of both head and tail null.
  3. Execution of new is quite an expensive and time-consuming operation. One way to reduce the cost of this part of the student database is to store a free list. Each time a node is deleted, it is added to the free list. Each time a node is added to the list, the free list is first checked to see if there’s an available node. If there is, the first node in the free list is used. If there isn’t, the program executes new. The free list can be implemented as a stack: there’s a dummy head node; insertions occur at the head or top of the list; and deletions from the free list can also occur at the top. Note that for this part, you should not bother trying to reuse Student objects: only reuse StudentNode objects.

In general, it will be much easier to implement, test, and debug these parts in order. Complete part 1 before starting part 2, and complete part 2 before starting part 3. It will also be much easier to design these on paper before writing any code. Test your design for all the special cases you can think of, e.g., insert into empty list, attempt to delete from empty list, etc. The StudentDB class should link with the online StudentDBMain and Student classes. So it should accept the same input that the existing online program accepts.

1

Extra Help

Our TA, Anna Tikhonova, will have an office hour on Tuesday evening from 5:30 to 6:30 in Harney 536.

Submission

Remember to copy your source code to /home/submit/cs245/youruserid before 3 pm Wednesday. For example, I would type

cp StudentDB.java /home/submit/cs245/peter

Your submitted program should be named StudentDB.java. You should also get a printout of your program to me by 6pm Wednesday. Programs that are late but less than 24 hours late will have their scores reduced by 50%. Programs that are more than 24 hours late will receive no credit.

Grading

  1. Correctness will be 50% of your grade. Does your program correctly implement all of the required changes. Does it correctly insert and delete and search and print the database?
  2. Documentation will be 20% of your grade. Does your header documentation include the author’s name, the purpose of the program, and a description of how to use the pro- gram? Are the identifiers meaningful? Are any obscure constructs clearly explained? Are the purpose and usage of the classes and methods clearly explained?
  3. Source format will be 20% of your grade. Is the indentation consistent? Have blank lines been used so that the program is easy to read? Is the use of capitalization consistent? Are there any lines of source that are longer than 80 characters (i.e., wrap around the screen)?
  4. Quality of solution will be 10% of your grade. Are any of your methods more than 30 lines (not including blank lines, curly braces, or comments)? Are there multipurpose methods? Is your solution too clever — i.e., has the solution been condensed to the point where it’s incomprehensible?

Cheating

Remember that you can discuss the program with your classmates, but you cannot look at anyone else’s source code. (This includes source code that you might find on the internet.)