Skip to main content

Posts

Showing posts with the label Algorithms

Big O notation

Big-O Analysis of Algorithms The Big O notation defines an upper bound of an algorithm, it bounds a function only from above. Don't get too hung up on this.  We want to use this as an example to measure how long it takes for this function to run.  We can do this in Java by saying let's say Time0 is going to  start this timer before the loop happens. And then when the loop ends I'm going to have another timer called T-1   package com. algo . practise ; import java.util.Arrays ; import java.util.concurrent.TimeUnit ; public class Performance { public static void main (String[] args) { String ar[] = { "rks" , "rk" , "rakesh" , "singhania" , "kumar" }; // Returns current time in millis long timeMilli1 = System. nanoTime (); for ( int i = 0 ; i < ar. length ; i++) { if (ar[i]. equals ( "rakesh" )) { System. out . println ( "found" ); } } long timeMil...