Docsity

Random Access Machine - Algorithm - Lecture Slides, Slides of Algorithms and Programming

Partial preview of the text

Download Random Access Machine - Algorithm - Lecture Slides and more Slides Algorithms and Programming in PDF only on Docsity!

Random Access Machine^ •^ A RAM is an idealized machine with aninfinitely large random-access memory.^ •^ Instructions are executed one-by-one (thereis no parallelism).^ •^ Each instruction involves performing somebasic operation on two values in themachine’s memory

Basic RAM Operations^ Basic operations include^ •^ assigning a value to a variable,^ •^ computing any basic arithmetic operation (+, -,^ ×

and division) on integer values of any size • performing any comparison or booleanoperations • accessing an element of an array (e.g.

A[^10

]) Docsity.com^ Algorithms – p. 25

RAM Model^ Basic operations in C++ that are assumed totake up same amount of CPU time.^ •^ x

=^ y; • z =^ a

  • b;

z^

= a^

-^ b; -^ z^ =

a^ * b;

z^

= a^

/^ b;

-^ z^ =

w[10];

-^ (x^

<=^ y)

Example: 2-dimension maxima^ Let us do an example that illustrates how weanalyze algorithms.^ •^ Suppose you want to buy a car.^ •^ You want the pick the fastest car.^ •^ But fast cars are expensive; you want thecheapest.^ •^ You cannot decide which is more important:speed or price.

Example: 2-dimension maxima^ Here is how we might model this as a formalproblem.^ •^ Let a point

p^ in 2-dimensional space be given by its integer coordinates,

p^ = (

p.x, p.y

-^ A point

p^ is said to be

dominated

by point

q^ if

p.x^ ≤

q.x^ and

p.y^ ≤

q.y.

Example: 2-dimension maxima^ •^ Given a set of

n^ points,

P^ =^ {

p, p^12

,... , p

}^ inn

2-space a point is said to be

maximal

if it is

not dominated by any other point in

P.

Example: 2-dimension maxima^ •^ High

y^ value means a cheap car and low

y

means expensive car. • Think of

y^ as the money left in your pocket after you have paid for the car. • Maximal points correspond to the fastest andcheapest cars.

Example: 2-dimension maxima^ 2-dimensional Maxima:^ •^ Given a set of points

P^ =^ {

p, p^12

,... , p

}^ inn

2-space, • output the set of maximal points of

P,

-^ i.e., those points

psuch thati^

pis noti^

dominated by any other point of

P.

Example: 2-dimension maxima^ •^ Our description of the problem is at a fairlymathematical level.^ •^ We have intentionally not discussed how thepoints are represented.^ •^ We have not discussed any input or outputformats.^ •^ We have avoided programming and othersoftware issues.