Question

Please discuss numerical algorithms and briefly talk about their time complexities. Some examples are randomizing values,...

Please discuss numerical algorithms and briefly talk about their time complexities. Some examples are randomizing values, breaking numbers into their prime factors, finding greatest common divisors, computing geometric areas, etc.

Note: Question is from advanced algorithms. I just need one paragraph of information on this.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The algorithms I have taken are finding GCD, Merge sort and randomizing values.

1. Finding GCD

Algorithm

int gcd(int a, int b)

{

    if (a == 0)

        return b; ---> Executed once

    return gcd(b % a, a); ---> Gets executed log min(a,b) times

}

Time complexity = O(log min(a,b)) if a and b are two numbers for which we need to find the GCD.

2. Merge sort

MERGE-SORT(A, p,r) 1 if p <r q= [(p +r)/2] MERGE-SORT(A, p, q) MERGE-SORT(A,9 +1,r) MERGE(A, p, q,r)

p and r represent the start and end index of the array to be sorted. Line 3 splits the array into halves (This represents first half). Line 4 sorts the second half. This process happens recursively. Once, the split is complete, the merge happens.

So, the recurrence relation T(n) = 2T(n/2) + n

2T(n/2) represents the time complexity of splitting the array into two halves recursively.

n represents the complexity of merging the array

On solving this recurrence relation, Time complexity T(n) = O(n log n) where n is the size of the array

3. Randomizing values

Consider the following piece of code.

int main()
{
    int no = 8;
    while(no!=rand()) {
       printf("Hello world!\n");
    }
    return 0;
}

In this case, the time complexity cannot be determined. If rand() generates number '8' in the first attempt, the time complexity would be O(1). On the other hand, if the rand() function generates numbers other than '8', the time complexity goes on increasing.

Add a comment
Know the answer?
Add Answer to:
Please discuss numerical algorithms and briefly talk about their time complexities. Some examples are randomizing values,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

  • I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter T...

    I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT