Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

10. Understanding and modifying algorithms: Selection problem (12 points) First, understand the Selection-sort algorithm below: Selection-sort(A: Array [1..n] of numbers) 1 for i=n down to

image text in transcribed

10. Understanding and modifying algorithms: Selection problem (12 points) First, understand the Selection-sort algorithm below: Selection-sort(A: Array [1..n] of numbers) 1 for i=n down to 2 position=1 for j=1 to (i-1) if A[j]>A[position) then position=j if position # then temp=A[i] A[i]=A[position] A[position]=temp Hamin 14 points) If input A=(12.5.11.6.10.7.9.81, what will A be after the 3rd iteration of the outermost for loop of the Selection-sort algorithm completes? A= L J U J (8 points) Modify the algorithm to solve the problem of finding the k-th largest number in array A, 1sksn, without sorting the entire array. Parts of the algorithm are given below. Fill in the blanks. Select-k-th-largest/A: Array [1..n] of numbers; k: integer, 1sksn) for for then NM + io if position #i then temp=A[i] A[i]=A[position] A[position]=temp return A[n-k+1]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions