What's Algorithms? An algorithm is a procedure that consists of a finite set of instructions which,given an input from some set of possible inputs,enables us to obtain an output if such an output exists or else obtain nothing at all if there is no output for that particular input through a systematic execution of the instructions
What’s Algorithms? ◼ An algorithm is a procedure that consists of a finite set of instructions which, given an input from some set of possible inputs, enables us to obtain an output if such an output exists or else obtain nothing at all if there is no output for that particular input through a systematic execution of the instructions
Inputs Outputs Instructions (Problems) (Answers) Computers
Instructions Inputs (Problems) Outputs (Answers) Computers
Programming Data Software Algorithms Languages Structure Systems
Programming Languages Data Structure Algorithms Software Systems
Binary Search Let A[1...n]be a sequence of n elements.Consider the problem of determining whether a given element xis in A
Binary Search ◼ Let A[1…n] be a sequence of n elements. Consider the problem of determining whether a given element x is in A
Binary Search Example: A[1..14]=1457891012152223273235 X=22 Does x exist in A?How many comparisons do you need to give the answer?
Binary Search Example: A[1…14]=1 4 5 7 8 9 10 12 15 22 23 27 32 35 x=22 Does x exist in A? How many comparisons do you need to give the answer?