DOC PREVIEW
STEVENS CS 115 - CS 115 Exam Review

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Review for first exam Format for Thursday part (80% of exam score) - Closed book, closed notes, no phones etc - Short answer questions Format for Friday part (20% of exam score) - Problem and some code will be provided online - Solve problem using DrJava - Submit via Moodle - NO OTHER APPS OPEN ON YOUR NOTEBOOK - You may use textbook and your notes on paper - But no web/email/other info/communication - Network traces may be used as evidence. - Honor code: you are responsible for reporting possible violations.The big picture Given a “problem”, design & implement “solution”. Singers in band control light and sound with wearable sensors. Laser controls auto-detect faces and dim so as to avoid eye damage. Find small “toy” problems inside real problems. Explore. E.g.: multiplexing signals over one wire from several sensors; someone suggests encoding using multiples of prime numbers. 2 Left: CO2 detector dress By Diffus, Copenhagen; Right: ITP program, NYU Above: Musical Jacket MIT Media Lab3 Topics covered on exam: through 1.4 arrays objects functions and modules graphics, sound, and image I/O arrays any program you might want to write conditionals and loops Math text I/O assignment statements primitive data typesHow to succeed on exam 1. Read carefully and think about what is being asked. 2. Do not waste time doing more than asked (e.g., “trace variables i, j”) 3. Prepare by reviewing the textbook. 4. Prepare by doing exercises and reviewing labs and homework. 5. Know these topics • declaration, expression, statement • Assignment statement • Control structures: sequence, conditional, while- and for-loop (but not break, continue) • Data type: value, literal value, operation • Primitive types: boolean, int, double • Arrays: declare, create, initialize; index - Compile-time (static) errors - Run-time errors 45 Sieve of Eratosthenes Prime. An integer > 1 whose only positive factors are 1 and itself. Ex. 2, 3, 5, 7, 11, 13, 17, 23, … Prime counting function. π(N) = # primes ≤ N. Ex. π(17) = 7.!!Sieve of Eratosthenes.  Maintain an array isPrime[] to record which integers are prime.  Repeat for i=2 to √N // make accurate info in isPrime[2..i] – if i is not still marked as prime i is is not prime since we previously found a factor – if i is marked as prime i is prime since it has no smaller factors mark all multiples of i to be non-prime6 Sieve of Eratosthenes Prime. An integer > 1 whose only positive factors are 1 and itself. Ex. 2, 3, 5, 7, 11, 13, 17, 23, … Prime counting function. π(N) = # primes ≤ N. Ex. π(25) = 9.7 Sieve of Eratosthenes: Implementation public class PrimeSieve { public static void main(String[] args) { int N = Integer.parseInt(args[0]); // initially assume all integers are prime boolean[] isPrime = new boolean[N+1]; for (int i = 2; i <= N; i++) isPrime[i] = true; // mark non-primes <= N using Sieve of Eratosthenes for (int i = 2; i*i <= N; i++) { if (isPrime[i]) { for (int j = i; i*j <= N; j++) isPrime[i*j] = false; } } // count primes int primes = 0; for (int i = 2; i <= N; i++) if (isPrime[i]) primes++; StdOut.println("The number of primes <= " + N + " is " + primes); } }8 What does this code do? or: Write code to do this. or: Trace this


View Full Document

STEVENS CS 115 - CS 115 Exam Review

Download CS 115 Exam Review
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS 115 Exam Review and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS 115 Exam Review 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?