










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Various decrease-and-conquer algorithms, including binary search, exponentiation by squaring, russian peasant multiplication, fake-coin puzzle, josephus problem, euclid's algorithm, and selection problem. These algorithms reduce the instance size by a constant factor and are used to solve problems such as finding the median, computing exponentiation, and detecting the fake coin. The document also covers variable-size-decrease algorithms and their applications.
Typology: Study notes
1 / 18
This page cannot be seen from the preview
Don't miss anything!











Oct
In
this
variation
of
decrease
and
conquer,
instance
size
is
reduced
by
the
same
factor
(typically,
Examples:• Binary
search
and
the
method
of
bisection
by
squaring
à la
russe
(Russian
peasant
method)
coin
puzzle
problem
The
problem:
Compute
the
product
of
two
positive
integers
Can
be
solved
by
a
decrease
‐by
‐half
algorithm
based
on
the
following
formulas.
For odd values of
n
:
n
m
=
m + m
if
n
1
and
m
if
n
= 1
n
For even values of
n
:
n
m
=
m
n 2
Example
of
Russian
Peasant
Multiplication
Compute
20
26
n
m
20
26
10
52
5
104
104
2
208
1
416
416520
Note: Method reduces to adding
m
’s values corresponding to odd
n
’s.
There
are
n
identical
looking
coins,
one
of
which
is
fake. The
fake
coin
is
lighter
than
the
real
coins,
real
coins
all
weigh
the
same.
There
is
a
balance
scale,
which
can
tell
whether
two
sets
of
coins
weigh
the
same,
or
which
of
the
two
sets
is
heavier. Design
an
efficient
algorithm
for
detecting
the
fake
coin.
Divide
coins
into
two
piles
of
n
coins
Heavier
pile
is
all
real
coins
Repeat
for
lighter
pile
(problem
of
n/
size)
Number
of
weighing:
W(n)
n
W(n)
log
2
n
Can
we
do
better
by
increasing
the
decrease
factor?
if
n
is
even
(n
2k):
J(2k)
2J(k)
relates
Josephus’ position
in
original
circle
to
his
position
in
next
smaller
circle
if
n
is
odd
(n
2k+1):
J(2k+1)
2J(k)
base
case:
To
determine
J(n),
we
need
a
closed
form
solution
(a
bit
tricky)
Most
elegant
solution:
J(n)
one
bit
cyclic
left
shift
of
n
Examples:
2
2
2
2
Euclid’s
algorithm
is
based
on
repeated
application
of
equality
gcd(
m,
n
gcd(
n,
m
mod
n
Ex.:
gcd(80,44)
gcd(44,36)
gcd(36,
gcd(12,0)
One
can
prove
that
the
size,
measured
by
the
second
number,
decreases
at
least
by
half
after
two
consecutive
iterations.
Hence,
T(
n
)^
∈
O(log
n
)
Euclid’s
Algorithm
Find
the
k
th
smallest
element
in
a
list
of
n
numbers
k
or
k
n
usual,
smallest/largest
value
problem
median
k
n/
Example:
median =
The
median
is
used
in
statistics
as
a
measure
of
an
average
value
of
a
sample.
It
is
a
better
(more
robust)
indicator
than
the
mean,
which
is
used
for
the
same
purpose.
The
sorting
‐based
algorithm:
Sort
and
return
the
k
‐th
element
Efficiency
(if
sorted
by
mergesort):
Θ
( n
log
n
)
A
faster
algorithm
is
based
on
using
the
quicksort
‐like
partition
of
the
list.
Let
s
be
a
split
position
obtained
by
a
partition:
Assuming
that
the
list
is
indexed
from
1
to
n
:
If
s
=
k
,^
the
problem
is
solved;
if
s
>
k
,^
look
for
the
k
‐ th
smallest
elem.
in
the
left
part;
if
s
<
k
,^
look
for
the
(
k
‐ s
)‐
th
smallest
elem.
in
the
right
part.
s
all are
≤
A[
s
]^
all are
≥
A[
s
]
Example:
4
1
10
9
7
12
8
2
15
Here:
n
=
9,
k
=
⎡
9/
⎤
=
5
4
1
10
9
7
12
8
2
15
4
1
2
9
7
12
8
10
15
2
1
4
9
7
12
8
10
15
‐‐‐
s
=
<
k
=
9
7
12
8
10
15
9
7
8
12
10
15
8
7
9
12
10
15
‐‐‐
s
=
k
=
8
7
7
8
‐‐‐
s
=
k
=
Solution:
median
is
8