Upload
meghan-reed
View
215
Download
2
Tags:
Embed Size (px)
Citation preview
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];
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"
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
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.
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.