Question

In: Computer Science

There are two algorithms: –Algorithm A requires 5*n2 time units to solve a problem of size...

There are two algorithms:

–Algorithm A requires 5*n2 time units to solve a problem of size n.

–Algorithm B requires 7*n time units to solve a problem of size n.

Draw a chart (graph) to show the performance of the programs.

Solutions

Expert Solution

Algorithm A requires: 5*n^(2) and Algorithm B requires: 7*n time units to solve a problem of size n

Below are the graph which shows the performances of Algorithm A and Algorithm B for different case:

Case1: very large values of n: ~ 10^(9)

As we can observe that performance of Algorithm is extremly worse than that of Algorithm B, this shows that Algo B outperforms Algo A for Larger values of n

Case2: Medium value of n: ~ 10^(4)

In this case also Algo A's performance is extremely worse as compared to Algo B

Case3: Small value of n: ~100

In this case also performance of Algo B is much better than Algo A.

Case4: Small value of n: ~10

In this case also performance of Algo B is still fairly better than Algo A

Case5: very small value of n: ~ 2

We can observe from this graph that for some value of n, between 0 and n, performance of Algo A is better than Algo B.

Equating these two equations: 5*n^(2) = 7*(n) => n = 0, 1.4

Therefore in range 0 to 1.4 Algo A is better than Algo B and since n is integer therefore, it can have only value of 1 in that range, therefore, for n=1, Algorithm A performs better than Algorithm B

Conclusion:

for all integer values of n except 1, Algorithm B is better than Algorithm A


Related Solutions

How much time does an algorithm take to solve a problem of size n if this...
How much time does an algorithm take to solve a problem of size n if this algorithm uses 2n2 + 2n operations, each requiring 10-8 seconds, with these values of n? a) 10: b) 20: c) 50: d) 100
1. Purpose: Apply various algorithm design strategies to solve a problem, practice formulating and analyzing algorithms,...
1. Purpose: Apply various algorithm design strategies to solve a problem, practice formulating and analyzing algorithms, implement an algorithm. In the US, coins are minted with denominations of 50, 25, 10, 5, and 1 cent. An algorithm for making change using the smallest possible number of coins repeatedly returns the biggest coin smaller than the amount to be changed until it is zero. For example, 17 cents will result in the series 10 cents, 5 cents, 1 cent, and 1...
Suppose you are choosing between the following two algorithms: Algorithm A: solves problems of size n...
Suppose you are choosing between the following two algorithms: Algorithm A: solves problems of size n by recursively solving two subproblems each of size (n-1) and then combining the solutions in constant time (take T(0) = 0). Algorithm B: solves problems of size n by recursively solving one subproblem of size (n-1) and then combining the solution in (log n) time (take T(1) = 0). Write down the recurrence relations for the above algorithms.                           Solve the recurrence relations...
Describe a polynomial time algorithm to solve following problem Input: A boolean function in CNF such...
Describe a polynomial time algorithm to solve following problem Input: A boolean function in CNF such that each clause has exactly three literals. Output: An assignment of the variables such that each clause has all TRUE literals or all FALSE literals.
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, ....
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, . . . , n] of positive integers, an integer K. Decide: Are there integers in A such that their sum is K. (Return T RUE or F ALSE) Example: The answer is TRUE for the array A = [1, 2, 3] and 5, since 2 + 3 = 5. The answer is FALSE for A = [2, 3, 4] and 8. Note that you...
2 algorithms for Prefix Averages, one that ran in big-Oh n2 time and a second that...
2 algorithms for Prefix Averages, one that ran in big-Oh n2 time and a second that ran in big-Oh n time. Code up methods for both algorithms. Show through different input examples and using the Current Time method call how the polynomial time algorithm runs slower than the linear time version. Use system.out.println statement to show your results. please who can help with this question In Java Thank you
Explain: Analysis of algorithms with the example. Explain with example: How computational time of an algorithm...
Explain: Analysis of algorithms with the example. Explain with example: How computational time of an algorithm depends on input size? Write an algorithm (using whatever method you prefer) that takes an input of 10 integers, sorts the integers in ascending order and out puts the sorted list. In relation to computational time of your algorithm for part 4, what arrangement of the input numbers will cause the best case computational time? What arrangement will cause the worst case time?
Sorting algorithm for arrays: understand how to perform the following algorithms. (a). Simple sorting Bubblesort:T(n)ÎO(n2) Selection...
Sorting algorithm for arrays: understand how to perform the following algorithms. (a). Simple sorting Bubblesort:T(n)ÎO(n2) Selection sort : T(n) Î O(n2) Insertion sort: T(n) Î O(n2) (b).Advanced sorting i. Shell sort: O(n2) < O(n1.25) < O(nlogn), O(n1.25) is empirical result for shell sort. Merge sort: T(n) Î O(nlogn), need one temporary array with the same length as the array needed to be sorted. Quick sort: -average case: T(n) Î O(nlogn), -worst case(rare occurrence): T(n) Î O(n2) 5. Searching algorithm for...
Use quickselect algorithm to implement the two algorithms for finding the kth smallest integer in a...
Use quickselect algorithm to implement the two algorithms for finding the kth smallest integer in a set of integers. MUST USE JAVA AND QUICKSELECT. Algorithm 1: Procedure SELECT( k,S) { if ISI =1 then return the single element in S    else { choose an element randomly from S;               let S1, S2, and S3 be the sequences of elements in S                 less than, equal to, and greater than m, respectively;              if IS1I >=k then return SELECT(k,S1)              ...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm being used) Requirements Choose one problem with an algorithm and implement it. You should show and explain the result whatever you got. I recommend using N-Queen problem (at least N=8 or more) or any simple perfect games. For example, - N-Queen problem with hill climbing - N-Queen problem with simulated annealing - N-Queen problem with genetic algorithm - Tic-Tac-Toe with Minimax
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT