100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Summary How to Calculate Time Complexity of an Algorithm

Rating
-
Sold
-
Pages
2
Uploaded on
23-02-2023
Written in
2022/2023

Information about How to Calculate the Time Complexity of an Algorithm can be referred to by the student who starts to learn the basics of Data Structures and Algorithms. DSA PART 5

Institution
Course








Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Course

Document information

Uploaded on
February 23, 2023
Number of pages
2
Written in
2022/2023
Type
Summary

Subjects

Content preview

How to Calculate Time Complexity of an Algorithm
Before Solving Some Questions of Time Complexity I will tell you some tricks to get rid of time
complexity. After that we will do some set of questions. which will make you a very good grasp
in such questions. due to the time complexity of any algorithm when you have to find it so what
is the first step that you do and at the same time how to approach this problem. In this way,
whatever instructions are going on here , it is taking almost ( k ) time. We believe that these
operations are all (k ) time consuming This for loop , that is , how much time is being taken for
this fragment It seems ( kn ) , okay So before this ( int i ) would have been written here, ( int
k=0 ) would be written here. The third technique that I want to tell you is this : That break the
code into fragments. The first fragment turned out to be this one , with a little bit of
initialization. It took constant time because it is not such that if the value of ( n ) increases, then
its time will increases.


I will go for ( n = 100 ) to determine whether i will be going for n = 1000. I will accept it in ( k4)
and ( n * k4 ) I will do it in k4 and (n* k4), and it will happen O (n²) If you do it ( k=0 ) , ( k < n )
and if you look at it , it will come out O ( n²) Okay, it will not (N²) ok remember you this thing.
There will be some code on it which will take ( k1 ) Now I have become so smart, by doing
questions , and you will be done too That (k1) it is will going to be non-dominant , if constant is
being added then we will remove it. So once the value of ( i ) will be zero (0) and then the value
of ( j ) will run for. Then ( j=1) will become Then ( 0,2) Then (i=0 , and j=0 ) will then run for Okay.
The value of ( i ) will be zero ( 0 ) for ( n ) times running then the value of (i ) will become ( 1 ) , it
will run again (n ) times then it will go on till n. When ( n) is running out, watch carefully , watch
very closely. Then later I will ask the question, then I am telling if it is not done. value of i will be
( 1) , ( n ), it will be n-1 because I am taking the index ( i=0 ) then (i=n-1) will be and here is ( n- 1
)


I told you guys If it 's not clear to you why it will work ( n² ) times So I 'd say let 's go look at it for
3 and 3 and print here (i , j ) and make a count variable and count it , how many times it is
running You write ( c ) program , write in Python, write in Java, write in Python and write in the
Java. But when there are 2 loops inside one , then that will run for n² times. And if another loop
is given inside it , then it will run ( n³ ) times. If there is a double for loop, then it becomes
straight (n² ) I have handpicked some questions which I am going to give to you guys here. And I
have also given their programs to you. So you see here I have opened this folder in visual studio
code. So it 's saying that Find the time complexity ( Func1 ) function in the program shown in
program1. c as follows. Even if you come from another programming language nothing is going
to be change. The time of (F1+F2+F3) will be that I will take as the overall time of the whole
function. The time is not depending on Array 's length so i 'll accept it ( k1 ) and I can not accept
( F2 ) as ( k ) , i will accept it as k2 * n. So now if I find a total time complexity that is , if I T ( n )
come out , then what will it be ? T (n ) will be done as T (N) =F1 +F2 +F3.


The answer is O (length) The algorithm it is talking in terms of length over here. The time
$7.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
adityashrivastav

Get to know the seller

Seller avatar
adityashrivastav Thakur College of Science and Commerce
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
2 year
Number of followers
0
Documents
8
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions