For example, if Merge sort is used to sort the letters of the word PROVISIONAL into alphabetical order then the subsequences at each stage will be: after Oth iteration (P),(R),(0), (V),(I),(S),(I),(0), (N), (A), (L); after 1st iteration (P,R),(0,V),(1,S),(I,0),(A,N),(L); after 2nd iteration (0,P,R,V),(I,1,0,S),(A,L,N); after 3rd iteration (I,I,0,0,P,R,S,V),(A,L,N); after 4th iteration (A,I,I,L,N,0,0,P,R,S,V). (a) Apply the Merge sort algorithm to sort the letters of the word STEREOPHOTOGRAPHIC into alphabetical order, showing the results of each iteration as in the example above.

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
In lectures we saw how use the Merge sort algorithm to sort a sequence
of length n = 2" into ascending order. In fact the algorithm can be applied to sequences
of any length n e N. At each iteration the current sorted sub-sequences are merged in
pairs as for the 2" case but if there are an odd number of sub-sequences then the 'left over'
one just joins, unchanged, the newly formed sub-sequences at the next iteration. This
will mean that the merge algorithm will sometimes need to merge sequences of unequal
lengths, but this causes no problems.
For example, if Merge sort is used to sort the letters of the word PROVISIONAL into
alphabetical order then the subsequences at each stage will be:
after Oth iteration (P),(R),(0), (V),(I),(S),(I),(0),(N),(A), (L);
after 1st iteration (P,R),(0,V),(I,S),(I,0),(A,N),(L);
after 2nd iteration (0,P,R,V),(I,I,0,S),(A,L,N);
after 3rd iteration (I,I,0,0,P,R,S,V),(A,L,N);
after 4th iteration (A,I,I,L,N,0,0,P,R,S,V).
(a) Apply the Merge sort algorithm to sort the letters of the word STEREOPHOTOGRAPHIC
into alphabetical order, showing the results of each iteration as in the example above.
(b) How many comparison operations are used to merge sort STEREOPHOTOGRAPHIC? As
in Worksheet Q5, remember that when the merge algorithm reaches the stage where
one of its input lists is empty, it does not need any more comparisons to complete
its task. For example, for PROVISIONAL there are only 5 comparisons during the first
iteration, 8 in the 2nd, 7 in the 3rd and 5 in the last.
(c) How many comparison operations would be used if STEREOPHOTOGRAPHIC were sorted
using the Selection sort algorithm?
Transcribed Image Text:In lectures we saw how use the Merge sort algorithm to sort a sequence of length n = 2" into ascending order. In fact the algorithm can be applied to sequences of any length n e N. At each iteration the current sorted sub-sequences are merged in pairs as for the 2" case but if there are an odd number of sub-sequences then the 'left over' one just joins, unchanged, the newly formed sub-sequences at the next iteration. This will mean that the merge algorithm will sometimes need to merge sequences of unequal lengths, but this causes no problems. For example, if Merge sort is used to sort the letters of the word PROVISIONAL into alphabetical order then the subsequences at each stage will be: after Oth iteration (P),(R),(0), (V),(I),(S),(I),(0),(N),(A), (L); after 1st iteration (P,R),(0,V),(I,S),(I,0),(A,N),(L); after 2nd iteration (0,P,R,V),(I,I,0,S),(A,L,N); after 3rd iteration (I,I,0,0,P,R,S,V),(A,L,N); after 4th iteration (A,I,I,L,N,0,0,P,R,S,V). (a) Apply the Merge sort algorithm to sort the letters of the word STEREOPHOTOGRAPHIC into alphabetical order, showing the results of each iteration as in the example above. (b) How many comparison operations are used to merge sort STEREOPHOTOGRAPHIC? As in Worksheet Q5, remember that when the merge algorithm reaches the stage where one of its input lists is empty, it does not need any more comparisons to complete its task. For example, for PROVISIONAL there are only 5 comparisons during the first iteration, 8 in the 2nd, 7 in the 3rd and 5 in the last. (c) How many comparison operations would be used if STEREOPHOTOGRAPHIC were sorted using the Selection sort algorithm?
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Radix Sort
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