Arpita Shaw - CA1 - DSA

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

GHANI KHAN CHOUDHURY INSTITUTE OF

ENGINEERING & TECHNOLOGY

N A M E – A R P I TA S H AW

COURSE – B. TECH

BRANCH – CSE(AI & ML)

REG. NO. – 23355010038

ROLL NO. – 35530823013

SEMESTER – 3RD
CONTENT

• A LG ORI THM

• W H AT I S T I M E C O M P L E XI TY ?

• W H Y I S T I M E C O M P L E XIT Y I M PO RTANT ?

• B A S I C C O N C E P TS – IN PU T SIZE , W O RST, B E ST & AVE RA GE C A SE

• A S Y M P TOTI C N OTATI ON – B IG O, B IG TH ETA, B I G O M E G A

• E X A M PL ES O F TI M E C O M PL E XITIE S

• C O N C LUS IO N

• REFERNCES
Algorithm

• Se q u e n c e o f s t e p s o n d a t a u s i n g
e f f ic ien t d a t a s t r u c t u r e s t o s o l ve a
g i ve n p r o b l em.

• G o o d A l g o r i t h m s?

• R u n i n l e s s ti m e

• Consume less memory

• B u t ti m e co m p l e xity i s u s u a l ly m or e
i m p o r t a n t.
What is Time Complexity? WHY IS TIME COMPLEXITY IMPORTANT?

D E F I N I T IO N : T IM E C O M P LE X I T Y I S A • Resource Optimization: Understanding time


M E A S U R E O F T H E A M O U N T O F T I ME A N complexity allows developers to optimize
A L G O R I T HM T A K ES T O C O MP L E T E A S A resources like CPU time and memory.
F U N C T I O N O F T HE I N P U T S I Z E , U S U A L L Y
Efficient algorithms can lead to significant
DENOTED BY N.
savings in computation time and energy,
• P redicting Performance: T i m e c om p l exi t y especially in large -scale systems.
h e l p s i n e s t i m a t i n g h ow a n a l g or i t h m w i l l
s c a l e a s t h e i n p u t s i z e i n c re a s e s . T h i s i s • Comparison of Algorithms: Time complexity

c r u c i a l for de te r m i n i ng wh e t h e r a n provides a standardized way to compare the

a l g or i t h m i s p ra c t i c a l for l a rg e da t a s e t s . efficiency of different algorithms. By


analyzing the time complexity, we can choose
• E xample: For i n s t a n c e , c on s i de r a n
the most efficient algorithm for our specific
a l g or i t h m t h a t s e a rc h e s for a n i te m i n a
problem.
l i s t . T h e t i m e i t t a ke s to f i n d t h e i te m
w i l l de p e n d on t h e n u m be r of i te m s i n
the list.
BASIC CONCEPTS
WORST, BEST, AND AVERAGE CASE:

INPUT SIZE(N) • Wo r s t C a s e : Th e m a xi m u m ti m e a n a l g o rithm


ta ke s f o r a ny i n p u t o f s i ze n . Fo r i n s ta n ce, i n a
• Th e i n p u t s i ze n i s a cr u ci a l l i n ea r s e ar ch , th e w o r s t ca s e o ccu r s w h e n th e
f a cto r b e ca u s e th e ti m e i te m b e i n g s e a r ch e d f o r i s a t th e e n d o f th e
com p l exity of a n a l g orithm i s l i s t, r e s u l ting i n O ( n ) ti m e .
e xp r e s s e d a s a f u n ctio n o f n .
• Be s t C a s e : Th e m i n imu m time a n a l g o rithm
Fo r e xa m p l e, i f w e 'r e s o r ti ng a
ta ke s f o r a ny i n p u t o f s i ze n . Fo r e xa m p l e, i n
l i s t, n r e p r e s e n ts th e n u m b e r
th e b e st ca se f or l i near se a r ch, the i te m i s a t
of e l e m ents i n tha t l i st. A s n
th e b e g i nn ing o f th e l i s t, s o th e ti m e
i n cr e a s es , th e ti m e ta ke n b y
co m p l exity i s O ( 1 ) .
th e a l g o rith m m ay i n cr e a s e,
d e p e n d ing o n i ts co m p l exity. • Ave ra g e C a s e : Th e e xp e cte d ti m e a n a l g o r ithm
ta ke s o n a " ty p i cal" i n p u t o f s i ze n .
Asymptotic Notation
f(n) <= c*g(n) for all n >= n0
BIG O (O):

• Pu r p o s e : B i g O n o t a t i o n i s u s e d t o
d e s c r i b e t h e w o r s t - c a s e s c e n a ri o. I t
p r ov i d e s a n u p p e r l i m i t o n t h e t i m e
c o m p l e x i ty.

• E x a m p l e : Fo r a s i m p l e l i n e a r s e a r c h,
where you check each element in a
l i s t o n e b y o n e , t h e t i m e c o m p l e x i ty
is O(n).

• Why It Matters: Big O is crucial for


e n s u r i ng t h a t a n a l g o r i t h m w o n ' t
p e r f o r m w o r s e t h a n e x p e c te d , e v e n i n
t h e m o s t d e m a n d i n g s i t u a tio n s .
• Big Theta (Θ): c1 g(n)≤f(n)≤c2 g(n),
• Pu r p o s e : B i g T h e t a n o t a t i o n g i ve s a p r e c i s e m e a s ur e o f a n a l g o r i thm’s e f f i c i e nc y b y p r ov i di n g
b o t h a n u p p e r a n d l o w e r b o u n d . I t t e l l s u s t h a t t h e r u n n i n g t i m e g r o w s a t e x a c tl y t h i s ra t e .

• E x a m p l e : I f a n a l g o ri th m h a s a t i me c o m p l e x i ty o f Θ ( n l o g n ) , i t m e a n s t h a t i t s r u n n i ng t i m e
w i l l g r o w a t a ra t e p r o p o r t i o n a l t o n l o g n , r e g a r d l e s s o f w h e t h e r i t ’s t h e b e s t , a v e ra g e , o r
worst case.

• W h y I t M a t t e r s : B i g T h e t a p r ov i d e s a m o r e a c c u ra te p i c t ur e o f a n a l g o r i thm' s p e r f o r ma n c e
a c r o s s a l l p o s s i b l e c a s e s , m a k i n g i t u s e f u l w h e n t h e e x a c t g r o w t h ra t e i s i m p o r ta n t .

• Big Omega (Ω): c g(n) ≤ f(n)

• Pu r p o s e : B i g O m e g a n o t a t i o n d e s c r i be s t h e b e s t - c a se s c e n a ri o o r t h e m i n i mum t i m e a n
a l g o r i th m c o u l d t a ke t o r u n . I t s e t s a l o w e r l i m i t o n t h e t i m e c o m p l e x i ty.

• E x a m p l e : Fo r t h e s a m e l i n e a r s e a r c h , i f t h e i t e m yo u’ r e l o o k i n g f o r i s t h e f i r s t o n e i n t h e l i s t ,
t h e t i m e c o m p l e x i ty i s Ω ( 1 ) , m e a n i n g t h e s e a r c h c o m p l e te s i n c o n s t a n t t i m e .

• W h y I t M a t t e r s : B i g O m e g a h e l p s i n u n d e r st a ndi n g t h e p o t e n ti a l e f f i c i e nc y o f a n a l g o r i thm
under optimal conditions.
Examples of Time Complexities

• Constant Time: O(1)

• Example: Accessing an element in an array by its index.

• Linear Time: O(n)

• Example: Finding an element in a list using linear search.

• Quadra tic Time: O(n²)

• Example: Nested loops, such as in a bubble sor t algorithm .


CONCLUSION

• I n s u m m a r y, t i m e c o m p l e x ity i s a f u n d a me nt a l c o n c e p t i n c o m p u t e r s c ie nc e t h a t a l l ow s u s
t o a n a l y ze a n d c o m p a r e t h e p e r f o rm a n c e o f a l g o rit hm s . B y u s i n g a s y m p t o tic n o t a t ion s l i ke
B i g O, B i g T h e t a , a n d B i g O m e g a , w e c a n d e s c r i be h o w t h e r u n n i ng t i m e o f a n a l g o rit hm
c h a n g e s w i t h t h e s i ze o f t h e i n p u t . T h e s e n o t a tio n s h e l p i n u n d e r s t a n din g t h e e f f ic ien c y o f
a l g o rit hm s a n d i n m a k i n g i n f o r me d d e c i s i on s w h e n s e l e c t in g a l g o r ith ms f o r d i f fe re nt
tasks.

REFERENCES

https://www.freecodecamp.org/news/big-o-cheat-sheet-
time-complexity-chart/ THANK YOU

https://www.geeksforgeeks.org/understanding-time-
complexity-simple-examples/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy