Assignment1 Up
Transcript of Assignment1 Up
-
7/22/2019 Assignment1 Up
1/5
The assignment carries out 20% of the total mark of the course.
Total mark of the assignment: 100.
Objectives:
1. To apply Brute Force and Greedy Techniques in problem solving.
2. Algorithm implementation using java
Problem Description:
The assignment consists of four problems described below. For eachproblem you are
required to:
1. Designand implement (using Java) an EFFICIENTalgorithm to solve the
problem using Brute Force/Greedy technique.
2. Analyze your algorithm in the best and worst cases (if needed).
3. Test the correctness of your algorithm by running the code.
Problem 1: [25 Marks]
A string is called smooth if all its letters are the same. Write an algorithm that can
change any string Sinto smooth in the smallest number of seconds, assuming that
changing each single letter takes 1 second (Assume that string S of lowercase letters).
13CSCI01I: Analysis of Algorithms
Assignment #1
Assigned: Wednesday 23/10/2013
Deadline: Thursday 31/10/2013
-
7/22/2019 Assignment1 Up
2/5
Examples
1) "geese"
Returns: 2
There are many ways you can change this S into a smooth string. One of the best ways
could be done in two steps that takes 2 seconds. You can first change all 'g's to 'e's (1
second) and produces the string "eeese".then change all 's's to 'e's (1 second) and
obtaining the smooth string "eeeee".
2) "www"
Returns: 0
This string is already smooth so no changes are needed.
3) "tattarrattat"
Returns: 6
Problem2: Greedy [25 Marks]
Suppose you were to drive from cairo to luxor. Your gas tank, when full, holds enough
gas to travel mkilometers, and you have a map that gives distancesbetween gas
stations along the route. Let d1 < d2 < .< dn be the locations of all the gas stations
along the route where di is the distance from Cairo to the gas station. You can assume
that the distance between neighboring gas stations is at mostm Km.
Your goal is to make as few gas stops as possiblealong the way.
Give the most efficient algorithmyou can to determine at which gas stations you
should stop and prove that your strategy yields an optimal solution. Be sure to give
the time complexity of your algorithm as a function of n (number of gas stops).
-
7/22/2019 Assignment1 Up
3/5
Problem3: Greedy [25 Mark]
You are given n eventswhere each takes one unit of time. Event i will provide a profit
of gi dollars(gi > 0) if started at or before time ti, where ti is an arbitrary real number.
(Note: If an event is not started by ti then there is no benefitin scheduling it at all.
All events can start as early as time 0.)
Given the most efficient algorithm you can to find a schedule that maximizes the profits.
Problem 4: [25 Mark]
You just bought a very delicious chocolate bar from a local store. This chocolate bar
consists of N squares, numbered 0 through N-1. All the squares are arranged in a
single row. There is a letter carved on each square.
You are given a String letters. The i-th character of letters denotes the letter carved on
the i-th square (both indices are 0-based).
You want to share this delicious chocolate bar with your best friend. At first, you want to
give him the whole bar, but then you remembered that your friend only likes a chocolate
bar without repeated letters. Therefore, you want to remove zero or more squares from
the beginning of the bar, and then zero or more squares from the end of the bar, in such
way that the remaining bar will contain no repeated letters.
Return the maximum possible length of the remaining chocolate bar that contains no
repeated letters.
Examples
1) "srm"
Returns: 3
You can give the whole chocolate bar as it contains no repeated letters.
-
7/22/2019 Assignment1 Up
4/5
2) "dengklek"
Returns: 6
Remove two squares from the end of the bar.
3) "haha"
Returns: 2
There are three possible ways:
Remove two squares from the beginning of the bar.
Remove two squares from the end of the bar.
Remove one square from the beginning of the bar and one square from the end
of the bar.
Deliverables
You must submit (by the specified deadline) the following:
1. A document file includes: The algorithm strategies (explain the ideas of your
algorithms), the source code (or pseudo code in case of you didnt implement),
the testing (snap shots of code runs) and analysis of each algorithm. Soft-copy
should be turned in via E-Learning and Hard-copy should be turned in to TAs.
2. A zip file for your implementations submitted via E-Learning.
-
7/22/2019 Assignment1 Up
5/5
Marking Criteria and scheme
The marking of each problemis based on the following:
1. Algorithm Efficiency.
2. Correctness.
3. Implementation.
4. Testing.
Algorithm analysis : 3 Marks
Testing : 3 Marks
Algorithm strategy : 5 Marks
Algorithm implementation: 14 Marks ( If your code is not running and the algorithm is
correct you get only 10 out of 14 mark)
Restrictions
1. Late submission is not allowed.
2. Your .java and the document files should begin with header comments containing
your name and ID. Also, make sure that you include comments throughout your code
describing the major steps in your algorithms.
Academic Honesty
Copying any piece of code from wherever or getting helpfrom someone other than
TAs or me is a plagiarism. During the discussion you have to show your supervisor that
you have a good understanding of your own work.
Plagiarism will not be tolerated. If any plagiarism case is detected, a misconduct
report will be filed to the dean and Q&V office.