EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Question
Chapter 2, Problem 10E
Program Plan Intro
Computational complexity:
- The resource used by an
algorithm is known as its complexity. - The resources required for solving computational problems or for executing an algorithm.
- Time complexity denotes the complexity expressed in terms of execution time.
- Space complexity denotes the complexity expressed in terms of memory needed for computation.
- Complexity of operations that is mathematical.
Explanation of Solution
(b) The auto increment “cnt2++” is executed exactly “n2” times
- The external for loop is executing “n” times
- The internal for loop is executin...
Explanation of Solution
(c) The auto increment “cnt3++” is executed exactly “nlogn” times
- The external for loop is executing “logn” times
- The internal for loop is executing “n” times
Explanation of Solution
(d) The auto increment “cnt4++” is executed exactly “n” times
- The external for loop is executing “logn” times
- The internal for loop is executing “2n” times
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
int functionC (int n)
{
int i, j, sumC = 0;
for (i=n; i > 0; i=i-5)
for (j=1; j 0)
{
if (functionC(n) % 2 == 0)
{
for (i=m; i > 0; i=i/3) sumE++;
}
else
(10) Asymptotic runtime of functionE
{
for (i=m; i > 0; i=i-3) sumE--;
}
n--;
}
return sumE;
for ( i = 1 ; i < n ; i * 2 ){
for ( j = 0 ; j < min( i , k ) ; j++){
sum++
}
}
}
what is the time complexity
sum= 0;
for (int i = 0; i 1) {
sum++;
i= 1/2;
}
= 2*log2 (n)
We denote by Ta(n), Tb (n), Te(n) the running time of the three fragments.
1. Give evaluations for Ta(n), Tb (n), Te(n).
2. Is T(n) = O(Ta(n)) ? Answer YES or NO and justify your answer.
3. Is Te(n) = (Ta(n)) ? Answer YES or NO and justify your answer.
Chapter 2 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- I Evaluate the time complexity of following code: int a-0; for (i-0; i< N; i++){ aa+i;) for (i 0; i< N; i+){ a-a+i;) 2arrow_forwardI. Compute for the running time for each algorithm 1. for i = 1 to n do Statement B 2. for(j=1; js n*n*n;j++) for (k=1; ksn) Statement f; for(m=1;marrow_forwardWrite the Fibonacci Function program with: Recursive and Iterative method respectively using the following condition: Fib (1) is 1 Fib (2) is 1 Fib (N) is Fib (N-2) + Fib (N-1), for N > 2 Show the Hand Simulations of activation records for both the programs and display the outputarrow_forward1. Consider the following two loops: // Loop A for (i = 1; i e n; i++) for (j - 1; j e 10000; j++) sum = sum + j; // Loop B for (i - 1; i <= n; i++) for (j - 1; j n; j++) sum - sum + j: What is the Big O of each loop? Design and implement an experiment to find a value of n for which Loop B is faster than Loop A. 2. Repeat the previous project, but use the following for Loop B: // Loop B for (i = 1; i <= n; i++) for (j = 1; jarrow_forwardWrite the Fibonacci Function program with: Recursive and Iterative method respectively using the following condition: Fib (1) is 1 Fib (2) is 1 Fib (N) is Fib (N-2) + Fib (N-1), for N>2 Show the Hand Simulations of activation records for both the programs and display the outputarrow_forwardQ. Time Complexity of the following CPP code will be order of O()? int a = 0; for (i = 0; i < N; i++) { for (j = N; j > i; j--) { a = a + i + j; } }arrow_forwardFind the solution and draw the recursion trace for the execution of function Recursive (3). Please circle your answer. Algorithm Recursive (x) : Input: Integer x Output: Integer d if x > 7 d = 5 else if x = 7 d = 3 else d = Recursive (x + 3) + Recursive (x + 1) returndarrow_forwardAnalyze the time complexity of the code segment and find their Big-O. void myfunction2(int n) {for (int i = 0; i < n * n; ++i) {for (int j = 0; j < n; ++j) {for (int k = 0; k < i; ++k) printf(”k = ” + k);for (int m = 0; m < 100; ++m)printf(”m = ” + m); }}}arrow_forwardi = 0, j = 0 For(a = 0; a*a < n; a++){ For(b = 0; b < n; b *= 2){ For(c = 0; c*c < n; c++){ i += i j = j*2 } } } What is the time complexity for the code? (a) O(n−−√∗n∗n) (b) O(n−−√∗logn∗n−−√) (c) O(n∗logn) (d) O(n2.5) (e) O(n)arrow_forwardAnalyze the following codes for Time and space complexity. Determine Big O for the following code fragments in the average case. Assume that all variables are of type int. (i) sum = 0; if (EVEN(n)) for (i=0; i<n; i++) sum++; else sum = sum + n; sum1 = 0;arrow_forwardIndicate the run time complexity: for(int i = 1; i < n; i = i*2) y++; for(int i = 1; i < n; i = i*2) y++; O(n lg n) O(n) O(lg n) O None of the choices O(2")arrow_forwardCashOrNothingOption = function(S, k, Time, r, q, sigma) {d1 = (log(S / k) + (r - q + sigma ^ 2 / 2) * Time) / (sigma * sqrt(Time))d2 = d1 - sigma * sqrt(Time)if(k>S){return (k * exp (-r * Time) * (-d2))}elseprint("zero")}arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- 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
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:PEARSONC 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
The Top Down Approach to Software Development; Author: Christopher Kalodikis;https://www.youtube.com/watch?v=v9M8LA2uM48;License: Standard YouTube License, CC-BY