Question

In: Computer Science

What is the Big O of the following algorithms along with the worst and average cases:...

What is the Big O of the following algorithms along with the worst and average cases:

Euclid's Algorithm

Brute-Force Matching

Topological Sort

Lomuto Partition

Russian Peasant Algorithm

Solutions

Expert Solution

1) In euclid's algorithm we take bigeer number modulo small number in each iteration. So the complexity in average case as well as worst case is log(min(m,n)), where m and n are the numbers we want to find gcd of.

2) Brute force matching is basically an algorithm for matching two string patterns. As we're using the brute force approach we'll start with each index of a string and match the characters with each character of the second string. Here the complexity in average case as well as worst case is m*n, where m and n are the lengths of the strings.

3) Topological sorting is basically the same as DFS just with an extra stack. So the complexity in average case as well as worst case will be V+E.

4) Lumuto partition is the same method as we use in quick sort we take a pivot in the array and and swap the elements to make the left elements smaller and right elements bigger. So the complexity in average case is n/2 and in the worst case is n.

5) Russian peasent algorithm we right shift the smaller number untill it becomes 0 so the complexity in average case as well as worst case will be log(min(m,n)), where m and n are the numbers we want to find product of.


Related Solutions

20. The concept of best-, worst-, and average-case analyses extends beyond algorithms to other counting problems...
20. The concept of best-, worst-, and average-case analyses extends beyond algorithms to other counting problems in mathematics. Recall that the height of a binary tree is the number of edges in the longest path from the root to a leaf. (a) Find the best-case height of a binary tree with five nodes. (b) Find the worst-case height of a binary tree with five nodes. (c) Find the average-case height of a binary tree with five nodes. For this problem,...
Calculate the time complexity of each algorithm for best, worst and average cases. Give all steps...
Calculate the time complexity of each algorithm for best, worst and average cases. Give all steps of your calculation and results in Big-O notation. algorithm : Selection Sort Bubble Sort Insertion Sort
1. What is the Big-O run-time of linear search and binary search in the best, average...
1. What is the Big-O run-time of linear search and binary search in the best, average and worst cases?       Linear Search                  Binary Search Best: Worst: Average: 2. What is the Big-O runtime of the following linked list methods? addFirst() toString() What is the Big-O runtime of the below Stack method? isSorted(Node n) 3. What is the Big-O runtime of the below methods: Method A: Stack Copy Constructor Option 1 public Stack(Stack<T> original) { if(original == null) { return; }...
1. Find the big−O, big−Ω estimate for x7y3+x5y5+x3y7. [Hint: Big-O, big- Θ, and big-Omega notation can...
1. Find the big−O, big−Ω estimate for x7y3+x5y5+x3y7. [Hint: Big-O, big- Θ, and big-Omega notation can be extended to functions in more than one variable. For example, the statement f(x, y) is O(g(x, y)) means that there exist constants C, k1, and k2 such that|f(x, y)|≤C|g(x, y)|whenever x > k1 and y > k2] 2. Find a div b and a mod b when: (a) a = 30303, b = 333 (b) a = −765432, b = 3827 3. Convert...
What is the time complexity of the following code? (in big-O notaion) sum = 0 var...
What is the time complexity of the following code? (in big-O notaion) sum = 0 var = 0 product = 0 for i = 1 to (n+2){ sum = sum + 2i for j = i to [(n*n)+i]{ var = sum + var for k = sum + var{ product = var++ } } } for m + 1 to (j*i){ sum = sum + product }
What are Big-O expressions for the following runtine functions?      a) T(n)= nlog n + n...
What are Big-O expressions for the following runtine functions?      a) T(n)= nlog n + n log (n2 )        b) T(n)= (nnn)2           c) T(n)= n1/3 + n1/4 + log n      d) T(n)= 23n + 32n      e) T(n)= n! + 2n Write algorithm and program : Find the sum of the integers from 1 through n.     a)Use iterative algorithm and program         b) Use recursive algorithm and program. Order the following functions by growth rate:...
Q What were the main design goals of the ALGOL programming language? o To describe algorithms...
Q What were the main design goals of the ALGOL programming language? o To describe algorithms in publications o To be machine independent o To teach non-science students o To mimic standard mathematical notation o To standardise software development tools Q The types of variables used in a programming language can be statically declared as part of the source code of a computer program. Define and give an example of explicit variable declaration and implicit variable declaration [2 marks]:
What characteristic of the binary search algorithm results in its speed? What is big O for...
What characteristic of the binary search algorithm results in its speed? What is big O for binary search? Binary search has a significant disadvantage -- what is it?
• What are the assessment tools often used by clinicians in violence risk assessment cases? o...
• What are the assessment tools often used by clinicians in violence risk assessment cases? o What is the most common tool used in these cases? o What type of tools are each (i.e., actuarial, SPJ, clinical, etc.)
(a) Explain the difference between big-O and big-theta, and give examples of each to show the...
(a) Explain the difference between big-O and big-theta, and give examples of each to show the difference. (b) How can we say that two functions have the same asymptotic complexity, using big-theta notation? (c) Rank the following functions in order of increasing complexity (rate of growth), and indicate which functions have the same asymptotic complexity. x2; x log(x); 2x; log(x) + 7; 92x2 + 57x + 3921; 4x; 27x2 + 8x3; 22x+5; log(x42); 3x + 12.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT