Question

2. In class, we discussed the recursive Merge-Sort algorithm. This sorts the whole array by sorting the left side, sorting th
0 0
Add a comment Improve this question Transcribed image text
Answer #1

2)

PSEUDOCODE to find the max in array:
find_max(a[],l,r):
   if(l==r):
       return a[l]
   m = (l+r)/2
   left = find_max(a,l,m)//recursive calls
   right =find_max(a,m+1,r)
   if(left<right)://comparing left and right
       return right
   else:
       return left

recurrence relation to find number of comparisions:
T(n)= 2T(n/2)+1

PSEUDOCODE to find the max in array: find_max(a[1,1,5): if (l==r): return a[1] m = (1+r)/2 left = find_max(a,l,m) //recursive

Add a comment
Know the answer?
Add Answer to:
2. In class, we discussed the recursive Merge-Sort algorithm. This sorts the whole array by sorting...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. E...

    Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...

  • 07-15 pts) Develop a recursive version of the Bubble Sort algorithm. (a) Write the pseudo code...

    07-15 pts) Develop a recursive version of the Bubble Sort algorithm. (a) Write the pseudo code of the algorithm and justify that it is recursive and works correctly Write the recurrence relation for the algorithm and solve it using one of the two approaches discussed in class, as appropriate. Solve the recurrence relation and show that the time complexity of the recursive algorithm is θ(n).

  • Python Merge sort algorithm...

    Implement MERGE-SORT() algorithm that reads from a file named “inputHW02.txt” a list of double numbers (max = 3,000,000 numbers), sorts those numbers and indicates time consumption. This programming question will address the advantage of using iteration loops over recursive calls as well as using INSERTION-SORT() as a procedure in MERGESORT(). Your program must perform the following actions: 1. Opens the given file name and reads all double numbers. For simplicity, we assume this file only contains numbers and nothing else....

  • The algorithm for the Closest Point Pair problem (that we discussed in class) is careful to...

    The algorithm for the Closest Point Pair problem (that we discussed in class) is careful to ensure that it does O(n) work outside of the recursive calls. In this problem, I want to investigate the consequences of not being this careful, on the running time of algorithm for his problem. Specifically, suppose that instead of sorting the points initially (outside the recursion), we sort the points as needed (by x-coordinate and by y-coordinate) inside the recursive calls. (a) Write down...

  • 1. Algorithm write recurrence relation Help? Consider a version of merge sort in which an array...

    1. Algorithm write recurrence relation Help? Consider a version of merge sort in which an array of size n is divided into 5 segments of sizes n/5. Write the recurrence relation for the time complexity and solve it. (Show all your work.)

  • Java Merge sort algorithm

    Implement MERGE-SORT() algorithm that reads from a file named “inputHW02.txt” a list of double numbers (max = 3,000,000 numbers), sorts those numbers and indicates time consumption. This programming question will address the advantage of using iteration loops over recursive calls as well as using INSERTION-SORT() as a procedure in MERGESORT(). Your program must perform the following actions: 1. Opens the given file name and reads all double numbers. For simplicity, we assume this file only contains numbers and nothing else....

  • Consider the following recursive method for finding the maximum element in an int array: public int...

    Consider the following recursive method for finding the maximum element in an int array: public int static max(int[] a, int lo, int hi) { if (lo > hi) return a[lo]; int mid = (lo + hi) / 2; int loMax = max(a, lo, mid); int hiMax = max(a, mid+1, hi); if (loMax > hiMax) return loMax; else return hiMax; } Write down the recurrence relation for counting the number of times the comparison if (loMax > hiMax) is performed. Use...

  • Write a MIPS assembly language for sorting an array of integers using non-recursive bottom-up merge sort...

    Write a MIPS assembly language for sorting an array of integers using non-recursive bottom-up merge sort algorithm. Your program should print the processed array after each step of the merge sort. For example, if the input array is 14 27 13 11 49 63 17 9, your program should print each sort process: Input Arra;y 14 27 13 11 49 63 17 9 Print After first Iteration 14 27 11 13 49 639 17 Print After second iteration 11 13...

  • Part 1: Extend your sorting framework with two advanced sorting methods of your choice: (Shell Sort OR Radix Sort) AND (...

    Part 1: Extend your sorting framework with two advanced sorting methods of your choice: (Shell Sort OR Radix Sort) AND (Merge Sort OR Quick Sort). If you choose Shell Sort, experiment with different incremental sequences to see how they affect the algorithm's run time efficiency (count the number of comparisons and exchanges). If you choose to implement Radix Sort, answer the following question as well: Can you write a version of Radix Sort to work with real numbers? If yes,...

  • Create MIPS program that sorts positive numbers. Inputs the numbers until a zero is inputted and the program displays the sorted numbers. Can use any sorting algorithm except bubble sort.

    Write a MIPS assembly program that sorts a sequence of positive integersentered from the console (one number in one line). The end of thesequence is indicated by a 0 (zero). Verify that the program is correct bysimulation. You can use any sorting algorithm in your code except bubblesort, such as selection sort, merge sort, quick sort, etc. There must be aprocedure call as well as looping in your code. use recursive procedurecalls instead of looping to solve the same problem....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT