






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth analysis of algorithms, focusing on their complexity in terms of time and space. Topics covered include best and worst-case scenarios, storage vs. Computation time, big-o notation, and code comparisons. Students will learn how to write procedures, understand the importance of big-o notation, and compare the efficiency of different algorithms.
Typology: Slides
1 / 10
This page cannot be seen from the preview
Don't miss anything!







3
Time (seconds)
60 50 40 30 20 10 (^0 1 2 3 4 )
O(C) O(n 2 )
4
5
with Ada.Integer_Text_Io, Ada.Text_Io; use Ada.Integer_Text_Io, Ada.Text_Io; procedure CalcSum is N : Integer; Total_Sum : Integer; begin Put_Line("Enter an Integer: "); Get(N); Total_Sum := 0; for I in 1..N loop Total_Sum := Total_Sum + I; ; Put(Total_Sum); end ;
6
with Ada.Integer_Text_Io, Ada.Text_Io; use Ada.Integer_Text_Io, Ada.Text_Io; procedure Calcsum is N : Integer; Total_Sum : Integer; begin Put_Line("Enter an Integer: "); Get(N); Total_Sum := 0; Total_Sum := (N * (N + 1)) / 2; Put(Total_Sum); end ;
N*(N+1) 2
end loop
9
10
11
search
12
10 11 14 17 21 33 55 57 62 71 87 89 91 93 95 97
1 2 3 4 5 6 7 8 9
Example, a full balanced Binary Search Tree
Can eliminate half of the BST every time the
Any algorithm that eliminates a large portion of the data set at each iteration is generalized
10 11 12 13 14 15 16
15
2 N^ calculations
16
1 and largest N 2 number in a list and generate a new list of 1 and N 2
all the numbers in between N
17
Definition : T (n) = O(f(n)) – “ T of n is in Big-Oh of f of n” c and n 0 such that: T (n) ≤ cf(n) for all n ≥ n 0
: The algorithm is in O( n^2 ) in [best, average, worst] case.
Meaning : For all data sets big enough (i.e., n > n 0 ), the algorithm always executes in less than cf ( n case. Big-O is said to describe an “upper bound
18
Finding value X in an array (average cost).
T ( n ) = cs n /2.
For all values of n > 1, c (^) s n /2 <= c (^) s n.
Therefore, by the definition, T ( n ) is in O( n ) for n 0 = 1 and c = cs.
T (n) = O(f(n)) iff T (n) ≤ cf(n) for all n ≥ n 0
iff there are constants
Usage
) steps in [best, average, worst]
” on the complexity.
21
O(N*M+N^2 ) Same as
O(N^2 logP+N) Same as
O(5*N^3 Reduces to
22
2 n 13 16 -----
2 n^270223 3.
5 n log n 250 1,842 7.
20 n 500 5,000 10
10 n 1,000 10,000 10
T ( n ) n n ’ n ’/ n