




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





2
3
4
5
6
sum(int array v, int n) returns int if n = 0 then sum = 0 else sum = nth number + sum of first n-1 numbers return sum
7
8
9
10
11
// Insert your algorithm here
What algorithm would you choose to implement this code snippet?^12
bool LinearArrayContains (int array[], int n, int key ) { for( int i = 0; i < n; i++ ) { if( array[i] == key ) // Found it! return true; } return false; }
Best Case:
Worst Case:
19
20
21
22
23
Remember: the “fastest” algorithm has the slowest growing function for its runtime
BS
24
25
26
B
27
28
29
30
37
38
39
40
41
lim ( )/ ( ) n h n f n 0
lim ( )/ n h n g n ( )
lim ( )/ ( ) n h n f n c 0 42
43
44
45
46
47