Lab3003
  • FacultyAlgorithmChallenge
  • README
  • Question Bank
  • Python Documentation
    • BetterMap
    • Board
    • Card
    • Circle
    • Deck
    • README.md
    • Guide For Bookmarklet
    • Hand
    • HashMap
    • Hist
    • Kangaroo
    • LinearMap
    • Markov
    • Point
    • PokerDeck
    • PokerHand
    • Rectangle
    • State
    • Test
    • ThinkPython
    • ThinkPython2
    • Time
    • Think Python
    • thinkpython
  • Files
  • Image Files
  • lab
    • InsertSortTDD
    • countingBits
    • cs3003mergeSortLectureGuideLine
    • index_min
    • insort
    • One-line factorial function in Python
  • Manual for Python Lab
    • COURSE OBJECTIVES
    • 1_timelines
    • FDPNotes
    • PC-2_Python
    • lab1-kgashok.py
    • Lab 10 :Matrix Multiplication
    • Lab 11: Programs that take command line arguments (word count)
    • Lab 11: Programs that take command line arguments
    • Lab 12: Compute the most frequently used words from the text file
    • Lab 12: Find the most frequent words in a text read from a file
    • Lab 12a: File content sorter
    • Lab 2: Find the square root of a number (Newton’s method)
    • Lab 3: Compute power of a number (Exponentiation)
    • Lab 3: Exponentiation (power of a number)
    • lab4-binaraysearch-anvar.py
    • Solution for Binary Search
    • lab4-joelanandraj-binarysearch.py
    • Lab 4: Linear and Binary Search
    • lab4-lin-anvar.py
    • Linear Searcher
    • Lab 5 : find n prime numbers
    • lab6-kgashok.py
    • lab7-kgashok.py
    • lab8-kgashok.py
    • Lab 8: Selection and Insertion sort using Python
    • Merge Sort
    • Quick Sort
    • labSheet
    • pc0
    • sortPythonic
    • Sorting
  • misc
    • Bookmarklets
    • Guide For Bookmarklet
    • pythonResources
    • FDP for Python
    • Agenda for Workshop
      • Agenda
  • notes
    • Problem Set
    • InsertSortTDD
    • MergeSort
    • cs3003-unit1-notes
    • cs3003-unit3
    • cs3003-unit4-examples
    • Unit 4 Lists, Tuples and Dictionaries
    • cs3003insertsortLectureGuide
    • cs3003mergeSortLectureGuideLine
    • Designing and Delivering Effective Lectures
    • histogram.py
    • selectSortLectureGuide
  • Sandbox to try ThinkPy2 code
    • Code from ThinkPython Github repository
  • Important Topics
    • 3003-syllabus
    • GE8161 PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY L T P C
    • Unit II Version 2
    • Unit IV material
    • UNIT III CONTROL FLOW, FUNCTIONS
    • Unit 1 Algorithm Problem Solving
    • Unit_V_Notes
    • UpdatedSyllabus
    • glossary
    • glossaryGeneration.py
    • importantTopics-kgashok
    • memCSV
    • Tower of Hanoi
    • Notes for Unit 2 - Illustrative programs
    • unit5-updated_notes
    • unit_1_notes
    • Unit 3 Control Flow Version 1
    • unit 3
      • UNIT III CONTROL FLOW, FUNCTIONS
    • unit_i_img
Powered by GitBook
On this page
  • A Visualization is worth a 1000 tables
  • A Table is Worth a 1000 pictures
  • Pictures, pictures galore
  • Modified Bubble Sort Approach
  • Selection Sort
  • Insertion Sort
  • Divide and Conquer Approach
  • Merge Sort
  • Quick Sort
  • Clarifying Questions
  1. Manual for Python Lab

Sorting

PrevioussortPythonicNextmisc

Last updated 3 years ago

For a quick wordy comparison, take a look at:

A Visualization is worth a 1000 tables

A Table is Worth a 1000 pictures

Classifier
Selection
Insertion
Merge
Quick

Type

Simple

Simple

Efficient

Efficient

Extra Space

Not required

Not required

Required

Required

Constructs

Two for loops

Two for loops

Terminal cases and Recursive calls

Terminal case and Recursive calls

Stable

Yes

No

Yes

No

Strategy

Only Comparison

Only Comparison

Divide and Conquer

Divide and Conquer

Most preferable for

small size lists

small size lists

bigger lists

bigger lists

Parallelism

Not applicable

Not applicable

Most suitable

Suitable

Complexity O(n)

n**2

n**2

nlogn - worst case

n**2 - worst case

Used by

Python's timsort

Python's timsort

Linux's sort

Pictures, pictures galore

"A picture is worth a 1000 words." The pictures help convey the contrasting dynamics that occur between the four sorts that need to covered in the lab.

[TOC]

Modified Bubble Sort Approach

  • Typically O(n**2) and therefore good only for small data sets.

  • Most likely they are stable sorts - meaning they maintain the order in which equal elements appear in the list

Selection Sort

Insertion Sort

Divide and Conquer Approach

  • Typically O(n*logn) and therefore suitably for bigger data sets.

  • As in the case of Merge Sort, it requires additional space (so for real large sets, this can be a disadvantage). For Quick Sort, additional nlog(n) space is required.

  • Typically, as in the case of Quick Sort, they are also not stable sorts - the order of equal elements may not be maintained after the sort is complete

Merge Sort

Quick Sort

Clarifying Questions

  1. Which of the following sort algorithms are guaranteed to be O(n log n) even in the worst case?

  2. (A) Selection Sort

  3. (B) Quick Sort

  4. (C) Merge Sort

  5. (D) Insertion Sort

  6. Which takes the least amount of extra space for sorting to happen? Which takes the most amount of extra space?

  7. A. Selection Sort, Merge Sort

  8. B. Insertion Sort, Quick Sort

  9. C. Insertion Sort, Merge Sort

  10. D. None of the above combinations

  11. What is the correct order in terms of increased efficiency of sorting?

  12. A. Selection, Insertion, Quick and Merge

  13. B. Insertion, Selection, Merge and Quick

  14. C. Selection, Insertion, Merge and Quick

  15. D. None of the above

selection
insertion

Merge

split
partition1
partition2
http://bit.ly/sortsCompared
http://j.mp/mergeVsQuick
https://en.wikipedia.org/wiki/Sorting_algorithm#Comparison_of_algorithms
http://interactivepython.org/runestone/static/pythonds/SortSearch/TheSelectionSort.html
http://interactivepython.org/runestone/static/pythonds/SortSearch/TheInsertionSort.html
http://interactivepython.org/runestone/static/pythonds/SortSearch/TheMergeSort.html
http://interactivepython.org/runestone/static/pythonds/SortSearch/TheQuickSort.html
mergeA
mergeB