You are on page 1of 10

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Summer, Year: 2022), B.Sc. in CSE (Day)

PROJECT REPORT
Course Title: Algorithm Lab
Course Code: CSE-206 Section: 183-D3

Project Name: Problem Solving From UVA Online Judge (#612 & #10340)

Student Details
Name ID
Ra-Ad Arafin 183002035

Lab Date : 8 september 2022


Submission Date : 09 september 2022
Course Teacher’s Name : Jargis Ahmed

Project Report Status


Marks: ………………………………… Signature: .....................
Comments: .............................................. Date: ..............................

1
1. Introduction

In this project we solved two UVA problem UVA #612 and UVA #10340.
UVA is a renown online judge for problem solving. The #612 or DNA sorting
problem is a sorting related problem where we have to sort the DNA sequences
list based on given sorting conditions (inversion value). And #10340 or All in
All is a searching related problem which can be solved by greedy approach.
This is a problem to see if we can make a given string from another string by
deleting some/no character.

2. Problem Description
The following screen shots shows the problem description taken from UVA
website, UVA# 612:

Figure 1: UVA 612 problem description 2


UVA # 10340:

Figure 2: UVA 10340 problem description

3. Solving Approach

UVA# 612:
All the DNA sequences must sort in
ascending order of their inversion value. To
calculate the inversion value, if large value
character come first than small value
character we add inversion value by 1.
For example,
Figure 3: Inversion value calculation method
AB has inversion value of 0 ; because A<B
BA has inversion value of 1; because B > A
So we will take one DNA sequence at a time and calculate the inversion value.
Then we will make a list of DNA objects. The DNA object will have it’s
sequence and inversion value inside. After that we will sort the DNA list based
on inversion value (ascending order) by java comparable interface and
collections. This sorted list of DNA is our expected output.

3
The class DNA implements Comparable interface and create a
calculateInversion() method to calculate the inversion for its DNA sequence.
The override method compareTo() of Comparable interface help to sort the list
based on inversion value.

UVA# 10340
In this problem we have given two string s and t. We have to find if we can
make s from t by deleting or by not deleting any characters.
For example,
s=«rahad» and t=«zrlashttagd»
Now if we remove «zlshttg» from t and concatinate the remainning charecter we
will get «rahad» as in s. In simple, if all the charecters of s are present in t in
order we can make s from t.
We will start a loop from 0 to t.length() with two index i=0,j=0. If s[i]==t[j] we
will increment the value of i by 1. If all charecter of s are found in t the i index
will be i==s.length and we break the loop. If i != s.length even after loop is
completed, we can say s can’t be found in t.
Let’s we have s= “GUB” and t= “GetyoUrBook” we can find the solution by the
following steps.

Step 1:
G U B

i
G e t y o U r B o o k

j s[i]==t[j] ; so i++ and j++

Step 2:
G U B

i
G e t y o U r B o o k

s[i]!=t[j] ; j++
j

Step 3:
4
G U B

i
G e t y o U r B o o k

s[i]!=t[j] ; j++
j
Step 4:
G U B

i
G e t y o U r B o o k

j s[i]!=t[j] ; j++

Step 5:
G U B

i
G e t y o U r B o o k

s[i]!=t[j] ; j++
j
Step 6:
G U B

i
G e t y o U r B o o k

s[i]==t[j] ; so i++ and j++ j


Step 7:
G U B

i
G e t y o U r B o o k

s[i]!=t[j] ; j++
j
5
Step 8:
G U B

i
G e t y o U r B o o k

s[i]==t[j] ;so i++ and j++


j
All the character of s are in t so the loop will terminate here. We can check if
i== s.length(), means I reached at the end of string by matching with t. This is a
greedy searching approach because we’re searching in order the s has the
characters.

4. Java code
UVA# 612

6
7
Input/ Output:

8
UVA# 1034

9
Input/ Output:

5. Discussion

We studied and analyzed two UVA online judge problems (UVA #612 & UVA
#10340). We also discussed the solving approaches of these problems and
implemented those approach in java. The java code was verified by input and
expected output vs original output. The output was as expected. The greedy
approach in #10340 problem is only able to get correct solution if the character
is in order. Like s= “ABC” t= “CBA” all character in s are present in t but the
result will be No because it’s not in order.

10

You might also like