The if condition checks that arr[i] < 5000, but if you observe in case of a sorted array, after passing the number 5000 the condition is always false, and before that, it is always true, compiler optimizes the code here. The CPU will recognize that pattern and skips the if conditionbe able to predict correctly which is referred asinstruction to execute next after the conditional branch prediction, instead of sometimes having to rewind after guessing wrong.
allAll the names are sorted. lookLook for ‘johnson’‘Johnson’ in the book. I bet it will take you less than 3 minutes. asAs you know where J is in the alphabet now pretend you have those same 60,000 names and phone numbers - unsorted in the same type of book, all jumbled up. no particular order now go find johnsonJohnson in the book. I bet it will take you hours! as itIt could be on page 3, or page 349.,349; you never know where it is.