Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 3. (20 points) Consider the pseudo-code below for both insertion sort and merge sort. Re-write the for-loop as a while loop in the merge

image text in transcribed

Problem 3. (20 points) Consider the pseudo-code below for both insertion sort and merge sort. Re-write the for-loop as a while loop in the merge sort pseudo-code. (You do not need to show the modified while-loop merge sort.) Then count how many lines need to execute to sort the array [3, 2, 1] for both algorithms. Show some work to receive full (and partial) credit. Only count lines the computer thinks on. Note: for merge sort, do not count the function calls, splits or array creation. Just the number of lines inside the merge function. Also, assume no work needs to be done merging a size 1 and 0 array. Example: sorting 12, 1] with insertion sort = 11 lines, merge = 14 lines.) TopDownMerge (A[], iBegin, iMiddle, iEnd, B[]) Merge sort i = iBegin, j = iMiddle; wnLLe nere are elements in the left or right runs... for (k - iBegin; k = and A[j] > x A[j+1] A[j] 1 end while i-i+ 1 end while

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

More Books

Students also viewed these Databases questions