Unit01A - Algorithms A Look At Efficiency Counting...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1 1 Algorithms A Look At Efficiency Counting Operations: How much work is done? 1A 2 Algorithms A computer program should be totally correct, but it should also execute as quickly as possible (time-efficiency) use memory wisely (storage-efficiency) How do we compare programs (or algorithms in general) with respect to execution time? various computers run at different speeds due to different processors compilers optimize code before execution the same algorithm can be written differently depending on the programming paradigm 3 Analyzing Algorithms Worst Case Case with maximum number of operations Best Case Case with minimum number of operations Average Case Average number of operations over all cases. 4 What are the operations? Search an array for a value public static int search(int[] x, int target) { for (int i = 0; i < x.length; i++) { if (x[i] == target) return i; } return -1; } 1 2 3 4 5 6 5 Counting Operations Let the x.length = n.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

Unit01A - Algorithms A Look At Efficiency Counting...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online