4 Problems on Algorithms and Data Structures - Midterm Exam 1 | 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/13/2009

koofers-user-2tu
koofers-user-2tu 🇺🇸

9 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS200 Spring 2004
Midterm Exam I
March 3, 2004
Value
Points
1.
15
2.
30
3a.
15
3b.
10
3c.
10
4.
20
Total
100
Name _______________________________________
StudentID#____________________________________
pf3
pf4
pf5

Partial preview of the text

Download 4 Problems on Algorithms and Data Structures - Midterm Exam 1 | CS 200 and more Exams Computer Science in PDF only on Docsity!

CS200 Spring 2004

Midterm Exam I

March 3, 2004

Value Points

3a. 15

3b. 10

3c. 10

Total 100

Name _______________________________________

StudentID#____________________________________

  1. [15 pts] Short Answer: Fill in the Linux, Eclipse or Java information asked for in each question below. a) [3 pts] What single line of commands would you use to print a list of only the printers, but not the queue information? (hint use the pipe command)

 b) [3 pts] Give an example of casting in Java. __________________________________________________________________ _c)_ [3 pts] What is the command to give the owner read and write permissions and groups and others read only permissions to the file "index.html"? __________________________________________________________________ d) [3 pts] You are running program "java prog1". What is the command to redirect both standard out and standard error into "output.log"? __________________________________________________________________ e) [3 pts] What color does eclipse display "standard error" as in the console window? __________________________________________________________________ 
  1. [30 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 QuickSort? i) In-place. ii) Worst case is when data are already sorted. iii) O(n log n) best case time complexity. b) Which of the following statements describes SelectionSort? i) Search the unsorted part of the array for the next highest value and swap its position with the position next to the sorted part. ii) To improve the basic algorithm, use binary search to find the position in the array for a swap. iii) In-place, O(n) worst case for swaps, O(n^2) best case for compares

b) [10 pts] In assignment 2, you used mergesort to sort the Contacts file. So assignment 1 and 2 required two approaches to the same problem: creating a sorted ArrayList by reading in strings from a file. Which approach is better for this problem? (Circle one and justify your response based on efficiency and use considerations) BinarySearch+Insert OR MergeSort c) [10 pts] Assume you were being asked to program a class for keeping track of the allowed email Contacts. The calling code will need to confirm whether a given contact (of type String) is an allowed email address. You get a choice of data structure for storing the Contacts. Which data structure is better for the Contacts? (Circle one and justify your response based on efficiency and use considerations) Ordered ArrayList OR Ordered Doubly Linked List

  1. [20 pts] The following is a modified version of Bailey’s MergeSort. The code is missing two lines and has two other bugs in it. Annotate the code with changes that should fix it so that it sorts an array of numbers from low to high. private static void mergeSort (ArrayList data, ArrayList temp, int low, int high){ int n = high-low+1; int mid = low + n/2; int i; for (i = low; i <mid; i++){ temp.set(i,data.get(i)); } mergeSortRecursive(data,temp,low,mid-1,cnt); merge(data,temp,low,mid,high); } private static void merge(ArrayList data, ArrayList temp, int low, int mid, int high){ int ri = 0; int ti = low; int di = mid; while (ti < mid && di <= high){ if (((Comparable)data.get(di)).compareTo((Comparable)temp.get(ti)) < 0){ data.set(ri++,data.get(di++)); } else { data.set(ri++,temp.get(ti++)); } } }