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 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?
Please state the worst case run time for the following with an example of the worst...
Please state the worst case run time for the following with an example of the worst case and explain why! 1. Dijksta's Algorithm 2. Bellman-Ford Algorithm 3.DAG Algorithm 4. Prim's Algorithm 5. Kruskal's Algorithm 6. Baruvka's algorithm
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
How to determine whether the following statements about big-O notation are true or false? (a) Let...
How to determine whether the following statements about big-O notation are true or false? (a) Let f(n) = √ n log n − 4, then f(n) = O(n^ 2) (b) Let f(n) = 4 n + 2 log^ 2 (n), then f(n) = O(log^ 2 (n)) (c) Let f(n) = 5 √ n + 2, then f(n) = Ω(log^ 4 (n)) (d) Let f(n) = 5 n^ 2 + 5 n log n + 4, then f(n) = O(n^3 )...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT