Introduction to Algorithms
Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
bartleby

Concept explainers

Question
Book Icon
Chapter 2.2, Problem 2E
Program Plan Intro

To write the pseudo code of selection sort and also describe the loop invariants and the running time complexity in best and worst case.

Blurred answer
Students have asked these similar questions
Consider sorting n numbers stored in array A by first finding the smallest elementof A and exchanging it with the element in A[1]. Then find the second smallestelement of A, and exchange it with A[2]. Continue in this manner for the first n-1elements of A. Write pseudocode for this algorithm, which is known as selectionsort. What loop invariant does this algorithm maintain? Why does it need to run foronly the first n - 1 elements, rather than for all n elements? Give the best-case andworst-case running times of selection sort in Θ -notation.
Write an algorithm that sorts a list of n items by dividing it into three sublists of about n/3 items, sorting each sublist recursively and merging the three sorted sublists. Analyze your algorithm, and give the results under order notation.
Consider sorting n numbers stored in array A[1:n] by first finding the smallestelement of A[1:n] and exchanging it with the element in A[1]. Then find thesmallest element of A[2:n], and exchange it with A[2]. Then find the smallestelement of A[3:n], and exchange it with A[3]. Continue in this manner for thefirst n-1 elements of A. Write pseudocode for this algorithm, which is knownas selection sort. What loop invariant does this algorithm maintain? Why does itneed to run for only the first n-1 elements, rather than for all n elements? Give theworst-case running time of selection sort in big theta notation. Is the best-case runningtime any better?
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education