CSSE 221: Software Development Honors - Assignment Solutions, Assignments of Computer Science

The solutions to various programming assignments and exercises from the csse 221: fundamentals of software development honors course. The assignments cover topics such as treeset, priorityqueue, run time analysis, and more. Students are expected to have completed the corresponding readings before attempting the solutions.

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-g6v
koofers-user-g6v ๐Ÿ‡บ๐Ÿ‡ธ

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSSE 221: Fundamentals of Software Development Honors
Key
Programming assignment (due by Saturday Oct 20, 11:59 pm)
You should have checked in the version of your Simulation project corresponding to
where you are on your schedule.
Written homework due before beginning of class on Thursday, Oct 18).
1. Complete all the reading.
2. (12 pts) Weiss 6.4
SOLUTION:
TreeSet, PriorityQueue
3. (8 pts) Weiss 6.6
SOLUTION:
Run time = O(1)
4. (10 pts) Weiss 6.12 (a,b only); assume that the elements are sorted in increasing
order.
a. SOLUTION:
findMin โ€“ returns a reference to the first item in the array
deleteMin โ€“ returns a reference to the first item in the array, shift
all items forward
insert โ€“ iterate to the location in the array where the element
belongs, shift all other elements toward the back and then store the
value into the array
b. SOLUTION:
findMin โ€“ O(1)
deleteMin โ€“ O(N)
insert โ€“ O(N)
5. (10 pts) Weiss 6.13 (a,b only)
a. SOLUTION:
findMin โ€“ loops through the entire list, storing a reference to the
smallest value until it reaches the end, then returns a reference to
the smallest
deleteMin โ€“ loops through to find the min, then removes the
element and shifts all forward, then returns the reference to the
minimum
insert โ€“ add to the end of the array
b. SOLUTION:
findMin โ€“ O(N)
deleteMin โ€“ O(N)
insert โ€“ O(1)
pf2

Partial preview of the text

Download CSSE 221: Software Development Honors - Assignment Solutions and more Assignments Computer Science in PDF only on Docsity!

CSSE 221: Fundamentals of Software Development Honors Key Programming assignment (due by Saturday Oct 20, 11:59 pm) You should have checked in the version of your Simulation project corresponding to where you are on your schedule. Written homework due before beginning of class on Thursday, Oct 18).

  1. Complete all the reading.
  2. (12 pts) Weiss 6. SOLUTION: TreeSet, PriorityQueue
  3. (8 pts) Weiss 6. SOLUTION: Run time = O(1)
  4. (10 pts) Weiss 6.12 (a,b only); assume that the elements are sorted in increasing order. a. SOLUTION: findMin โ€“ returns a reference to the first item in the array deleteMin โ€“ returns a reference to the first item in the array, shift all items forward insert โ€“ iterate to the location in the array where the element belongs, shift all other elements toward the back and then store the value into the array

b. SOLUTION: findMin โ€“ O(1) deleteMin โ€“ O(N) insert โ€“ O(N)

  1. (10 pts) Weiss 6.13 (a,b only) a. SOLUTION: findMin โ€“ loops through the entire list, storing a reference to the smallest value until it reaches the end, then returns a reference to the smallest deleteMin โ€“ loops through to find the min, then removes the element and shifts all forward, then returns the reference to the minimum insert โ€“ add to the end of the array

b. SOLUTION: findMin โ€“ O(N) deleteMin โ€“ O(N) insert โ€“ O(1)

  1. (10 pts) Weiss 6.14 (a,b only) a. SOLUTION: insert โ€“ inserts at the end of the array findMin โ€“ returns a reference to the element based on the additional data member deleteMin โ€“ removes from the known minimum location, shifts all forward, loops to the new minimum

b. SOLUTION: findMin โ€“ O(1) deleteMin โ€“ O(N) insert โ€“ O(1)

  1. (10 pts) Weiss 6. SOLUTION: private static void removeEveryOther(List list) { Iterator itr = list.iterator(); boolean toggle = true ; while (itr.hasNext()) { itr.next(); if (toggle) { itr.remove(); } toggle = !toggle; } } You need to use an iterator to do this one, since Listโ€™s remove(i) is O(n), and you are doing n/2 removes, giving O(n^2 ) runtime, which isnโ€™t allowed in the problem.

An interesting related problem is how to do this if itโ€™s a definitely a LinkedList and you have access to its internal structure. Grading: if iterator, gets >=5 pts. If use set/get, this is O(n^2 ), so -5..

  1. (20 pts) Please finish the Sierpinski Gasket project and check in your code to your personal repository.
  2. (20 pts) Please do the Fibonacci efficiency exercise stated here, making sure your code is in your personal repository as well.