LAB 2 and 1
LAB 2 and 1
Lab1: Ex1. Calculate the elapsed time of Linear search and Binary Search.
Code:
public class App {
public static void main(String[] args) {
int[] num = {1, 2, 3, 5, 6, 7};
if (foundBinary == -1) {
System.out.println("Not Found!");
} else {
System.out.println("Found at Index " + foundBinary);
}
Output:
Lab2: Ex2.Consider the below code for interative binary search. Run the code
and write down the output. And also explain its working.
class BinarySearchDemo {
static Object[] a = { 10, 20, 30, 40, 50, 60, 70, 80 };
static Object key = 50;
Output: