The RAM Computation Model

Similar documents
Cost of Your Programs

Binary Search and Worst-Case Analysis

Binary Search and Worst-Case Analysis

Recursion: The Beginning

k-selection Yufei Tao Department of Computer Science and Engineering Chinese University of Hong Kong

CSCI 3130: Formal Languages and Automata Theory Lecture 16 The Chinese University of Hong Kong, Fall 2010

Course Learning Outcomes for Unit I. Reading Assignment. Unit Lesson. UNIT I STUDY GUIDE Number Theory and the Real Number System

Dr. Relja Vulanovic Professor of Mathematics Kent State University at Stark c 2008

Recursion: The Beginning

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

The eighth scene in a series of articles on elementary mathematics. written by Eugene Maier designed and illustrated by Tyson Smith. equals me.

Linked Lists, Stacks, and Queues

AXIOMS FOR THE INTEGERS

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Constructing Algorithms and Pseudocoding This document was originally developed by Professor John P. Russo

Modular Arithmetic. Marizza Bailey. December 14, 2015

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

Encoding and Encrypting Information

1. Let n be a positive number. a. When we divide a decimal number, n, by 10, how are the numeral and the quotient related?

Bulgarian Math Olympiads with a Challenge Twist

Computer Architecture

Learning By Sample Series. Learning By Sample - T-SQL : Part 3

EECS 3101: Introduction to the Design and Analysis of Algorithms Instructor: Suprakash Datta (datta[at]cse.yorku.ca) ext 77875

Senior Math Circles Cryptography and Number Theory Week 1

Hashing. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong

i W E I R D U T O P I A i

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Sets MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Sets Fall / 31

Computer Architecture

Lesson 4.02: Operations with Radicals

Discrete Structures Lecture The Basics of Counting

A.1 Numbers, Sets and Arithmetic

Data Handing in Python

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #33 Pointer Arithmetic

QUICK EXCEL TUTORIAL. The Very Basics

Lecture Notes on Liveness Analysis

UNIT-II NUMBER THEORY

Comp 151. More on Arithmetic and intro to Objects

36 Modular Arithmetic

Slides for Faculty Oxford University Press All rights reserved.

LECTURE 9 Data Structures: A systematic way of organizing and accessing data. --No single data structure works well for ALL purposes.

GAP CLOSING. Integers. Intermediate / Senior Facilitator s Guide

Programming, Data Structures and Algorithms Prof. Hema Murthy Department of Computer Science and Engineering Indian Institute of Technology, Madras

Subset sum problem and dynamic programming

Cardinality of Sets MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Cardinality of Sets Fall / 15

Data Structures Lecture 8

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions

GAP CLOSING. Grade 9. Facilitator s Guide

Theory and Algorithms Introduction: insertion sort, merge sort

OPERATING SYSTEMS. G.C.E. Advanced Level ICT

Introduction to Sets and Logic (MATH 1190)

Lecture Notes on Contracts

COMPETENCY 1.0 UNDERSTAND THE STRUCTURE OF THE BASE TEN NUMERATION SYSTEM AND NUMBER THEORY

Pick any positive integer. If the integer is even, divide it by 2. If it is odd,

(2 1) What does evaluate to? What does evaluate to? What does evaluate to?

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Topic C. Communicating the Precision of Measured Numbers

What s the Difference?

Civil Engineering Computation

Intro to semantics; Small-step semantics Lecture 1 Tuesday, January 29, 2013

3.1 Constructions with sets

Adding Integers with the Same Sign

CSE 410 Computer Systems. Hal Perkins Spring 2010 Lecture 12 More About Caches

6th Bay Area Mathematical Olympiad

2.4 Choose method names carefully

More Complicated Recursion CMPSC 122

CS101 Lecture 25: The Machinery of Computation: Computer Architecture. John Magee 29 July 2013 Some material copyright Jones and Bartlett

6.001 Notes: Section 4.1

The mathematics you have learned about so

(Refer Slide Time 6:48)

Algebraic Specifications

in this web service Cambridge University Press

Midterm I - Solution CS164, Spring 2014

Lattice Tutorial Version 1.0

Intermediate Mathematics League of Eastern Massachusetts

C++ Programming Language Lecture 2 Problem Analysis and Solution Representation

Week - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program.

Chapter 1: Building Blocks of Programming

p x i 1 i n x, y, z = 2 x 3 y 5 z

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

(Refer Slide Time 5:19)

With IBM BPM 8.5.5, the features needed to express both BPM solutions and case management oriented solutions comes together in one offering.

Introduction to Counting, Some Basic Principles

Unit 7 Number System and Bases. 7.1 Number System. 7.2 Binary Numbers. 7.3 Adding and Subtracting Binary Numbers. 7.4 Multiplying Binary Numbers

Rational Numbers and the Coordinate Plane

C++ Programming Lecture 1 Software Engineering Group

MAT 003 Brian Killough s Instructor Notes Saint Leo University

CS150 Introduction to Computer Science 1. What is CS150? Who Are We? CS150 is a programming course You will learn

Worksheet - Storing Data

1 Elementary number theory

0.1 Welcome. 0.2 Insertion sort. Jessica Su (some portions copied from CLRS)

Algorithm Analysis. This is based on Chapter 4 of the text.

Outline. Program development cycle. Algorithms development and representation. Examples.

3.5 Indeterminate Forms. Consider the function given by the rule f(x) = Whenever direct substitution into lim x c f(x) yields a 0 0

Chapter 1: Foundations for Algebra

Problem Set 4: Streams and Lazy Evaluation

2.2 THE MARIE Instruction Set Architecture

Assembly Language Manual for the STACK Computer

14.1 Encoding for different models of computation

Transcription:

Department of Computer Science and Engineering Chinese University of Hong Kong

This is not a programming course. Take-away message 1 from this course Programming is the last step in software development, which occurs only after the algorithms are clear. Take-away message 2 No programming knowledge is needed to study algorithms, which is the core of computer science: a beautiful branch of mathematics. Many people believe that this branch holds the future of mankind.

In mathematics (and hence, computer science) everything including every term and symbol must be rigorous. Computer science is a subject where we 1 first define a computation model, which is a simple yet accurate abstraction of a computing machine; 2 then slowly build up a theory in this model from scratch.

The Random Access Machine (RAM) model A machine has a CPU and a memory. Memory An infinite sequence of cells, each of which contains the same number w of bits. Every cell has an address: the first cell of memory has address 1, the second cell 2, and so on.

The Random Access Machine (RAM) model CPU Contains a fixed number 32 in this course of registers, each of which has w bits (i.e., same as a memory cell). w bits w bits... 32 registers 1 2 3... address

The Random Access Machine (RAM) model CPU Can do the following atomic operations: 1. (Register (Re-)Initialization) Set a register to a fixed value (e.g., 0, 1, 100, etc.), or to the contents of another register.

The Random Access Machine (RAM) model CPU Can do the following 4 atomic operations: 2. (Arithmetic) Take the integers a, b stored in two registers, calculate one of the following and store the result in a register: a + b, a b, a b, and a/b. Note: a/b is integer division, which returns an integer. For example, 6/3 = 2 and 5/3 = 1.

The Random Access Machine (RAM) model CPU Can do the following 4 atomic operations: 3. (Comparison/Branching) Take the integers a, b stored in two registers, compare them, and learn which of the following is true: a < b, a = b, a > b.

The Random Access Machine (RAM) model CPU Can do the following 4 atomic operations: 4. (Memory Access) Take a memory address A currently stored in a register. Do one of the following: Read the contents of the memory cell with address A into another register (overwriting the bits there). Write the contents of another register into the memory cell with address A (overwriting the bits there).

The Random Access Machine (RAM) model Algorithms and Their Cost An algorithm is a sequence of atomic operations. Its cost (also called its running time, or simply, time) is the length of the sequence, namely, the number of atomic operations.

The Random Access Machine (RAM) model A word is a sequence of w bits, where w is called the word length. In other words, each memory cell and CPU register store a word. Unless otherwise stated, you do not need to pay attention to the value of w in this course.

Example 1 Problem Suppose that an integer of n 1 has already been stored at the memory cell of address 1. We want to calculate 1 + 2 +... + n (the sum can be stored anywhere, e.g., in a register).

Example 1 Algorithm Set register b to 0, c to 1, and d to 1. Load n into register a. Repeat the following until c > a: Calculate b + c, and store the result in b. Calculate c + d, and store the result in c (effectively increasing c by 1). Cost of the algorithm = 3n + 4 Think: which atomic operations are performed? We have described the algorithm essentially in English words. The next slide shows a different way to describe the same algorithm.

Example 1 Algorithm 1. load n into register a 2. register b 0, c 1, d 1 3. repeat 4. b b + c 5. c c + d 6. until c > a 7. return b The above is called pseudocode. As you can see, we are not restricting ourselves to any particular programming languages. The description is in a free form, mixing English words and programming-like statements as we wish, as long as it serves the purpose of conveying without ambiguity how our algorithm runs.

Example 2 Same problem as before. Problem Suppose that an integer of n 1 has already been stored at the memory cell of address 1. We want to calculate 1 + 2 +... + n (the sum can be stored anywhere, e.g., in a register). But this time we will give a faster algorithm.

Example 2 Algorithm Set register a to 1, and b to 2. Load n into register c. Then: Set a to a + c (note: a now equals n + 1). Set a to a c (now equals n(n + 1)). Set a to a/b (now equals n(n + 1)/2). Cost of the algorithm = 6 This is significantly faster than the previous algorithm when n is large. In particular, the time of the previous algorithm increases linearly with n, while the time of the above one remains constant.

Although we have not talked about how to implement our algorithms into actual programs, now it should be straightforward for you (who must have learned a programming language prior to taking this course) to do so. Indeed, to design algorithms, a real computer science person never has a programming language in mind. Instead, s/he focuses on the simple abstraction of the RAM model, knowing that once an algorithm is out, implementing it into an actual program is merely a matter of translation and experience.