Produce an equation that asymptotically describes the following algorithms runtime: define algorithm_1(input): x = 2 y = 2 x = ((y + z) * 80)/4 print x, y, z define algorithm_2(input): x = 1 y = 5 loop from x to size(input) * 4: y = y +5 print x, y define algorithm_3(input): x = user_input() y = user_input() z = 0 loop i = 0 to size(input): if x
Please solve and show all steps. This is for C++ problem.
![Produce an equation that asymptotically describes the following algorithms runtime:
define algorithm_1(input):
x = 2
y = 2
x = ((y +z) * 80)/4
print x, y, z
define algorithm_2(input):
x = 1
y = 5
loop from x to size(input) * 4:
y = y +5
print x, y
define algorithm_3(input):
x = user_input()
y = user_input()
z = 0
loop i = 0 to size (input):
if x <y:
z=z+1
else
Z=Z-1](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1dbff557-c987-45fc-8dd6-6084416c9157%2F6633c274-5803-497e-9acc-2393621b2bc4%2Fpjue11d_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Use previous solution to Derive Big Oh for the
- We need to provide the asymptotic equation that will describe the complexity of the provided code snippets.
1. First code ::
-> In this we have 3 operations and all the operation take constant time.
We are considering (input = n).
Lets take time taken for ::
- x = 2 , y = 2 -> a (Constant time)
- x = ((y + z) * 80) /4 -> b (Constant time)
- print x ,y, z -> c (Constant time)
Here all are constant operations. So,
T(n) = a + b + c , which can also be written as ::
T(n) = k (Constant)
2. Second code ::
-> In this code we have a loop and so the operation will take linear time.
We are considering (input = n).
Lets take time taken for ::
- x = 1 , y = 5 -> a (Constant time)
- loop, (y = y + 5) , (print x, y) -> 4*n (Linear time)
T(n) = a + 4*n or,
T(n) = a + b*n ( a, b = constant)
3. Third code ::
-> In this code we have a loop and so the operation will take linear time.
We are considering (input = n).
Lets take time taken for ::
- x and y input -> e (Constant time)
- z = 0 -> f (constant time)
- loop -> g* n (linear time)
- if x < y -> h* n (linear time)
- Other operations -> k (linear time)
T(n) = (e + f) + (g+h) *n + k
- We assume :: (e + f) = a , (g+h) = b
T(n) = a + bn + k ( a, b, n are constants)
![Derive Big Oh for the algorithms from Problem 1.](https://content.bartleby.com/qna-images/question/1dbff557-c987-45fc-8dd6-6084416c9157/1445ba92-b932-4015-9bc4-e8a1314cf0eb/aq5slo7p_thumbnail.jpeg)
![Produce an equation that asymptotically describes the following algorithms runtime:
define algorithm_1(input):
x = 2
y = 2
x = ((y+z) * 80)/4
print x, y, z
define algorithm_2(input):
x = 1
y = 5
loop from x to size(input) * 4:
y = y +5
print x, y
Derive Big Oh for the algorithms from Problem 1.
define algorithm_3(input):
x = user_input()
y = user_input()
z = 0
loop i = 0 to size (input):
if x <y:
z=z+1
else
Z=Z-1](https://content.bartleby.com/qna-images/question/1dbff557-c987-45fc-8dd6-6084416c9157/1445ba92-b932-4015-9bc4-e8a1314cf0eb/1afq3db_thumbnail.jpeg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)