Assignment #3

CS 163 Data Structures

 

Submit your assignment to the D2L Dropbox (sign on via d2l.pdx.edu)

***Assignments in CS163 consist of written homework and programming***

***All parts are required to get a grade on this homework ***

 

HOMEWORK QUESTIONS:

1)      Evaluate Data Structures. We learned about a number of data structures so far this term:

a)      linear linked lists,

b)     circular linked lists,

c)      doubly linked lists,

d)     linear linked lists of arrays of data

e)      Arrays of head pointers to linear linked lists

 

Discuss the strengths and weaknesses of these data structures, in terms of run time efficiency and memory.

 

2)      Ethics. As we work building abstract data types this term (ADTs), we find that we can come in contact with sensitive information that is stored in our data structures. Let’s say you were working for a company and it is your responsibility to ensure the safety and security of that information. Create a list of 3 rules that you would expect to be followed by programmers at your company. These must represent your thoughts about ethical concerns that may arise.

 

3)      Linux. Look into the following tools and experiment with each:

a)      Makefile – what is a makefile and discuss why we would want one

b)     Vim – show how to substitute “teh” for “the” in all occurances

c)      GDB – discuss how to use break points

d)     Valgrind – ask the tutors how to use it and what it is for!

 

4)      Programming – Goal: The goal of the third program is to create a hash table using chaining per Topic#6. Hash tables are very useful in situations where an individual wants to quickly find their data by the “value” or “search key”.  You could think of them as similar to an array, except the client program uses a “key” instead of an “index” to get to the data. The key is then mapped through the hash function which turns it into an index!

 

 

 

Programming – Problem Statement: It is time to start planning for Spring term and soon even next year. Have you decided what classes you are going to take? And, how do those classes help you in reaching your graduation goal? My daughter is just starting to plan her classes for OSU next year for her Math major and is finding it rather complicated. So many options but yet there are so many restrictions. Our job with this program is to build a system to simplify finding courses that work for your ultimate plans. This application is well suited for hashing, because I am not concerned about getting a sorted list. Instead, I want to quickly determine if a course is available without the need for a sequential search!

 

Data Structures: Write a C++ program that implements and uses a table abstract data type using a hash table (with chaining) to load from a file, retrieve, display, and remove (a section) information about college classes. We would like to search by (a) class number/name (e.g., CS163 Data Structures). Extra credit will be given for people who also build a hash table for searching for all courses available at a given time/day.

What does retrieve need to do? It should take the class number/name and supply back to the calling routine information about the details about that class (number of sections and any notes (e.g., fees, or registration restrictions). Retrieve, since it is an ADT operation, should not correspond with the user (i.e., it should not prompt, echo, input, or output data). Provide an additional retrieve_section, that performs the same work but finds a particular section of the course and provides more details about that particular sections (e.g., time/day, how full the class is, classroom location). You may alter the information stored about a class – if you find that other information would be more valuable to you.

 

Evaluate the performance of storing and retrieving items from this table. Monitor the number of collisions that occur for a given set of data that you select. Make sure your hash table’s size is a prime number. Try different table sizes, and evaluate the performance (i.e., the length of the chains!). Your design writeup must discuss what you have discovered.

 

In summary, the required functions for your TABLE ADT are:

1.      Constructor,

2.      Destructor

3.      Load information about the classes offered (you should use external data files)

4.      Retrieve (based on class number/name)

5.      Retrieve a Section (based on class number/name/section)

6.      Display all

7.      Remove (based on class number/name/section)

 

Things you should know...as part of your program:

1)      Do not use statically allocated arrays in your classes or structures. All memory must be dynamically allocated and kept to a minimum!

2)      All data members in a class must be private

3)      Never perform input operations from your class in CS163

4)      Global variables are not allowed in CS163

5) Do not use the String class! (use arrays of characters instead and the cstring library!)

6)   Use modular design, separating the .h files from the .cpp files. Remember, .h files should contain the class header and any necessary prototypes. The .cpp files should contain function definitions. You must have at least 1 .h file and 2 .cpp files. Never "#include" .cpp files!

7)  Use the iostream library for all I/O; do not use stdio.h.

8) Make sure to define a constructor and destructor for your class. Your destructor must deallocate all dynamically allocated memory.

9) Remember that 20% of each program's grade is based on a written discussion of the design. Take a look at the style sheet which gives instruction on the topics that your write-up needs to cover.