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

The following functions have been calculated as the runtime complexity of various algorithms. Identify the Big-O...
The following functions have been calculated as the runtime complexity of various algorithms. Identify the Big-O complexity, and provide witness values to support your answer. Clearly highlight your answer and show any working out you do. i. f(n) = 13 + 3n2 – 9n ii. f(n) = 3n.log2n + 7n iii. f(n) = nn + 2n5 – 7 iv. f(n) = 2log2n + 4n v. f(n) = 20 + 2n4 – n2 +n vi. f(n) = 7n3/4 +3n
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]:
1. State and explain the definition of big-O. 2. Explain why we use big-O to compare...
1. State and explain the definition of big-O. 2. Explain why we use big-O to compare algorithms. 3. Explain why binary search runs in O(log n) time. 4. Under what conditions is it possible to sort a list in less than O(nlog n) time? 5. List and explain the worst-case and average-case running times for each Vector method below: (a) insert(iterator here, Object item) (b) insertAtHead (c) insertAtTail (aka push back) (d) get(iterator here) (e) get(index i) (f) remove(iterator here)...
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?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT