Solved Exam 2 for Algorithms and Data Structures | CS 200, Exams of Computer Science

Material Type: Exam; Professor: Howe; Class: Algorithms and Data Structures; Subject: Computer Science; University: Colorado State University; Term: Spring 2004;

Typology: Exams

Pre 2010

Uploaded on 03/18/2009

koofers-user-hwn
koofers-user-hwn 🇺🇸

1

(2)

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS200 Spring 2004
Midterm Exam II
April 14, 2004
Value
Points
1.
12
2.
26
3a.
5
3b.
16
3c.
8
3d.
8
4.
25
Total
100
Name _______________________________________
StudentID#____________________________________
pf3
pf4
pf5

Partial preview of the text

Download Solved Exam 2 for Algorithms and Data Structures | CS 200 and more Exams Computer Science in PDF only on Docsity!

CS200 Spring 2004

Midterm Exam II

April 14, 2004

Value Points

3a. 5

3b. 16

3c. 8

3d. 8

Total 100

Name _______________________________________

StudentID#____________________________________

  1. [12 pts] Short Answer from recitations: a) [3 pts] What is the first line in a shell script?
    b) [3 pts] How would you archive the files in directory backup into file backup.tar using verbose output?
    c) [3 pts] What command would you use to print to the screen in a shell script?
    d) [3 pts] If I wanted to run a command line interactive program as a batch and I had put the commands to be input in a file called responses, modify the following command to redirect the contents of the file into standard input: java assign5 contacts messagelist spamlist oklist
  2. [26 pts] Multiple Choice. Circle the letter of each statement that is true in each of the statements that follow the beginning statement. Note: there can be more than one or no true answers to each statement. a) Which of the following are true about stacks and queues? i) They are both linear, time-ordered structures. ii) Stack is FIFO and Queue is LIFO. iii) A wrap around array implementation of a queue provides the lowest Big O values for all operations provided you know how much space to allocate. b) Which are true about priority queues? i) It has methods: peek, enqueue and dequeue. ii) Worst case to add an element is O(n) when using either sorted or unsorted ArrayList implementation. iii) Provides access to the highest priority/minimum value, one element at a time. 26

b) [16 pts] Fill in the array for the heap that results given the following heap and the commands that follow: 1 13 15 21 24 19 22 Add 5 Remove Remove Add 21 c) [8 pts] In assignment 5, the word lists are implemented using a Binary Search Tree. Compare that approach (i.e., the Binary Search Tree) against storing them in an ArrayList which is searched using Binary Search. State one pro (reason why the Binary Search Tree is a better approach) and one con (reason why the Binary Search Tree is a worse approach). PROS CONS

d) [8 pts] Pick one of the data structures that can be used to implement a map (as listed in class). Name the underlying data structure that you have selected and fill out the following table of worst case Big-O values for the computation of the three operations and for the space required. Operation Data Structure Space Add Search Remove

  1. [25 pts] Assuming you have code that implements the following interface for a BinaryTreeNode class, fill in the code for the constructor and Next method for an Iterator that performs an inorder traversal of a Binary Tree starting from the root. If you need to create other supporting methods, use the next page or back of this page. Assume that left, right and parent return null if there is none. public class BinaryTreeNode { public BinaryTreeNode(Object value) public BinaryTreeNode left() public BinaryTreeNode right() public BinaryTreeNode parent() public void setLeft(BinaryTreeNode newnode) public void setRight(BinaryTreeNode newnode) public void setParent(BinaryTreeNode newnode) public Object value() public void setValue(Object newval) } public class BTIterator{ public BTIterator(BinaryTreeNode root) {