Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Analyzing Time Complexity of Loops in Programming: Understanding Common Loop Structures and Nested Loops

Rating
-
Sold
-
Pages
1
Uploaded on
05-03-2023
Written in
2020/2021

This document provides an in-depth understanding of time complexity and how it relates to loops in programming. The document explores common loops used in programs and provides examples of how to calculate their time complexity. It also covers nested loops and how to calculate their time complexity by multiplying the time taken by each loop. The document uses mathematical concepts to explain the time complexity of loops and provides practical examples to help readers understand the concept. This document is essential for anyone looking to improve their programming skills and develop efficient algorithms.

Show more Read less
Institution
Course

Content preview

Analysis of Loop in Programming
Data Structures and Algorithm
In this lecture, we will look at some common loops frequently used in
programs and try to find their time complexities. Later, we will examine
functions containing multiple loops and find their time complexities as
well. A ceiling of n by c means that plus or minus some number is a
constant. Therefore, if we find the order of growth, that constant will be
ignored, and the order of growth will be n, resulting in a time complexity
of theta of n. After every pass, we increase i by multiplying it with c until
i becomes more than n. Then we check the condition i < n, which is not
satisfied. We use the condition i < n, which means c raised to the power
k minus 1 is less than something. Now we'll log both sides to base c. If we
find the order of growth of k, we ignore the lower-order term. To find the
time complexity here, we can use mathematics like we did in the
previous example. We need to write i in terms of c. Initially, i is 2, and
then i becomes 2 raised to the power c. C raised to power 0 is 1, and 2
raised to power 1 is also 1, so these two terms are the same. Another
term we can write is 2 raised to power 1 divided by c. 3 is 5 1 2. Three,
which is 5, 1 2 1 1 1. The overall time complexity becomes theta of log
log log n, and the time complexity of our third example becomes theta
log of log n. I hope that you are now able to find the time complexity of
these common loops on your own because these are very common loops.
A nested loop means a loop inside another loop. In this example, we
declared a variable i, which is 0, and after every pass, we increase j by a
constant or multiply it by a constant, which here is 2. In the case of a
nested loop, we multiply the time taken by the first loop into the time
spent by another loop, resulting in this. You can see this logic.

Written for

Course

Document information

Uploaded on
March 5, 2023
File latest updated on
March 5, 2023
Number of pages
1
Written in
2020/2021
Type
SUMMARY

Subjects

$10.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
user111

Get to know the seller

Seller avatar
user111 University of Arizona College of Engineering
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 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

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions