Please solve and show all steps. This is for C++ problem.
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
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)
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)
- Working on an assignment for C++ codding. Need a little help. I need to write a function that takes in the user's input and returns true if the input contains "polly", "cracker", or "hello". Thanks in advance!arrow_forwardThis assignment will give you practice on basic C programming. You will implement a few Cprogramsarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education