Question: JAVA PROGRAM: LABORATORY EXERCISE: Use the above class which defines the different Big O Notation to test each of the following algorithms. Take a screenshot

JAVA PROGRAM:

JAVA PROGRAM: LABORATORY EXERCISE: Use the above class which defines the different

LABORATORY EXERCISE:

Use the above class which defines the different Big O Notation to test each of the following algorithms. Take a screenshot for the result for each algorithm and write down your own comment on its complexity performance. Then summarize your findings by comparing all the observations you have done.

1. O(1) Order of One Test: import java.util.Arrays; public classOrderOfOneTest {

public static void main(String[] args) {

BigONotation testAlgo = new BigONotation(10);

testAlgo.addItemToArray(10);

System.out.println(Arrays.toString(testAlgo.theArray));

}

}

2. O(N) Order of N Test:

public class OrderOfNTest {

public static void main(String[] args) {

BigONotation testAlgo2 = new BigONotation(100000); testAlgo2.generateRandomArray();

BigONotation testAlgo3 = new BigONotation(200000); testAlgo3.generateRandomArray();

BigONotation testAlgo4 = new BigONotation(300000); testAlgo4.generateRandomArray();

BigONotation testAlgo5 = new BigONotation(400000); testAlgo5.generateRandomArray();

testAlgo2.linearSearchForValue(20); testAlgo3.linearSearchForValue(20); testAlgo4.linearSearchForValue(20); testAlgo5.linearSearchForValue(20);

}

}

3. O(N2) Order of N square Test:

public class OrderOfNSquareTest {

public static void main(String[] args) {

BigONotation testAlgo2 = new BigONotation(10000);

testAlgo2.generateRandomArray();

BigONotation testAlgo3 = new BigONotation(20000);

testAlgo3.generateRandomArray();

BigONotation testAlgo4 = new BigONotation(30000);

testAlgo4.generateRandomArray();

testAlgo2.bubbleSort(); testAlgo3.bubbleSort(); testAlgo4.bubbleSort();

}

}

4. O(Log N) Order of Log N Test: public class OrderOfLogNTest {

public static void main(String[] args) {

BigONotation testAlgo2 = new BigONotation(1000000);

testAlgo2.generateRandomArray();

BigONotation testAlgo3 = new BigONotation(2000000);

testAlgo3.generateRandomArray();

testAlgo2.binarySearchForValue(20); testAlgo3.binarySearchForValue(20);

}

}

5. O(N Log N) Order of N Log N Test: public class OrderOfNLogNTest { public static void main(String[] args) {

long startTime;

long endTime;

BigONotation testAlgo2 = new BigONotation(10000);

testAlgo2.generateRandomArray();

BigONotation testAlgo3 = new BigONotation(20000);

testAlgo3.generateRandomArray();

BigONotation testAlgo4 = new BigONotation(30000);

testAlgo4.generateRandomArray();

startTime = System.currentTimeMillis(); testAlgo2.quickSort(0, testAlgo2.itemsInArray); endTime = System.currentTimeMillis();

System.out.println("Quick Sort Took " + (endTime - startTime));

//--------------------- startTime = System.currentTimeMillis(); testAlgo3.quickSort(0, testAlgo3.itemsInArray); endTime = System.currentTimeMillis();

System.out.println("Quick Sort Took " + (endTime - startTime));

//--------------------- startTime = System.currentTimeMillis(); testAlgo4.quickSort(0, testAlgo4.itemsInArray); endTime = System.currentTimeMillis();

System.out.println("Quick Sort Took " + (endTime - startTime));

}

}

import java uti].Arravs; public class BigoNotation \{ public int [] theArray; public int arraySize; public int itemsInArray =; static long startTime; static long endTime; BigoNotation(int size) { arraysize = size; theArray = new int[ size ]; 3 public void addItemToArray(int newItem) \{ theArray[itemsInArray++] = newItem; System, out.println("Value Found: =+ valueInArray); endTime = System. currentimeMiLLis() System.out.println("Linear Search Took " + (endTime - startTime)); endTime = System. current Timemillis() System.out.println("Bubble Sort Took " + (endTime - startTime)); public void quicksort(int left, int right) \{ \}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!