a powerpoint about algorithm’s. what is an algorithm? a process or set of rules to be followed in...

5
A PowerPoint about Algorithm’s function binarySearch(values, target, start, end) { if (start > end) { return - 1; } //does not exist var middle = Math.floor((start + end) / 2); var value = values[middle];

Upload: meghan-reed

Post on 31-Dec-2015

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: A PowerPoint about Algorithm’s. What is an algorithm?  a process or set of rules to be followed in calculations or other problem-solving operations,

A PowerPoint about

Algorithm’s

function binarySearch(values,

target, start, end) { if (s

tart >

end) { return -1; } //does not

exist var middle =

Math.floor((start + end) / 2);

var value = values[middle];

Page 2: A PowerPoint about Algorithm’s. What is an algorithm?  a process or set of rules to be followed in calculations or other problem-solving operations,

What

is a

n

alg

ori

thm

?

a process or set of rules to be

followed in calculations or

other problem-solving

operations, especially by a

computer. "a basic algorithm for

division"

Page 3: A PowerPoint about Algorithm’s. What is an algorithm?  a process or set of rules to be followed in calculations or other problem-solving operations,

START

GET CUP

PUT TEA BAG IN

PUT MILK IN

PUT SUGAR

IN?

STIR IT

END

NO

YES

START

Put water in kettle

Boil kettle

Get a cup and put a tea bag in

Pour water in kettle

Remove tea bag

Put milk in?

Put sugar

in?

END

NOYES

YES NO

WHERE IS THE HOT WATER IN A KETTLE !!!

YOU DON’T POOR THE HOT WATER INTO THE KETTLE AGAIN

Page 4: A PowerPoint about Algorithm’s. What is an algorithm?  a process or set of rules to be followed in calculations or other problem-solving operations,

Searc

hin

g f

or

data

….

Usi

ng

Alg

ori

thm

s.

What is a linear search algorithm?

A linear search is the most basic of search algorithm

you can have. A linear search sequentially moves

through your collection (or data structure) looking for a

matching value.What is a binary search algorithm?

Binary search relies on a divide and conquer strategy

to find a value within an already-sorted collection. The

algorithm is deceptively simple. Pretend I was thinking

of a number between 1 and 100. Every guess you take,

I'll say higher or lower. The most efficient way to

discover my number is to first guess 50. Higher. 75.

Lower. 62. Higher 68.

Page 5: A PowerPoint about Algorithm’s. What is an algorithm?  a process or set of rules to be followed in calculations or other problem-solving operations,

Which is best when searching for data?

Why?

Use an example and give the good and bad points of

each search methodIf you use a linear search if your playing

a guessing game e.g

guess who if you go

throw all of the names

you will take longer

than you need to . But

if you use a binary

search it will narrow

the search down in

sections. Except the

data must be sorted

first.