CS61B Midterm Review Winston Liaw and Amir Kamil.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

CSE 351 Midterm Review. Your midterm is next Wednesday Study past midterms (link on the website) Point of emphasis: Registers are not memory Registers.
Analysis of Algorithms
Linked Lists
Recitation on analysis of algorithms. runtimeof MergeSort /** Sort b[h..k]. */ public static void mS(Comparable[] b, int h, int k) { if (h >= k) return;
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
First project Create a JApplet with 3 textfields (2 for input and one for the answer), appropriate labels, and buttons for plus, minus and times. Your.
COMP3221: Microprocessors and Embedded Systems--Lecture 4 1 COMP3221: Microprocessors and Embedded Systems Lecture 4: Number Systems (II)
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III
February 4, 2003 CSCE 212 Computer Architecture Lecture 3 Representing Integers.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Unsigned and Signed Numbers. Hexadecimal Number 217A 16 Position Digits A Value = 2x x x16 + Ax1 = 2x x x16.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Introduction to trees.
Data Representation in Computers. Data Representation in Computers/Session 3 / 2 of 33 Number systems  The additive approach – Number earlier consisted.
Binary Representation and Computer Arithmetic
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
CSE 373 Data Structures and Algorithms Lecture 4: Asymptotic Analysis II / Math Review.
Binary numbers and arithmetic. ADDITION Addition (decimal)
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
{ Lesson 5.05 Module 5 Activity.  Solve the equation  Solve the equation –x + 3 > 7. The first step in solving this inequality is to “isolate” the variable.
Carnegie Mellon 1 This Week: Integers Integers  Representation: unsigned and signed  Conversion, casting  Expanding, truncating  Addition, negation,
CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a lgorithms.
Lecture 8. How to Form Recursive relations 1. Recap Asymptotic analysis helps to highlight the order of growth of functions to compare algorithms Common.
Computer Science 111 Fundamentals of Programming I Number Systems.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
Recitation 11 Analysis of Algorithms and inductive proofs 1.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Operations on Bits Arithmetic Operations Logic Operations
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
1 Floating Point Operations - Part II. Multiplication Do unsigned multiplication on the mantissas including the hidden bits Do unsigned multiplication.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
Analysis of Algorithms Algorithm Input Output An algorithm is a step-by-step procedure for solving a problem in a finite amount of time.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Recitation on analysis of algorithms. Formal definition of O(n) We give a formal definition and show how it is used: f(n) is O(g(n)) iff There is a positive.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Information Representation: Negative Integer Representation.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Week 5 - Wednesday.  What did we talk about last time?  Recursion  Definitions: base case, recursive case  Recursive methods in Java.
CSE 373: Data Structures and Algorithms Lecture 4: Math Review/Asymptotic Analysis II 1.
1. What is it? It is a queue that access elements according to their importance value. Eg. A person with broken back should be treated before a person.
Numbers in Computers.
1 Signed Arithmetic Logical Operations Ellen Spertus MCS 111 October 1, 2002.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Introduction to Algorithm Analysis Concepts Fundamental Data Structures and Algorithms Aleks Nanevski and Margaret Reid-Miller January 15, 2003.
Practicum 1: - Persistent vs. destructive lists - Java interfaces Fundamental Data Structures and Algorithms Margaret Reid-Miller January 22, 2004.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
Lecture 4: Representing Negative Numbers CS 2011 Spring 2016, Dr. Rozier.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Binary Arithmetic James A. Rome Tennessee Governor's Academy August 2010.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
APS105 Malloc and 2D Arrays (text Ch6.4, Ch10.2).
Cosc 2150: Computer Organization
Bitwise Operations C includes operators that permit working with the bit-level representation of a value. You can: - shift the bits of a value to the left.
Week 4 - Friday CS221.
This Week: Integers Integers Summary
Instructor: David Ferry
COMP3221: Microprocessors and Embedded Systems
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Comp Integers Spring 2015 Topics Numeric Encodings
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

CS61B Midterm Review Winston Liaw and Amir Kamil

Midterm Review2 Agenda 1. Static vs. Dynamic 2. Box and pointer diagrams 3. Code Questions and examples 4. Bit representation 5. Algorithmic Analysis 6. Access rights 7. Quickie questions

Midterm Review3 Static vs. Dynamic What happens? Assume we have defined: Homer h = new Homer(); Bart b = new Bart(); Homer h1 = b; h1.talk2(); Answer: Homer, Bart: dude

Midterm Review4 Static vs. Dynamic cont. What happens? Assume the same definitions Bart b1 = b; b1.talk2(); Cartoon c1 = h; ((Homer)c1).talk4(); Answer: Homer, Bart: dude Answer: Homer, Homer: doh!

Midterm Review5 Static vs. Dynamic cont. What happens? Cartoon c2 = b; ((Bart)c2).whoa(); Lumpy l2 = b; ((Homer)l2).talk4(); Answer: dude Answer: Bart: dude

Midterm Review6 Static vs. Dynamic cont. For calls with an object of interest (i.e. h.f()), static methods are called based on static type, non-static methods are based on dynamic type For calls involving “this”, things get a little trickier. Static calls “stay” in the same class, dynamic calls are based on the dynamic set.

Midterm Review7 Box and Pointer diagrams Draw the diagrams that result from this code: int [] x = new int[3]; int [] y = new int[0]; int [][] z = new int[3][2];

Midterm Review8 Box and Pointer diagrams Draw the diagrams that result from this code: int [] x = new int[3]; int [] y = new int[0]; int [][] z = new int[3][2]; x y z

Midterm Review9 Box and Pointer diagrams cont. Modify the box and pointer diagram according to this code: z[1] = z[2];

Midterm Review10 Box and Pointer diagrams cont. Modify the box and pointer diagram according to this code: z[1] = z[2]; z

Midterm Review11 Coding Question Finish this method: /* Given an IntList, it will reverse it destructively and return the new list */ public IntList reverse(IntList l) { … }

Midterm Review12 Coding Question Solution public IntList reverse(IntList l) { IntList prev = null; IntList next = l.tail; while (l != null) { next = l.tail; l.tail = prev; prev = l; l = next; } return prev; //once we are done reversing all the pointers //we need to set l's head to the new head }

Midterm Review13 Bit Representation What is the bit representation for: byte b = 15; What is this value as a char? What about as a byte? Answer: Answer: 183 Answer: -73

Midterm Review14 Bit Representation Two’s complement If the Most Significant Bit (MSB) is 0, then treat the remaining bits as normal (as a positive number). If the MSB is 1, flip the remaining bits, add 1, and that is your negative value. Remember, two’s complement only applies to signed values. For an unsigned integer, for instance, treat it as “normal.”

Midterm Review15 Modular Arithmetic For modular arithmetic: Find out how many times your divisor can divide into your dividend. Remember, the remainder must be positive If the remainder is greater than the range of your values (byte can have values btw –128 and 127 for instance) then loop value around

Midterm Review16 Another Coding Question Finish these methods: IntList pqueue; /* removes the node with smallest value */ public int remove() { … } /* inserts the value into pqueue */ public void insert(int k) { … }

Midterm Review17 Another Coding Question Solution public int remove() { int x = pqueue.head; pqueue = pqueue.tail; return x; }

Midterm Review18 Another Coding Question Solution cont. public void insert(int k) { IntList temp = pqueue; IntList prev = null; while (temp != null) { if (k < temp.head) { if (prev != null) { prev.tail = new IntList(k, temp); } else { pqueue = new IntList(k, pqueue); } return; } else { prev = temp; temp = temp.tail; }

Midterm Review19 Algorithmic Analysis Definition of Big-Oh O(g(n)) = {f(n) : there exist positive constants c and n 0 such that 0 = n 0 Definition of Big-Omega  (g(n)) = {f(n) : there exist positive constants c and n 0 such that 0 = n 0

Midterm Review20 Algorithmic Analysis One method takes O(n 2 ), while another takes O(n lg(n)). The O(n lg(n)) method is always preferred. True or false?

Midterm Review21 Algorithmic Analysis What are the running times (Big-Oh, Big- Omega, Big-Theta) for this code? for (int i = k; i < z; i++) { for (int j = 0; j < z; j++) { //some lg (n) code here } Answer: all are (z-k)(z)lg(n)

Midterm Review22 Access rights If you override a method in a child class, Java allows you to change the access rights to be less restrictive Ex. – Parent’s method is protected Child’s method is public Refer to page 113 in Programming into Java for more details

Midterm Review23 Quickies What class has no superclass? Why would you want to pick an array over a list?