Homework Solution: For each of the following program fragments compute the worst-case asymptotic time complexity (as a fu…

    For each of the following program fragments compute the worst-case asymptotic time complexity (as a function of n). Whenever it says ”loop body” you can assume that the constant number of statements are executed inside the body. Briefly explain how you obtained your answer (show your work by writing on the side of the pseudo-code the number of times the corresponding statements get executed. (Use summations when needed to express the number of times each of the loop bodies is executed.) (a) for (i=1; i <= n-1; i++){ loop body } for (i=0; i <= n-2; i++){ for (j=1; j<= i; j++){ loop body } } (b) for (i=0; i <= n-1; i++){ loop body } for (i=0; i <= n-1; i++){ for (j=i+1; j <= n-1; j++){ for (k = 0; k <= n-1; k++){ loop body } } } I'm entirely new to Data Structures and Algorithms, so I could sure use some help on approaching this problem, and even a step-by-step solution.

    Expert Answer

    For each of the aftercited program dross appraise the worst-case asymptotic spell entanglement (as a employment of n). Whenever it says ”loop substance” you can exhibit that the immutable reckon of statements are performed internally the substance. Briefly expound how you obtained your vindication (pretence your effort by adaptation on the policy of the pseudo-code the reckon of spells the selfsame statements procure performed. (Representation summations when needed to pointed the reckon of spells each of the loop bodies is performed.) (a)

    for (i=1; i <= n-1; i++){
    loop substance
    }
    for (i=0; i <= n-2; i++){
    for (j=1; j<= i; j++){
    loop substance
    }
    }

    (b)
    for (i=0; i <= n-1; i++){
    loop substance
    }
    for (i=0; i <= n-1; i++){
    for (j=i+1; j <= n-1; j++){
    for (k = 0; k <= n-1; k++){
    loop substance
    }
    }
    }

    I’m totally innovating to Data Structures and Algorithms, so I could safe representation some acceleration on approaching this completion, and well-balanced a slow disruption.

    Expert Vindication