Fall 06 CS 100 Test 1

Fall 06 CS 100 Test 1 - Test 1: Compsci 100 Owen Astrachan...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Test 1: Compsci 100 Owen Astrachan October 3, 2006 Name: Login: Honor code acknowledgment (signature) value grade Problem 1 18 pts. Problem 2 18 pts. Problem 3 16 pts. Problem 4 18 pts. Problem 5 12 pts. TOTAL: 82 pts. This test has 12 pages, be sure your test has them all. Do NOT spend too much time on one question remember that this class lasts 75 minutes. In writing code you do not need to worry about specifying the proper import statements . Assume that all libraries and packages weve discussed are imported in any code you write. Nodes on this test are implemented using the following declaration which is nested inside a class Test in which all methods are written. public static class Node{ public String info; public Node next; public Node(String s, Node link){ info = s; next = link; } } 1 PROBLEM 1 : ( WhaddyaKnow (18 points) ) Part A (1 points) What is log 2 (1024) ? Part B (5 points) Evaluate both sums: What is 1 + 2 + 4 + 8 + 16 + 32? What is 1 + 2 + 3 + 4 + + 19 + 20? Part C (3 points) What is the exact value of the variable result below where the method think follows. Show reasoning for partial credit. int result = think(1000) - think(998); public static int think(int n){ int sum = 0; for(int k=1; k <= n; k++) sum += k; return sum; } Part D (4 points) What is the value returned by the call magic(802) where the method magic is below. Justify your answer. public static int magic(int n){ int sum = 0; for(int k=1; k <= n; k = k * 2) { sum += k; } return sum; } Part E (2 points) What is the runtime complexity of the call magic(N) ? Justify your answer. Part F (3 points) What is the runtime complexity of the call magic(N*N*N*N) ? Justify your answer. 2 PROBLEM 2 : ( tops, spot, ... (18 points) ) The method last2first below correctly moves the last node to the front of a linked-list and returns a pointer to the new first node. Thus the call list = last2first(list) would change ("ape", "bat", "cat", "dog") to the list ("dog", "ape", "bat", "cat") public static Node last2first(Node list){ if (list == null || list.next == null) return list; // contains at least two nodes Node temp = list; while (temp.next.next != null) { temp = temp.next; } temp.next.next = list; list = temp.next; temp.next = null; return list; } Part A (3 points) What is the big-Oh complexity of last2first when executed on an N-node list? Justify your answer briefly....
View Full Document

Page1 / 12

Fall 06 CS 100 Test 1 - Test 1: Compsci 100 Owen Astrachan...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online