CS 235 Homework Assignments
Homework assignments are due in the box at the TA office by the time the building closes on the due date. Please don't submit homework in class. Please submit each homework on a separate piece of 8.5 by 11 inch paper.
Late submissions are not accepted.
Email submissions are not accepted.
Assignment | Due Date |
---|---|
Homework 1 | 29 Jun 2017 |
1. Consider a List of strings that contains the following strings in the order given:
"bob" "ann" "sue" "ned" [0] [1] [2] [3]
Give the contents of the List after each operation.
a. list.insert(2, "bob"); b. list.insert(5, "ann"); c. list.remove(0); d. list.remove(3);
Assignment | Due Date |
---|---|
Homework 2 | 3 Jul 2017 |
1. Consider a Set of strings that contains the following strings:
"bob" "ann" "sue" "ned"
Give the contents of the Set after each operation.
a. set.add("bob"); b. set.add("zed"); c. set.remove("bob"); d. set.remove("ted");
Assignment | Due Date |
---|---|
Homework 3 | 5 Jul 2017 |
1. Consider a Stack that contains the following strings in the order given. The top of the Stack is the first string listed and the bottom of the Stack is the last string.
"bob" "ann"Give the contents of the Stack after each operation.
a. stack.pop(); b. stack.push("sue"); c. stack.push("ned"); d. stack.pop();
Assignment | Due Date |
---|---|
Homework 4 | 5 Jul 2017 |
1. Consider a Queue that contains the following strings in the order given. The front of the Queue is the first string listed and the back of the Queue is the last string.
"ann" "bob"
Give the contents of the Queue after each operation.
a. queue.remove(); b. queue.add("sue"); c. queue.add("ned"); d. queue.remove();
Assignment | Due Date |
---|---|
Homework 5 | 6 Jul 2017 |
1. Suppose you have been asked to implement software solutions for each of the applications listed below. For each application, indicate which data type (List, Set, Map, Stack, Queue, Priority Queue) would be most effective in solving the problem.
a. A compiler that uses a symbol table which stores the name, type, size, and location of each variable in a program.
b. A photo management application that allows you to create and edit slideshows that display a collection of photos in the order you want.
c. A barber shop where customers can pay a higher price for faster service.
d. A process scheduler for an operating system that runs jobs using a first-come-first-served rule.
Assignment | Due Date |
---|---|
Homework 6 | 6 Jul 2017 |
1. Trace the execution of 'mystery' when called with a value of 4 for n. List all the calls and returns of 'mystery' in the order they occur. For each call give the value passed into the function. For each return give the value returned from the function.
int mystery(int n) { if (n == 2) return 4; else return (n*n) * mystery(n / 2); }
Assignment | Due Date |
---|---|
Homework 7 | 10 Jul 2017 |
1. Give the Big-Oh for the running time of each code fragment.
a. double power( double x, int n ) { double result = 1.0; for( int i = 0; i < n; i++ ) result *= x; return result; } b. bool hasTwoTrueValues( bool array [], int n ) { for( int i = 0; i < n; i++ ) for( int j = i + 1; j < n; j++ ) if( array[ i ] && array[ j ] ) return true; return false; } c. bool hasTwoTrueValues( bool array [], int n ) { int count = 0; for( int i = 0; i < n; i++ ) if( array[ i ] ) count++; return count >= 2; } d. bool hasTwoTrueValues( bool array [], int n ) { for( int i = 0; i < n; i++ ) if( array[ i ] ) for( int j = i + 1; j < n; j++ ) if( array[ j ] ) return true; return false; }
Assignment | Due Date |
---|---|
Homework 8 | 10 Jul 2017 |
1. An algorithm takes 0.5ms for input size 100. How large a problem can be solved in 50 seconds if the running time is:
a. linear b. quadratic c. cubic d. O(10^n)
Assignment | Due Date |
---|---|
Homework 9 | 12 Jul 2017 |
1. Show the steps of the binary search algorithm. For each step of the algorithm, give the indexes of first, last, and middle when searching for "Deb" in the following list.
"Alf" "Ann" "Bev" "Bob" "Deb" "Jed" "Jim" "Joe" "Liz" "Meg" "Ned" "Sam" "Sue" "Wes" "Zed" [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]
Assignment | Due Date |
---|---|
Homework 10 | 12 Jul 2017 |
1. Show the steps of insertion sort on the list. Give the contents of the list after each pass of insertion sort.
8 4 1 5 1
2. Show the steps of selection sort on the list. Give the contents of the list after each pass of selection sort.
8 4 1 9 2
Assignment | Due Date |
---|---|
Homework 11 | 13 Jul 2017 |
1. Show the steps of Merge Sort on the List. Give the lists that result from each split step and each merge step of Merge Sort.
8 2 4 1
Assignment | Due Date |
---|---|
Homework 12 | 13 Jul 2017 |
1. Show the steps of Quick Sort on the List. Give the lists that result from each partition step and each concatenate step of Quick Sort. Always use the item in the middle position as the quick-sort pivot. Use the simple partitioning algorithm (not the in-place partitioning algorithm).
9 4 8 5 7 2 1
Assignment | Due Date |
---|---|
Homework 15 | 26 Jul 2017 |
1. For each type of traversal given below, list the order in which the nodes of the binary tree are visited.
a. preorder b. postorder c. inorder d. level-order
A / \ B C \ \ D E / \ F G / H
Assignment | Due Date |
---|---|
Homework 16 | 27 Jul 2017 |
1. Draw the tree that results after adding 5 to the BST.
3 / \ 2 7 / / \ 1 4 9 \ 6
2. Draw the tree that results after removing 3 from the BST. (Use the CTR rule when doing removes.)
3 / \ 2 7 / / \ 1 4 9 \ 6
Assignment | Due Date |
---|---|
Homework 17 | 31 Jul 2017 |
a. Insert the numbers into an initially empty AVL tree. Give the diagram of the tree that results.
2 1 4 5 9
b. Draw the tree that results from adding 3 to the tree in part a.
c. Draw the tree that results from adding 6 to the tree in part b.
d. Draw the tree that results from adding 7 to the tree in part c.
e. Draw the tree that results from removing 4 from the tree in part d.
f. Draw the tree that results from removing 7 from the tree in part e.
g. Draw the tree that results from removing 9 from the tree in part f.
h. Draw the tree that results from removing 6 from the tree in part g.
(Use the CTR rule when doing removes.)
Assignment | Due Date |
---|---|
Homework 18 | 3 Aug 2017 |
The following instructions apply to all parts of this assignment. Use a hash table with a fixed size of 10. Don't grow the table or do any rehashing. Use the hash function H(x) = x % 10.
Use Chaining to resolve collisions in part a.
a. Insert the items into an initially empty hash table. Draw the table that results.
71 23 73 99 44 79 89
Use Linear Probing to resolve collisions in parts b, c, and d.
b. Insert the items into an initially empty hash table. Draw the table that results.
71 23 73 99 44
c. Draw the table that results from adding 79 to the table in part b.
d. Draw the table that results from adding 89 to the table in part c.
Use Quadratic Probing to resolve collisions in parts e, f, and g.
e. Insert the items into an initially empty hash table. Draw the table that results.
71 23 73 99 44
f. Draw the table that results from adding 79 to the table in part e.
g. Draw the table that results from adding 89 to the table in part f.
Assignment | Due Date |
---|---|
Homework 19 | 7 Aug 2017 |
a. Give the heap that results from inserting 10, 12, 1 into an initially empty MIN-heap.
b. Give the heap that results from adding 14, 6 to the heap in part a.
c. Give the heap that results from adding 5 to the heap in part b.
d. Give the heap that results from adding 8, 15, 3 to the heap in part c.
e. Give the heap that results from removing the minimum item from the heap in part d.
f. Give the heap that results from removing the minimum item from the heap in part e.
Assignment | Due Date |
---|---|
Homework 20 | 9 Aug 2017 |
1. Follow the steps below to show the 'swap and percolate-down' steps of Heap Sort. The following heap has already been built using the Heapify algorithm.
9 8 7 4 5 1 2
a. Using the heap above, give the list after one 'swap and percolate-down' step of Heap Sort.
b. Using the result from part a, give the list after a second 'swap and percolate-down' step of Heap Sort.
c. Using the result from part b, give the list after a third 'swap and percolate-down' step of Heap Sort.
2. Follow the steps below to build a MAX-heap from the list of items using the 'Heapify' algorithm.
1 5 7 4 8 9 2
a. Give the contents of the list after the percolate-down step is done on 7.
b. Using the result from part a, give the contents of the list after the percolate-down step is done on 5.
c. Using the result from part b, give the contents of the list after the percolate-down step is done on 1.