CMPSC 20 Solution of HW1 Note: In grading: only problems 3,5,8,9 were graded out of 10,20,10,10 respectively. The total is out of 50 and the average is 38.6 -1- The output must be "0" regardless of the body of the method f(int x). This is because x i
Programming Assignment #2
CMPSC 20, Spring 2008
Date assigned: April 18, 2008
In this assignment you will develop a linked data structure that stores a single-variable algebraic expression.
You are supposed to develop functionality to encode and decode a
University of California, Santa Barbara
CS20, Spring 2008
Homework II solutions
Question 1.
(i) 24.
(ii) The factorial function.
Question 2.
(i) ab + cd − /
(ii) abc ∗ −de ∗ f ∗ g + /
(iii) ab/cde − +∗
(iv) ab^ c ∗ d - e ^ f g ^ h ^ +
Question 3.
public O
CS20S08- HW3 Solutions—May 8, 2008
Q1:
greatestCommonDivisor(int i, int j){
if ( j = 0 )
return i;
else
return greatestCommonDivisor(j, i % j);
}
Q2:
Recursive:
int power(int i, int n){
if ( n = 0 )
return 1;
else
return ( i * power(i, n-1);
}
Iterative:
CS 20 WEEK 2: THURSDAY
Algorithm analysis Useful identities.
n
2i = 2n+1 1
i=0 n i=0 n
i =2 2i
n
C f (i) = C
i=0 i=0
f (i)
xa xb = x(a+b) (xa )b = xa
b
2a + 2a = 2(a+1) = 2 2a logC (B ) logC (A)
logA (B ) = Counting iterations in a snippet of code.
Note.
CS 20: WEEK 1
Note. In diagrams, draw null as a ground schematic element Links example public class Link cfw_ public Link next; public int value; public Link(int v) cfw_ next = null; value = v; Variable categories instance variables are located in objec
Midterm #1 Solution CS20, Spring 2004 Problem 1: int compareTo( Object other) where the result: < 0 if this less than other = 0 if this = other > 0 if this > other Problem 2: String, Number, Integer, Float, Student, Name,. Problem 3: String getMajor(
Midterm Exam #1 (100 Points Total) CS20, Spring, 2004 April 23, 2004 1.(7 points) If a class implements the interface Comparable, describe the method(s) that need to be included? Be sure to include the parameters, the parameter types, and the return
CMPS 20 HW2 solution -1Notes: - If P is null then L points to the rightmost node and thus, all links point to the left - If L is null then P points to the leftmost node and thus, all the links point to the right - If the list is empty then both P and
CS20: Midterm #2 May 17, 2004
NAME_
1. (7 points) Using Big Oh notation, what is the order of the following computation's time requirement? for i = 1 to n { for j = 1 to 5 Answer: O(n) sum = sum + 1 } 2. (8 points) Reduce the following Big Oh value