100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

alg quiz questions and answers

Rating
-
Sold
-
Pages
4
Grade
A+
Uploaded on
23-02-2024
Written in
2023/2024

Consider the following generalization of the Activity Selection Problem: You are given a set of n activities each with a start time si, a finish time fi, and a weight wi. Design a dynamic programming algorithm to find the weight of a set of non-conflicting activities with maximum weight. - ANSWER-Formula: (Sort by finish time) A[i] = max (from activity 1 to i) { A[i - 1] max{A[x]} + wi } (x being activity whose finish time <= activity i's start time) A contiguous subsequence of a list S is a subsequence made up of consecutive elements of S. For instance, if S = {5, 15, −30, 10, −5, 40, 10} then {15, −30, 10} is a contiguous subsequence but {5, 15, 40} is not. Give a dynamic programming algorithm for the following task: You are given a list of numbers, {a1, a2, . . . , an}. You should return the contiguous subsequence of maximum sum (a subsequence of length zero has sum zero). For the preceding example, the answer would be 10, −5, 40, 10, with a sum of 55. - ANSWER-Formula: CSH[i] = max{ 0 CSH[i - 1] + Vi } You are going on a long trip. You start on the road at mile post 0. Along the way there are n hotels, at mile posts a1 < a2 < · · · < an, where each ai is measured from the starting point. The only places you are allowed to stop are at these hotels, but you can choose which of the hotels you stop at. You must stop at the final hotel (at distance an), which is your destination. You would ideally like to travel 300 miles a day, but this may not be possible (depending on the spacing of the hotels). If you travel x miles during a day, the penalty for that day is (300 − x)^2. You want to plan your trip so as to minimize the total penalty-that is, the sum, over all travel days, of the daily penalties. Give a dynamic programming algorithm to determine the optimal sequence of hotels at which to stop. - ANSWER-Formula: P[i] = min (0 <=

Show more Read less
Institution
Alg Quz
Course
Alg quz








Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Alg quz
Course
Alg quz

Document information

Uploaded on
February 23, 2024
Number of pages
4
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

  • alg quiz

Content preview

alg
quiz
Consider
the
following
generalization
of
the
Activity
Selection
Problem:
You
are
given
a
set
of
n
activities
each
with
a
start
time
si,
a
finish
time
fi,
and
a
weight
wi.
Design
a
dynamic
programming
algorithm
to
find
the
weight
of
a
set
of
non-conflicting
activities
with
maximum
weight.
-
ANSWER-Formula:
(Sort
by
finish
time)
A[i]
=
max
(from
activity
1
to
i)
{
A[i
-
1]
max{A[x]}
+
wi
}
(x
being
activity
whose
finish
time
<=
activity
i's
start
time)
A
contiguous
subsequence
of
a
list
S
is
a
subsequence
made
up
of
consecutive
elements
of
S.
For
instance,
if
S
=
{5,
15,
−30,
10,
−5,
40,
10}
then
{15,
−30,
10}
is
a
contiguous
subsequence
but
{5,
15,
40}
is
not.
Give
a
dynamic
programming
algorithm
for
the
following
task:
You
are
given
a
list
of
numbers,
{a1,
a2,
.
.
.
,
an}.
You
should
return
the
contiguous
subsequence
of
maximum
sum
(a
subsequence
of
length
zero
has
sum
zero).
For
the
preceding
example,
the
answer
would
be
10,
−5,
40,
10,
with
a
sum
of
55.
-
ANSWER-Formula:
CSH[i]
=
max{
0
CSH[i
-
1]
+
Vi
}
You
are
going
on
a
long
trip.
You
start
on
the
road
at
mile
post
0.
Along
the
way
there
are
n
hotels,
at
mile
posts
a1
<
a2
<
·
·
·
<
an,
where
each
ai
is
measured
from
the
starting
point.
The
only
places
you
are
allowed
to
stop
are
at
these
hotels,
but
you
can
choose
which
of
the
hotels
you
stop
at.
You
must
stop
at
the
final
hotel
(at
distance
an),
which
is
your
destination.
You
would
ideally
like
to
travel
300
miles
a
day,
but
this
may
not
be
possible
(depending
on
the
spacing
of
the
hotels).
If
you
travel
x
miles
during
a
day,
the
penalty
for
that
day
is
(300

x)^2.
You
want
to
plan
your
trip
so
as
to
minimize
the
total
penalty-that
is,
the
sum,
over
all
travel
days,
of
the
daily
penalties.
Give
a
dynamic
programming
algorithm
to
determine
the
optimal
sequence
of
hotels
at
which
to
stop.
-
ANSWER-Formula:
P[i]
=
min
(0
<=
k
<=
i)
{

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
AnswersCOM Chamberlain School Of Nursing
View profile
Follow You need to be logged in order to follow users or courses
Sold
1171
Member since
2 year
Number of followers
352
Documents
26304
Last sold
4 hours ago
Academic Guru

In my profile, you'll find a range of study resources, including detailed lecture notes, comprehensive summaries, and challenging practice exams. These materials are designed to help you grasp key concepts, review efficiently, and perform your best during assessments.I'm here not just to share but also to learn. Feel free to connect, ask questions, and share your insights. Together, we can make the learning journey more enriching. Browse through my materials, and I hope you find them beneficial for your academic success. Happy studying!

Read more Read less
3.6

219 reviews

5
97
4
23
3
45
2
15
1
39

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions