Question
Question about linear search and binary search in java Q - Write Java program to compare time consumed by linear search and binary search to
Question about linear search and binary search in java
Q - Write Java program to compare time consumed by linear search and binary search to search for non-exit element in arrays of length 1000, 100000, 500000, 1000000.
Hints:
Use Random class, method nextInt(a.length) to generate random numbers.
Select an element that is greater than a.length.
Use Arrays.sort(a) to sort the array before using binarySearch.
---------------------------------------------------------------------------------
This is the code that i wrote:
package searchingAlgorithms;
import java.util.Arrays; import java.util.Random;
public class LectureExrcise {
public static void main(String[] args) { int a1[] = new int[1000]; int a2[] = new int [100000]; int a3[] = new int [500000]; int a4[] = new int[1000000]; long startTime = 0; long endTime = 0; long elapsed; Random r = new Random(); for(int i = 0; i } ----------------------------------------- but i don't know why when i run it it gave me this: "same excuting time"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started