Lab-1

Implement the following using C and JAVA. Tabulate the running time of the programs by executing the programs for varying size of input. Also tabulate and observe if the running times of the programs differ due to difference in the programming languages.

1. Write a program to reverse the contents of an array.

2. Write a program which accepts a parenthesized arithmetic expression as input and prints “balanced” if the parenthesis in the expression are matched else prints “unbalanced”.

Ex: a= ((b+c)+e)*d = balanced

a=(b+c)e)*d, a = ) = unbalanced

3. Write a program which returns true if each item in an array is unique else returns false

Time calculation – Java

long startTime = System.currentTimeMillis(); // Number of millisec from Jan 1st 1970

.....your program....

long endTime = System.currentTimeMillis();

long totalTime = endTime - startTime;

System.out.println(totalTime);

Time calculation – C

1. Compile your program

$cc <filename.c>

2. Run your compiled program as follows

$time ./a.out

dsa_lab1.docx