Consider the list of characters: ['P', 'Y', 'T', 'H', 'O', 'N']. Show how this list is sorted using merge sort, use induction to prove the run time of this algorithm.
[P Y T H O N]
split in two
[P Y T] [O N]
split
[P Y] [T] [O N]
split
[P] [Y] [T] [O N]
merge [P] and [Y]
[P Y] [T] [O N]
merge [P Y] [T]
[P T Y] [O N]
split [O N]
[P T Y] [O] [N]
merge [O] [N]
[P T Y] [N O]
merge
[N O P T Y]
running time of this program is n(logn)
T(n) = 2T(n/2) + O(n)
T(n) = O(nlogn)
T(2) = 2T(1) + O(1) = 2
= which is same 2log2
so base case satisfied, let it be true till n-1 (i..e, true for n/2)
T(n) = 2T(n/2) + O(n)
= 2knlogn + cn
= n(2klogn + c)
= O(nlogn)
Hence proved
Let see
Consider the list of characters: ['P', 'Y', 'T', 'H', 'O', 'N']. Show how this list is...
Please show clear explanation for both parts explain how you
would use merge sort for (a) and divide and conquer for (b).
Order Statistic. Given two sorted lists x and y. Both x and y
have size n.
(a) Describe an algorithm that finds the median of X
Y in O(n) time.
(b) Describe an algorithm that finds the median of X
Y in O(logn) time.
Use the following sequence as the list to sort: [ T, H, A, N, K, F, U, L ] You need to display the contents of the list during the execution of the algorithm. a) Sort the list using selection sort. b) Sort the list using heap sort. You do not need to draw the heap diagram unless you find it helpful, but you must still show the contents on the list during execution. c) What is the worst-case runtime...
Insertion sort on small arrays in merge sort Although merge-sort runs in Θ(n log n) worst-case time and insertion sort runs in Θ(n 2 ) worst-case time, the constant factors in insertion sort can make it faster in practice for small problem sizes on many machines. Thus, it makes sense to coarsen the leaves of the recursion by using insertion sort within merge sort when subproblems become sufficiently small. Consider a modification to merge sort in which n/k sublists of...
r the recurrence relation o. Consider T(n) = Vn T(Vn) + n a. Why can't you solve this with the master theorem? b. S t involves a constant C, tell me what it is in terms of T(O), T(1), or whatever your inequality by induction. Show the base case. Then show the how that T( n)= 0(n lg ig n). First, clearly indicate the inequality that you wish to hen proceed to prove the inductive hypothesis inductive case, and clearly...
Puodace a char showing the number of moves required to solve the Towers of Hanoi puzle using t 30. What is an execution frame? What is an activation record? What is contained in it? 31. Write a recursive Java method that computes the factorial of a number 2. Linear search may require up to comparisons while binary search will only require roughly comparisons 33. Sort sorts a list of values by repetitively putting a particular value into its final, sorted,...
6. Consider the recurrence relation T(n) = 2T(n-1) + 5 for integers n 1 and T(O) = 0. Find a closed-form solution Using induction, prove your solution correct for all integers n 20.
List the worst case and average case Big O for each algorithm below and describe how the algorithm works. You can diagram or write a short paragraph. Bubble Sort Modified Bubble Sort Insertion Sort Merge Sort Selection Sort Shell Heap Quick
Consider a variation of Merge sort called 4-way Merge sort. Instead of splitting the array into two parts like Merge sort, 4-way Merge sort splits the array into four parts. 4-way Merge divides the input array into fourths, calls itself for each fourth and then merges the four sorted fourths. a)Implement 4-way Merge sort from Problem 4 to sort an array/vector of integers and name it merge4. Implement the algorithm in the same language you used for the sorting algorithms...
Please give a output Linux/Ubuntu and how to run it (compile) this program ,my assigment is below : : Merge Sort algorithm using 2 processes a.) Define an integer array of 100 integers. Populate this array with random numbers. You can use int rand(void); function. Do not forget to initialize this function. You will sort the numbers in the array using merge-sort algorithm. In merge sort algorithm the half of the array will be sorted by one process and second...
Prove using mathematical induction that for every positive integer n, = 1/i(i+1) = n/n+1. 2) Suppose r is a real number other than 1. Prove using mathematical induction that for every nonnegative integer n, = 1-r^n+1/1-r. 3) Prove using mathematical induction that for every nonnegative integer n, 1 + i+i! = (n+1)!. 4) Prove using mathematical induction that for every integer n>4, n!>2^n. 5) Prove using mathematical induction that for every positive integer n, 7 + 5 + 3 +.......