Ask Question
5 April, 22:44

Given an n-element array X, algorithm D calls algorithm E on each element X[i]. Algorithm E runs in O (i) time when it is called on element X[i]. What is the worst-case running time of algorithm D?

+3
Answers (1)
  1. 6 April, 00:56
    0
    O (n^2)

    Explanation:

    The number of elements in the array X is proportional to the algorithm E runs time:

    For one element (i=1) - > O (1)

    For two elements (i=2) - > O (2)

    .

    .

    .

    For n elements (i=n) - > O (n)

    If the array has n elements the algorithm D will call the algorithm E n times, so we have a maximum time of n times n, therefore the worst-case running time of D is O (n^2)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given an n-element array X, algorithm D calls algorithm E on each element X[i]. Algorithm E runs in O (i) time when it is called on element ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers