DOC PREVIEW
UVA CS 101 - Guest Speaker - Cryptography

This preview shows page 1-2-3-18-19-37-38-39 out of 39 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 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 39 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 39 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 39 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 39 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 39 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 39 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 39 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Guest Speaker - CryptographyFinal Exam ReviewBuilt-In DatatypesVariablesBuilt-in Data TypesMath LibraryType ConversionConditionals and LoopsControl Flow SummaryNesting Conditionals and LoopsMonte Carlo SimulationSingle-Dimensional ArraysArrays in JavaArray Layout in MemoryArray LengthAuto-incrementMultidimensional ArraysTwo Dimensional Arrays in JavaMemory Layout 2-D ArraysRagged ArraysFunctions/Static MethodsComponents of a FunctionFlow Control – Call by ValueThings to Remember About FunctionsRecursionSlide 26How-To’s on Writing Recursive FunctionsObjectsSlide 29Things to Remember About ObjectsObjects are Reference TypesPrinciples of Object Oriented ProgrammingSummary of Classes (“Charge” Class Discussed in the Textbook)Data StructuresSlide 35GenericsAutoboxingLists Can Be Organized in Different WaysSlide 39Guest Speaker - CryptographyWednesday (Apr. 22) – Prof. abhi shelatFinal Exam ReviewCS101: Introduction to Computer Science • Slides adapted from Sedgewick and Wayne • Copyright © 2007 • http://www.cs.Princeton.EDU/IntroCSBuilt-In DatatypesVariablesA variable has three parts:1. Name (e.g., “x”)2. Type (e.g., int, double, String)3. ValueHow does a variable get a value?–Can be initialized in the programE.g., int x = 10–Can be computed when the program is runningE.g., x = y + z;5Built-in Data TypesData type. A set of values and operations defined on those values.add, subtract, multiply, divide3.14156.022e23floating point numbersdoubleadd, subtract, multiply, divide1712345integersintand, or, nottruefalsetruth valuesbooleansequences of characterscharactersset of values operationsliteral valuestypecompare'A''@'charStringconcatenate"Hello World""CS is fun"6Math Library7Type ConversionType conversion. Convert from one type of data to another.Automatic: no loss of precision; or with strings.Explicit: cast; or method.Conditionals and Loops9Control Flow SummaryControl flow.Sequence of statements that are actually executed in a program.Conditionals and loops: enables us to choreograph the control flow.Straight-lineprogramsAll statements areexecuted in the order given.ConditionalsCertain statements areexecuted depending on thevalues of certain variables.ifif-elseLoopsCertain statements areexecuted repeatedly untilcertain conditions are met.whilefordo-whileControl Flow Description ExamplesNesting Conditionals and LoopsNest conditionals within conditionals.Nest loops within loops.Nest conditionals within loops within loops.10Monte Carlo SimulationGeneral Code Structure:class MonteCarloSimulation {for(i=0; i<num_trials; i++) {Perform one independent trial {Generate random input;Deterministic computation on that input;}}Compute results aggregated over all trials;}11Single-Dimensional Arrays13Arrays in JavaJava has special language support for arrays.To make an array: declare, create, and initialize it.To access element i of array named a, use a[i]. Array indices start at 0.Compact alternative. Declare, create, and initialize in one statement.Default initialization: all numbers automatically set to zero.int N = 10; double[] a; // declare the arraya = new double[N]; // create the arrayfor (int i = 0; i < N; i++) // initialize the array a[i] = 0.0; // all to 0.0int N = 10;double[] a = new double[N]; // declare, create, initArray Layout in MemoryMemory is split into equal sized units known as “addresses”. (Address Space)Arrays occupy consecutive addresses in this linear space: int[] a = {5, 6, 10};Key Point: Name of the array indirectly references its starting address.int[] b = new int[3]; b=a;//b is an alias to a. REFERENCE TYPE140 1 2 . . . N-2 N-1 0 1 2 3 4 5 N-2 N-1 a[0] a[1] a[2] 5 6 10 AddressesArray LengthThe array length can be obtained using the .length operatorfor(i=0; i< myArray.length; i++)The array length cannot be changed after memory allocationCan use arraylists to get around this limitation15Auto-incrementAuto-increment and auto-decrement operators used with arrays.++i means “add one to i’s value and use the updated value”i++ means “use i’s value now and then add one to the old value”Can use on line by itself as a single statement–In which case they do exactly the same thing!Differences between the auto-increment operators are important when used in expressions: y = 0; x = y++; y = 0; z = ++y; 16Y=0; x = y; y = y+1;Y=0; y = y+1; z = y;Multidimensional Arrays18Two Dimensional Arrays in JavaArray access. Use a[i][j] to access element in row i and column j. Zero-based indexing. Row and column indices start at 0.double[][] a = new double[10][3];for (int i = 0; i < 10; i++) { for (int j = 0; j < 3; j++) { a[i][j] = 0.0; }}Declaring and Initializing a 10-by-3 ArrayMemory Layout 2-D Arrays19Rowarray[0]array[1]array[2]array[3]array[0][0]array[1][2]Ragged ArraysRow lengths can be non-uniformCan use .lengthint[][] a = ...;for (int rows=0; rows < a.length; rows++) {for (int cols=0; cols < a[rows].length; cols++) System.out.print(" " + a[rows][cols]);System.out.println("");}20Number of rowsNumber of columns for a given rowFunctions/Static MethodsComponents of a Function23Flow Control – Call by ValueCall by reference – For reference types (arrays, objects)Things to Remember About FunctionsFunctions can be overloadedDifferent argument typesDifferent number of argumentsDifferent return value is NOT overloadingScoping Rules for functions and conditional and loop code-blocksRecursion26RecursionWhat is recursion? When one function calls itself directly or indirectly.Gcd. Find largest integer d that evenly divides into p and q.base casereduction steppublic static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q);}base casereduction step,converges to base case27How-To’s on Writing Recursive FunctionsBase Case: You must check if we’ve reached the base case before doing another level of recursion! Make Progress Towards Base Case:Your recursive calls must be on a smaller or simpler input. Eventually this must reach the base case (and not miss it).Multiple recursive calls:Sometimes more than one recursive call.–H-Tree, Towers of HanoiAre their return values chosen, combined?Objects29ObjectsObject. An entity that can take


View Full Document

UVA CS 101 - Guest Speaker - Cryptography

Documents in this Course
Classes

Classes

53 pages

Recursion

Recursion

15 pages

Iteration

Iteration

88 pages

PLEDGED

PLEDGED

6 pages

Objects

Objects

33 pages

PLEDGED

PLEDGED

11 pages

CS 101

CS 101

42 pages

Classes

Classes

83 pages

Iteration

Iteration

92 pages

Classes

Classes

186 pages

Classes

Classes

208 pages

Hardware

Hardware

21 pages

Arrays

Arrays

70 pages

Load more
Download Guest Speaker - Cryptography
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 Guest Speaker - Cryptography 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 Guest Speaker - Cryptography 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?