Question

Analysis of Algorithms Fall 2013 Do any (4) out of the following (5) problems 1. Assume n-3t is a power of 3 fork20. Solve ac

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

1)

Code://using Recursion

#include <iostream>

using namespace std;

long int calculatePower(int exponent)
{
   if (exponent == 1)
   {
       return 3;
   }
   return calculatePower( exponent - 1) * 3;
}
void main()
{
   cout << "Value : " << calculatePower(3);
}

2)a) True. Algorithm B runs more faster more increasing data size that is when n increases.

b) True, For most of the values of n Algorithm B runs faster than Algorithm A.For example for n = 2 O(n^2) = 4 and for O(n log n) it will be almost equal to 4 .This indicates that for small values of n which is less than 5.Both the time complexities will be almost equal.

c)False, For input size n like 100 Algorithm B will run many times faster when compared to Algorithm A. As explained in section b.

Add a comment
Know the answer?
Add Answer to:
Analysis of Algorithms Fall 2013 Do any (4) out of the following (5) problems 1. Assume n-3t is a...
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
  • Suppose we have two algorithms A1 and A2 for solving the same problem. Let T_1(n) be...

    Suppose we have two algorithms A1 and A2 for solving the same problem. Let T_1(n) be the worst case time complexity of Algorithm A1 and T_2(n) be the worst case time complexity of Algorithm A2. We know that T_1(1) = 1 and T_1(n) = 8 middot T_1(n/2) + 100n^2. We also know that T_2(1) = 1 and T_2(n) = 63 middot T_2(n/4) + 200 middot n^2. Use the master method to decide T_1(n). Follow all the steps as illustrated in...

  • Question 4 (10 marks) When analysing the complexity of algorithms, there are three main approaches: worst case, best ca...

    Question 4 (10 marks) When analysing the complexity of algorithms, there are three main approaches: worst case, best case and average case. As an example, consider measuring the complexity of list-merging by counting the number of comparisons used As a test example, assume the following A1: There are two ordered lists, each of length 4, say A2: Neither list contains repeats, so a! < a2 < аз < a4 and bl <b2 < b3 < b4 A3: The lists are...

  • ld ts biovs Part II: Analysis of recursive algorithms is somewhat different from that of non-recursive...

    ld ts biovs Part II: Analysis of recursive algorithms is somewhat different from that of non-recursive algorithms. We are very much interested in how many times the method gets called. The text refers to this as the number of activations. In inefficient algorithms, the number of calls to a method grows rapidly, in fact much worse than algorithms such as bubble sort. Consider the following: public static void foo ( int n ) { if n <=1 ow ura wor...

  • 4. [16 marks total (6 marks each)] Do a worst-case analysis for the following algorithm segments, counting the number of multiplications which occur. I have marked the lines with the multiplications...

    4. [16 marks total (6 marks each)] Do a worst-case analysis for the following algorithm segments, counting the number of multiplications which occur. I have marked the lines with the multiplications you are to count with ). For all of these algorithms, use n as your fixed input size (even though n doesn't really represent the "size" of the input). Be sure to include an explanation with your answers to obtain full marks. (a) t-10; for (i-1;in-H) t-5*t; (b) (For...

  • [Code in C] Help me with this. Not sure what to do. 1 Couting Sort You...

    [Code in C] Help me with this. Not sure what to do. 1 Couting Sort You may have learned some sorting algorithms - such as bubble sort ad quicksort in CS 110 and CS 210. This homework is about counting sort. Let n be the number of elements to be sorted. Bubble sort and quicksort assume tha time, which one is larger and which one is smaller. They make no assumption on the values of the elements t we can...

  • 3) Out of the following, name which kind of attack you carried out in part 1...

    3) Out of the following, name which kind of attack you carried out in part 1 and part2: a. ciphertext only, b. known plaintext, c. chosen plaintext, d. chosen ciphertext. Explain your answer Problem 3 10 points] A 4-bit long message was encrypted using one-time pad to yield a cipher-text “1010” Assuming the message space consists of all 4-bit long messages, what is the probability that the corresponding plaintext was “1001”? Explain your answer. Problem 4 Assume we perform a...

  • JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question...

    JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question 12 pts Which is a valid constructor for Thread? Thread ( Runnable r, int priority ); Thread ( Runnable r, String name ); Thread ( int priority ); Thread ( Runnable r, ThreadGroup g ); Flag this Question Question 22 pts What method in the Thread class is responsible for pausing a thread for a specific amount of milliseconds? pause(). sleep(). hang(). kill(). Flag...

  • Recursion and Trees Application – Building a Word Index Make sure you have read and understood...

    Recursion and Trees Application – Building a Word Index Make sure you have read and understood ·         lesson modules week 10 and 11 ·         chapters 9 and 10 of our text ·         module - Lab Homework Requirements before submitting this assignment. Hand in only one program, please. Background: In many applications, the composition of a collection of data items changes over time. Not only are new data items added and existing ones removed, but data items may be duplicated. A list data structure...

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