You are on page 1of 4

Tasks

[total: 100 points]

A. How similar are two DNA sequences?


[25 points]
1. Create a new IntelliJ IDEA project, name
it DNAHammingDistance.

For Lab 01, you wrote a simple Java program to generate a


string representing a random DNA sequence.
To continue with Problem Set 01, write a new file
named  RandomDNA.java , where you should reorganize your Lab
01 Java code, so that it provides a function
named  generateDNAstring() , which could be called from
a  main()  test client code thus:

import java.util.Random;
 
public class RandomDNA {
 
    public String generateDNAstring(int n) {
        String lDNA = "";
        Random lRandomizer = new Random();
 
//         place your Lab 01 implementation here
 
        return lDNA;
    }
 
    // a test client
    public static void main(String[] argv) {
        RandomDNA myRandomDNA = new RandomDNA();
        String myDNAstring = "";
        for (int i = 10; i<=1000; i = i * 10) {
            System.out.println("");
            myDNAstring = myRandomDNA.generateDNAstring(i);
            System.out.println("a DNA sequence " + i + " characters long: "
myDNAstring);
        }
        System.out.print(myDNAstring);
    }
 
} // end of class RandomDNA

2. For this Problem Set task, you need to expand on the above
code, so that it generates two random DNA sequences (of the
same length) and computes their distance (their Hamming
distance, defined below).
3. for C343 purposes, the Hamming distance between two strings
of equal length is defined as:
the number of positions at which the corresponding symbols
are different;
for example, the Hamming distance between "ATC" and "ATG"
is 1.

4. In the IntelliJ IDEA project, include the file


named  RandomDNA.java , completed from the starting Java
program code shown above.
Create a new class in a Java file
named  DNAHammingDistance.java . This class needs to:
a. have a method that takes two Strings (two DNA
sequences) as the inputs, as generated by the
above  generateDNAstring()  method.
b. compute the Hamming distance between the strings,
c. and return the Hamming distance between the
strings.

Both  DNAHammingDistance.java  and  RandomDNA.java  need to be


included in your IntelliJ IDEA project for Problem Set 01 Task A.
Within the  main()  method of your program, instantiate and test
both classes, and prints out the results. Your code needs to
make at least three different comparisons, to find the Hamming
distance between three different pairs of different randomly-
generated DNA strings; strings have to be each at least 100
characters in length.

5. Submit all your files to IU GitHub under  /ps/ps01/ .

B. Time Complexity analysis


[30 points]

1. Before working on Problem Set 01 Task B, you need


to read  Chapter 2: Algorithm Analysis  in the course textbook.

2. For the following code fragments, determine Θ in the average


case.
[5 points each]
Note:
You need to motivate your answers, i.e. clearly explain how you
determined Θ for each one of these code fragments.

a = b + c;
d = a + e;

2
sum = 0;
for (i=0; i<3; i++)
    for (j=0; j<n; j+
+)
        sum++;

sum=0;
for (i=0; i<n*n; i++)
    sum++;

for (i=0; i < n-1; i++)


    for (j=i+1; j < n; j++)
{
        tmp = AA[i][j];
        AA[i][j] = AA[j][i];
        AA[j][i] = tmp;
    }

sum = 0;
for (i=1; i<=n; i++)
    for (j=1; j<=n;
j*=2)
        sum++;

sum = 0;
for (i=1; i<=n; i*=2)
    for (j=1; j<=n; j+
+)
        sum++;

3. Provide your answers in a plain-text file named  problemSet-01-


README-C343-username.txt  and push it to your personal IU GitHub
C343 Summer 2021 repository under  /ps/ps01/ .

C. Array-based Lists, Linked Lists


[20 points]
1. Before working on Problem Set 01 Task C, read  Chapter 3:
Lists, Stacks, and Queues  in the course textbook.
2. Assume a list has the following configuration:  <|
2, 23, 15, 5, 9> .
Using one of the List ADT (written in Java) as seen in Lecture
03, write a series of Java statements(*) to delete the element
with value  15 .

Do not turn in an IntelliJ project for this Task C. Instead, write a


thorough explanation for your answer, in a plain-text file
named  problemSet-01-README-C343-username.txt .

(*)i.e.your solution needs to only call methods provided by one


of the List ADTs provided in Lecture 03 notes, not a Java
solution written from scratch. Other solutions are neither
required, not allowed: in particular, we're not asking for any
function calls to Java Collection types (Links to an external
site.).

3. Determine the break-even point for an array-based list and


linked list implementation for lists when the sizes for the data
field, a pointer, and the array-based list's array are as specified
below.
State when the linked list needs less space than the array.
a. The data field is two bytes, a pointer is four bytes, and
the array holds 30 elements.
b. The data field is one byte, a pointer is four bytes, and
the array holds 30 elements.
c. The data field is 32 bytes, a pointer is four bytes, and
the array holds 40 elements.

D. Asymptotic Complexity
[25 points]
1. Arrange the following expressions by growth rate, from slowest
to fastest:

 4n2
 log3n
 n!
 3n
 20 n
 2
 log2n
 n2/3
2. Using the definitions of Big-O, find the upper bound for the
following expressions:
 c1 n
 c2 n3 + c3
 c4 n log2n + c5 n
 c6 2n + c7 n6

You might also like