0% found this document useful (0 votes)
1 views

01_time_and_space_complexity

The document discusses factors of a number, providing examples and methods to find them, including brute force algorithms. It also touches on the importance of comparing algorithms based on iterations rather than just time, and introduces concepts like asymptotic analysis and neglecting lower order terms. Additionally, it highlights the significance of understanding algorithm performance for large inputs.

Uploaded by

Vidushi Vinod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

01_time_and_space_complexity

The document discusses factors of a number, providing examples and methods to find them, including brute force algorithms. It also touches on the importance of comparing algorithms based on iterations rather than just time, and introduces concepts like asymptotic analysis and neglecting lower order terms. Additionally, it highlights the significance of understanding algorithm performance for large inputs.

Uploaded by

Vidushi Vinod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Faitor of a number n

it a number that completely divides

for cg
x is a
factor of n

then n 0

8 1 2 4 8

Quiz 1 24 1,2 3,4 6,8 12,24


24
1 24
2 12
3 8
I
6 4
8 3
12 2
2u I
Quizz 10 2 5 10

Given total
a number n
find out the
number
of factors

BRUTE FORCE

T.int int i 1
for ien itt
L
if i
n o

Count tf
3
3

Iteration 1 loop

The above code has a iterations

108iterations 1 sec
n no of iteration Timetaken

108 108 1sec


101 10 100 sec
1018 1018 101 seconds

317 years

108 iteration I see


1 iteration
f
sec

101 iteration 10

8
1010
9 5
19
n i is a factor
then is also a factor

24 25

i Ni i Ni
1 24 1 25
2 12 5 5
a

8
6

3
IIT
12 2
24 1 ixi n
i ñ
for int i 1 ixi n it L
L
if
n i o

i Ii
if Count count 2
else
count count 1
3
3
24 25
i count I count
1 2 1 2

2 4 5 3
3 6
8
Total iterations Jn
Total iteration Total time
1818
109
of number

T a

a a n

6
Go
6 6 36

x̅ a

10T
1018 2 109
Pjime numbers Number where
count 2
of factors

10 11 23 2 25 27 31

4
a b Range
of numbers
when both a b
are inclusive

a b Range
of numbers
when both a b
are exclusive

b
Avish 3.10 a

10 3 1 8 b at

3 4 5 6 7 8 9,10 no
of integers
in the range
a b
Sum of 1ˢᵗ natural
If
n

number

Natural number 1 2 3,4

1 2 3 the 100

1 01 505

Geometric Progression G.PT


5 10 20 40 80 160

4 12 36 108

f Common
3 ration

a first term
Sum 1ˢᵗ n terms GP
of in

a ar ar as as

s
off 8 1

5 10 20 40 80 160

A 5 8 2 n 6

of 542
5 64 1

5 63 315
for int i 1 n L
i
if
n

break
3

1 n n it

n iterations
for int i 0 100 L
S St it i
3
0 100 I 100 0 1

101 iterations
Quiz 2

L
n iterations

m iterations

Ntm
How to compare 2 algorithms

Sumanth Amogh

10 sec 20sec
writes in Ctt

10sec 8sec

5sec 8sec

Time is not the best metric


to compare 2 algorithms because time
gets affected by external factor

No of iteration Best metric to


compare algorithms
Sumanth Amogh

100 logn No

n 3500 Amogh waebetter


n 3500 Sumanth was better

Most watched video Somewhere


on in billions
youter
Ind vs Pak viewship
in sore

Asymptotic
Analysis Analysing algorithm
of very large
fornumber
Algorithms Δ
BIG
1 no
of iterations

2
ignore lower order terms

3
ignore constant

niftions

14
constant

06 Fn
did f Un 3nlogn I

Un 3nlogn 1

nlogn

O nlogn
106
F n Unlogn 3nF
oarn
Comparison
Qer
log n A n nlogn
non m m 2 n
Neglect Lower Oodes terms

Iterations m loon

Contribution
Total iterations of
Infge lower orderteam

D 10 100 1000 90

7 100 10000 10000 50

105 1010 107 20.1


n

As input size contribution


increases
lower ordes term decreases
of
Neglect Constante

Algo 1 Algo 2 Which is


better
for large
inputs

lologn n Alost
loologn N Algo 1

1000 logn n Algo I


I withbigo

1stI.su
When we that alog 1 is better
say
than algo 2 using Bigo we can
only make that that claim for large
input

2ⁿᵈ Issue

Algol 2m Un Algo2 3m

n n

When Bigo is same we might have


to look at number
of iterations
to which is better
say
2013
ACM

ICPC 2 7 Bits Pilon


50
Media.net Diseti
Cakhel
Δ 2021
Worked on
side
startup
my
2oz
4
Phonepe

2024 4m
3
9
1n
204

You might also like