EBK DATA STRUCTURES AND ALGORITHMS IN C
EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
bartleby

Concept explainers

Question
Book Icon
Chapter 2, Problem 3E
Program Plan Intro

Asymptotic Notations:

For asymptotic analysis of algorithms, some mathematical tools are used to represent time complexity of algorithm, such mathematical tools are known as Asymptotic notations. Some of the asymptotic notations are described below:

Big-O:

A function “g(n)” is O(f(n)) if there exists a constant c > 0 such that “cf(n)” grows faster than "g(n)" for all n>=n0 , that is, “g(n)” is O(f(n)) iff for some constants “c” and “n0”, g(n)<=cf(n) for all n>=n0. Here, “f(n)” denotes upper bound for “g(n)”. The important points for above statements is as follows :

  • “n” is the data set size.
  • “f(n)” denotes a function that is calculated while taking n as the parameter.
  • O(f(n)) means that curve denoted by “f(n)” is an upper bound for a function’s need for resources.

Big Theta:

A function “g(n)” is Θ(f(n)) iff two positive constants “c1” and “c2” and a positive integer n0 exists such that c1f(n)g(n)c2f(n) for all n>=n0, that is, “f(n)” denotes the exact bound for “g(n)”, which denotes that growth rate of “g(n)” and “f(n)” are equal. The important points for above statements is as follows :

  • “n” is the data set size.
  • “f(n)” denotes a function that is evaluated taking “n” as the parameter.
  • Θ(f(n)) means that curve denoted by “f(n)” is an exact bound for the resource needs of a function.

Refer question 3 from chapter 2 for given statements.

Expert Solution
Check Mark

Explanation of Solution

 (a).

The statement i=1ni2 is O(n3) if a constant “c” exists such that i=1ni2cn3.

  • Here, i=1ni2 denotes sum of squares of natural numbers, that is

    i=1ni2 =12+22+...n2 =n(n+1)(2n+1)6 =2n3+3n2+n6

  • So, i=1ni2n.n2=n3 , thus c=1 for any “n”.

Hence, i=1ni2 is O(n3), and in general i=1nik is O(nk+1).

Explanation of Solution

(b).

  • Function anklogn is O(nk) if there is a “c and “N” for which anklogncnk for all nN
  • The inequality becomes a/lognc for N>1, and since alogn0, c=a can be substituted.
  • But, no value for “c” is possible for which ca/logn.

Thus, anklogn is not θ(nk). Hence, the function is O(nk).

Explanation of Solution

(c).

  • The function n1.1+nlogn is θ(n1.1) if two constants exists such that c1n1.1n1.1+nlognc2n1.1.
  • These inequalities could be transformed into c11+n-1lognc2 by rule of L'Hospital.
  • n-1logn=(logn)/n1 has same limit as (loge)/(1.n1)=(10.loge)/n1 that is 0.
  • Therefore, c1=1,c2=1+10loge .

Hence, the given function is θ(n1.1).

Explanation of Solution

(d).

  • The function 2n is O(n!) if there are “c” and “N” for which 2ncn! for all nN . If N = 1, then 2ncn! implies that 2nc(1*2*3...*n), that is , 21*22*23...*2n2=c , that is, value of constant c=2 .
  • Hence, function 2n is O(n!).
  • n! is O(2n)if there exists “c” and “N” such that n!c2n for nN .
  • The inequality n!c2n implies 1*2*3....*nc(2n) , that is , 12*22*32...*n2c for all “n’s” .
  • In this case, such a constant could not be found

Hence, function n! is not O(2n).

Explanation of Solution

(e)

  • A constant “c” exists such that for some “N” and all nN, 2n+ac2n.
  • If c2n+a/2n=2a, that is, if the value of constant c2a

Hence, function 2n+a is O(2n).

Explanation of Solution

(f).

  • A constant “c” doesnot exists such that for some “N” and all nN, 22n+ac2n.
  • There exists no constant “c” such that c22n+a/2n=2n+a.

Hence, the function 2n+a is not O(2n).

Explanation of Solution

(g).

  • As n=2logn, na=2alogn , therefore, if 2alogn>2logn, then na>2logn
  • A constant “c” has to be found such that for some “N” and all nN, 2logncna or 2lognc2alogn.
  • That is, c2logn/2alogn , which is possible because the function 2logn/2alogn is decreasing.

Hence, function 2logn is O(na).

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Give English language translations of the following wff if M(x): x is a man W(x): x is a woman i: Ivan p: Peter W(x, y): x works for y (∃x)(W(x) ∧ (∀y)(M(y) → [W(x, y)]')) which one of this answer choices a. No woman works for any man. b. Every woman works for some man. c. Some woman does not work for any man. d. Every woman works for every man.
Correct answer will be upvoted else downvoted. Computer science.    stage is a succession of n integers from 1 to n, in which every one of the numbers happen precisely once. For instance, [1], [3,5,2,1,4], [1,3,2] are stages, and [2,3,2], [4,3,1], [0] are not.    Polycarp was given four integers n, l, r (1≤l≤r≤n) and s (1≤s≤n(n+1)2) and requested to find a stage p of numbers from 1 to n that fulfills the accompanying condition:    s=pl+pl+1+… +pr.    For instance, for n=5, l=3, r=5, and s=8, the accompanying stages are reasonable (not all choices are recorded):    p=[3,4,5,2,1];    p=[5,2,4,3,1];    p=[5,2,1,3,4].    However, for instance, there is no change reasonable for the condition above for n=4, l=1, r=1, and s=5.    Help Polycarp, for the given n, l, r, and s, find a stage of numbers from 1 to n that fits the condition above. In case there are a few appropriate changes, print any of them.    Input    The primary line contains a solitary integer t (1≤t≤500). Then, at that point,…
Correct answer will be upvoted else downvoted. Computer science.    Allow us to signify by d(n) the amount of all divisors of the number n, for example d(n)=∑k|nk.    For instance, d(1)=1, d(4)=1+2+4=7, d(6)=1+2+3+6=12.    For a given number c, track down the base n to such an extent that d(n)=c.    Input    The principal line contains one integer t (1≤t≤104). Then, at that point, t experiments follow.    Each experiment is characterized by one integer c (1≤c≤107).    Output    For each experiment, output:    "- 1" in case there is no such n that d(n)=c;    n, in any case.
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage