From 175721a63b426355274fa9e8063f762020ab8362 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Thu, 30 Jan 2020 16:55:04 -0600 Subject: R E A R R A N G E --- csci1913/Java/lab7_strap012.java | 62 ---------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 csci1913/Java/lab7_strap012.java (limited to 'csci1913/Java/lab7_strap012.java') diff --git a/csci1913/Java/lab7_strap012.java b/csci1913/Java/lab7_strap012.java deleted file mode 100644 index cfb89ed..0000000 --- a/csci1913/Java/lab7_strap012.java +++ /dev/null @@ -1,62 +0,0 @@ -class BinaryVsLinear -{ - - private static int linearSearch(int key, int[] keys) - { - int searchCount = 0; - for (int i=0; iright) { - mid=-1; - break; - } else { - mid=(left+right)/2; - searchCount += 2; - if (keykeys[mid]) { - left=mid+1; - } else { - break; - } - } - } return searchCount; - } - - public static void main(String[] args) - { - for (int length = 1; length <= 30; length += 1) - { - int[] array = new int[length]; - for (int index = 0; index < length; index += 1) - { - array[index] = index; - } - - double linearTotal = 0.0; - double binaryTotal = 0.0; - for (int element = 0; element < length; element += 1) - { - linearTotal += linearSearch(element, array); - binaryTotal += binarySearch(element, array); - } - - double linearAverage = linearTotal / length; - double binaryAverage = binaryTotal / length; - System.out.println(length + " " + linearAverage + " " + binaryAverage); - } - } -} -- cgit v1.2.3