CS 261 Homework 3: Data Structures - Vectors and Interfaces, Assignments of Data Structures and Algorithms

Information about a university computer science homework assignment focused on implementing vector data structure with bag and findmin interfaces. It includes instructions, due date, and study questions related to vector data structures and java programming concepts. The assignment requires students to modify the vector class and write answers to given questions.

Typology: Assignments

Pre 2010

Uploaded on 08/30/2009

koofers-user-5kh
koofers-user-5kh 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 261 — Data Structures
Homework #3: Vectors (30 pts)
Due date: Friday, April 18, 2003 (5:00 PM)
This assignment is designed to make you think about the Vector data structure. Treat this paper as a
specification for your assignment. We will grade you code by providing a class that fully tests the various
method that you will implement. Study problems and exercises must be legible and will be graded on cor-
rectness.
What to do:
Modify the Vector data structure so that it will support the Bag interface. Call your new version
VectorBag.java. What is the asymptotic complexity of the methods you need (include the
answer with you written homework)? (I suggest that you have the class VectorBag extend Vec-
tor and implement Bag.) (10 pts)
Modify the Vector data structure so that it will support the FindMin interface. Call your new ver-
sion VectorMin.java. What is the asymptotic complexity of the methods you need? (Again, I suggest
a similar approach as with VectorBag above.) (5 pts)
Written homework:
Answer(s) to any questions given above.
Chapter 6 Study Questions 2, 3, 4, 6
Q 6.2) What does it mean to say that the array data type supports random access? (1 pt)
Q 6.3) What is a polymorphic variable? What are the two types of polymorphic variable in Java? (2
pts)
Q 6.4) What purpose is served by the wrapper classes in the Java standard library? (2 pts)
Q 6.6) What is the size of a Vector? What is the capacity? How are these two values different? (2
pts)
Chapter 6 Exercises 1,5, and 6
E 6.1) Describe the state of a Vector after the following sequence of operations: (2 pts)
Vector v = new Vector();
v.setSize(4);
v.setElementAt(“A”, 3);
v.setElementAt(“B”, 1);
v.removeLast();
v.addElementAt(“C”, 2);
v.addLast(“D”);
v.setSize(6);
pf2

Partial preview of the text

Download CS 261 Homework 3: Data Structures - Vectors and Interfaces and more Assignments Data Structures and Algorithms in PDF only on Docsity!

CS 261 — Data Structures

Homework #3: Vectors (30 pts) Due date: Friday, April 18, 2003 (5:00 PM)

This assignment is designed to make you think about the Vector data structure. Treat this paper as a specification for your assignment. We will grade you code by providing a class that fully tests the various method that you will implement. Study problems and exercises must be legible and will be graded on cor- rectness.

What to do:

  • Modify the Vector data structure so that it will support the Bag interface. Call your new version VectorBag.java. What is the asymptotic complexity of the methods you need (include the answer with you written homework)? (I suggest that you have the class VectorBag extend Vec- tor and implement Bag.) ( 10 pts )
  • Modify the Vector data structure so that it will support the FindMin interface. Call your new ver- sion VectorMin.java. What is the asymptotic complexity of the methods you need? (Again, I suggest a similar approach as with VectorBag above.) ( 5 pts )

Written homework:

  • Answer(s) to any questions given above.
  • Chapter 6 Study Questions 2, 3, 4, 6 Q 6.2) What does it mean to say that the array data type supports random access? ( 1 pt) Q 6.3) What is a polymorphic variable? What are the two types of polymorphic variable in Java? ( 2 pts ) Q 6.4) What purpose is served by the wrapper classes in the Java standard library? ( 2 pts ) Q 6.6) What is the size of a Vector? What is the capacity? How are these two values different? ( 2 pts )
  • Chapter 6 Exercises 1,5, and 6 E 6.1) Describe the state of a Vector after the following sequence of operations: ( 2 pts )

Vector v = new Vector(); v.setSize(4); v.setElementAt(“A”, 3); v.setElementAt(“B”, 1); v.removeLast(); v.addElementAt(“C”, 2); v.addLast(“D”); v.setSize(6);

E 6.5) To illustrate that the expected execution time for addLast is constant, imagine that we start with an empty vector and perform 25 successive addLast operations. To estimate the execution time for each, assign a value of 1 to those executions that can be performed in constant time and a value equal to the size of the old vector to those executions that require a reallocation. (Note that the book says to use the new size, but we want you to use the old size.) Then sum the values and divide by 25. How large is the resulting average? (Assume that the initial array size is 8) ( 3 pts )

E 6.6) Suppose that instead of doubling the size of the vector when a reallocation occurs, we sim- ply increase the size of the vector by 1. Perform the same analysis as described in the previ- ous question. How large is the resulting average now? ( 3 pts )

What to turn in:

In class: a printout of written homework in the file Answers.txt and a printout of your source files VectorBag.java and VectorMin.java.

Via the web: the files VectorBag.java, VectorMin.java, and Answers.txt.