Java code implementation:
Search Algorithm class -
package com.programmingpearls.study; public class SearchAlg { private static int[] a = new int[]{23,33,44,11,32,89, 56,77,98,123,432,97,92,11,56,20,127,132,721,321,9,8,6,14, 112,322,311,213,43,34,30,51,5,2,53,54,49,47,512,522,503,504, 607,702,700,78,74,71,81,93,101,39,59,88,77,222,227,228,122, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 155,145,135,195,197,198,199,189,109,108,1119,1089,190, 1999,2999,3999,4999,5999,6999,7999,8999,9999,99990}; private int size; public SearchAlg() { size = a.length; } public int searchMotherOne(int target) { TimeTracer mTimer = new TimeTracer(); for(int i=0; i;>
Utility class - Record Time overhead
package com.programmingpearls.study; public class TimeTracer { private long m_starttime; private long m_endtime; public TimeTracer() { startTimeStamp(); } private void startTimeStamp(){ m_starttime = System.nanoTime();//currentTimeMillis(); System.out.println(" start time = " + m_starttime); } private void endTimeStamp(){ m_endtime = System.nanoTime(); System.out.println(" end time = " + m_endtime); } public long getTimeDuration() { endTimeStamp(); long duration = m_endtime - m_starttime; System.out.println(" executing time = " + duration); return duration; } public long getStarttime() { return m_starttime; } public void setStarttime(long starttime) { this.m_starttime = starttime; } public long getEndtime() { return m_endtime; } public void setEndtime(long endtime) { this.m_endtime = endtime; } }
Programming Result :
start time = 5979371955374
end time = 5979372277202
executing time = 321828
start time = 5979372372186
end time = 5979372466612
executing time = 94426
start time = 5979372554053
end time = 5979372642333
executing time = 88280