Apply algorithm 4.3.2 in P.155 with n=6 and A=(3,5,4,1,3,2). Draw only the right half of the corresponding walkthrough as shown in P.155, showing only the list A at the end of the outer “for” loop.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Apply algorithm 4.3.2 in P.155 with n=6 and A=(3,5,4,1,3,2). Draw only the right half of the corresponding walkthrough as shown in P.155, showing only the list A at the end of the outer “for” loop.

We can sort the A-values by finding the minimum of all of them and
interchanging it with A[1], then finding the minimum of all the A-values from
A[2] to A[n] of them and interchanging it with A[2], and so on.
Algorithm 4.3.2: MinSort
Begin
For k + 1 To (n-1) Do
min – A[k];
// the kh pass selects a correct value for A[k]
// min will be the smallest in A[k]..A[n]
// & min occurs at entry A[index]
index + k;
For j + k+1 To n Do
If (A[j] < min) Then
min + A[j];
index + j;
// the if
// the for-j loop
A[index] E A[k];
End;
End;
A[k] + min;
End;
// the for-k loop
End.
// If A[1], A[2], ... A[n – 1] have been selected correctly, what about A[n]?
// Can we remove the variable min and just use A[index]?
Walkthrough with n = 5 and A = (3.1, 5.7, 4.3, 1.9, 3.1)
//
Al] %3 3.1, А2] — 5.7, А[3] — 4.3, A[4] —D 1.9, A|5] — 3.1
k
min
index
j
A[j]
A
3.1
2
5.7
3.1
5.7
4.3
1.9
3.1
3
4.3
4
1.9
1.9
4
3.1
1.9
5.7
4.3
3.1
3.1
5.7
3
4.3
4.3
3
4
3.1
3.1
4
3.1
1.9
3.1
4.3
5.7
3.1
3
4.3
4
5.7
3.1
3.1
1.9
3.1
3.1
5.7
4.3
4
5.7
4.3
4.3
5
1.9
3.1
3.1
4.3
5.7
We can prove that
"A[1] <= A[2] <= ... <= A[k] <= A[k + 1], A[k+2], ..., A[n]"
is a loop invariant of the for-k loop.
That will confirm that MinSort is correct.
// using MI on k
// But is it efficient?
Transcribed Image Text:We can sort the A-values by finding the minimum of all of them and interchanging it with A[1], then finding the minimum of all the A-values from A[2] to A[n] of them and interchanging it with A[2], and so on. Algorithm 4.3.2: MinSort Begin For k + 1 To (n-1) Do min – A[k]; // the kh pass selects a correct value for A[k] // min will be the smallest in A[k]..A[n] // & min occurs at entry A[index] index + k; For j + k+1 To n Do If (A[j] < min) Then min + A[j]; index + j; // the if // the for-j loop A[index] E A[k]; End; End; A[k] + min; End; // the for-k loop End. // If A[1], A[2], ... A[n – 1] have been selected correctly, what about A[n]? // Can we remove the variable min and just use A[index]? Walkthrough with n = 5 and A = (3.1, 5.7, 4.3, 1.9, 3.1) // Al] %3 3.1, А2] — 5.7, А[3] — 4.3, A[4] —D 1.9, A|5] — 3.1 k min index j A[j] A 3.1 2 5.7 3.1 5.7 4.3 1.9 3.1 3 4.3 4 1.9 1.9 4 3.1 1.9 5.7 4.3 3.1 3.1 5.7 3 4.3 4.3 3 4 3.1 3.1 4 3.1 1.9 3.1 4.3 5.7 3.1 3 4.3 4 5.7 3.1 3.1 1.9 3.1 3.1 5.7 4.3 4 5.7 4.3 4.3 5 1.9 3.1 3.1 4.3 5.7 We can prove that "A[1] <= A[2] <= ... <= A[k] <= A[k + 1], A[k+2], ..., A[n]" is a loop invariant of the for-k loop. That will confirm that MinSort is correct. // using MI on k // But is it efficient?
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education