Final Exam for Data Structures I | COMP 380, Exams of Data Structures and Algorithms

Material Type: Exam; Class: DATA STRUCTURES I; Subject: Computer Science; University: Wentworth Institute of Technology; Term: Unknown 1989;

Typology: Exams

Pre 2010

Uploaded on 08/18/2009

koofers-user-km1-1
koofers-user-km1-1 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
NAME___________________________________________________
Wentworth Institute of Technology
Division of Professional and Continuing Studies
COMP380 Section 71 - Data Structures I - Spring, 2006
Final – Open Book
Short Answers – 5 points each.
1.
(a)Declare an enumerated class called “Emotion”. Have the items in this class be “happy”, “sad”, “angry”.
(b) Write an enhanced for loop that prints out the values of Emotion
2. Add the appropriate items to the below diagram to make it into a stack.
3. List the methods (include the return datatypes and arguments with datatypes) that need to be implemented in order
for a class to implement the List interface
4. Put a checkmark next to the LEGAL statements below (T is a Generic datatype indicator):
______T item = new T();
______public class TwoTypes <T,K>
______public <T extends Comparable<? super T> > void aMethod(T anItem)
______anArray = new T[n];
______static <T> T getMax(T a, T b);
5. Write the “Big-O” running time notation of the following algorithms/operations:
Binary Search_______________________________________________
A bubble sort_______________________________________________
Cloning an array_____________________________________________
Accessing an element in an array________________________________
Insertion into a stack_________________________________________
/app/work/qkd26i-431935-2765038-finalcomp380sp06-doc.doc 11/28/2020 1
P1
P2
Total
pf3
pf4

Partial preview of the text

Download Final Exam for Data Structures I | COMP 380 and more Exams Data Structures and Algorithms in PDF only on Docsity!

NAME___________________________________________________

Wentworth Institute of Technology

Division of Professional and Continuing Studies

COMP380 Section 71 - Data Structures I - Spring, 2006

Final – Open Book

Short Answers – 5 points each.

(a)Declare an enumerated class called “Emotion”. Have the items in this class be “happy”, “sad”, “angry”. (b) Write an enhanced for loop that prints out the values of Emotion

  1. Add the appropriate items to the below diagram to make it into a stack.
  2. List the methods (include the return datatypes and arguments with datatypes) that need to be implemented in order for a class to implement the List interface
  3. Put a checkmark next to the LEGAL statements below (T is a Generic datatype indicator): ______ T item = new T(); ______public class TwoTypes <T,K> ______public <T extends Comparable<? super T> > void aMethod(T anItem) ______anArray = new T[n]; ______static T getMax(T a, T b);
  4. Write the “Big-O” running time notation of the following algorithms/operations: Binary Search_______________________________________________ A bubble sort_______________________________________________ Cloning an array_____________________________________________ Accessing an element in an array________________________________ Insertion into a stack_________________________________________

P

P

Total

a. What operation is EASY to do for an array-based list, but is hard to do with Linked? Why? b. What operation is EASY to do for Linked lists, but is Hard to do with array-based lists? Why?

  1. Given the following statements and associated class definitions : (IN MAIN PROGRAM) Food apple = new Food(); Food bread = new Food(); (AFTER MAIN PROGRAM) class Food { // this class defines a Food. No methods, just data protected int foodNum; //number of the Food public double weight; //weight of the Food public char category; //can be ‘M’, ‘G’, or ‘F’ //to indicate meat, grain, or fruit } a. Write a statement that sets the weight of bread to 5.7. b. Write a statement that sets the category of apple to the character F.
  2. Starting with the class Food from problem 7, a derived class Cereal is defined as follows: class Cereal extends Food { String whichGrain; //can be “Wheat” or “Corn” } Put a checkmark next to the LEGAL statements. Leave the illegal statements blank. Assume that the object myCereal was instantiated as a Cereal and myMeat was instantiated as a Food. ____________myCereal.foodNum = 3; __________myCereal.whichGrain=”Corn”; ____________myCereal = myMeat; __________myCereal.category = ‘G’; ____________myMeat = myCereal;
  3. Write a code fragment that will do a search on the below array for an integer called target. The fragment should then replace the target integer with the value of 99. The code fragment should determine the size of the list before it does the search. It should also count the number of substitutions made. In the below list, if the target integer is 66, two elements will be replaced with the number 99. int[] myList = {22,33,66,77,89, 92, 66, 102};

Part II - Programming Exercises - 40 points DO ONE OUT OF THE FOLLOWING THREE PROBLEMS Note that grading will take into account the quality of the comments in your code.

  1. Make a class called ScrabblePiece. A ScrabblePiece has a Letter and a Point Value. Write a main program that adds five Scrabble pieces to a Bag collection of ScrabblePieces, then “pulls them out” at random.
  2. Read datingData into an array of DatePerson. Sort the array based on the person’s last name. Then enter all the items that are in the array into a Queue based on the person’s last name. Print out the top 5 and the last 5 entries in the queue. You should use the DatePerson class, but modify it as necessary. Also use the readDatingDatafromDisk() method to read the file.
  3. Get the datafile, stateData.dat from the instructor. This datafile has 2-letter state codes followed by it’s name, it’s population, and the state codes of it’s neighbors. Read this file into a Stack data structure. Then have a query- response loop where the user enters the ID of a State, and the computer prints out the name of the state and it’s population.