Lists and Sorting Algorithms

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

Sorting CMSC 201. Sorting In computer science, there is often more than one way to do something. Sorting is a good example of this!
Sorting A fundamental operation in computer science (many programs need to sort as an intermediate step). Many sorting algorithms have been developed Choose.
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
CPS120: Introduction to Computer Science Searching and Sorting.
HST 952 Computing for Biomedical Scientists Lecture 9.
QuickSort 4 February QuickSort(S) Fast divide and conquer algorithm first discovered by C. A. R. Hoare in If the number of elements in.
ISOM MIS 215 Module 7 – Sorting. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Data Structures Data Structures Topic #13. Today’s Agenda Sorting Algorithms: Recursive –mergesort –quicksort As we learn about each sorting algorithm,
CMPS1371 Introduction to Computing for Engineers SORTING.
Sorting Algorithms What is it: An algorithm that puts the elements of a list in a certain order.
Ver. 1.0 Session 5 Data Structures and Algorithms Objectives In this session, you will learn to: Sort data by using quick sort Sort data by using merge.
Searching and Sorting Topics  Sequential Search on an Unordered File  Sequential Search on an Ordered File  Binary Search  Bubble Sort  Insertion.
CS 206 Introduction to Computer Science II 12 / 09 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 12 / 05 / 2008 Instructor: Michael Eckmann.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/23/2009.
CS 280 Data Structures Professor John Peterson. Project Questions?
Sorting Chapter 10.
Selection Sort, Insertion Sort, Bubble, & Shellsort
Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
Illuminating Computer Science CCIT 4-6Sep
Week 11 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Sorting HKOI Training Team (Advanced)
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
Sorting Chapter 10. Chapter Objectives  To learn how to use the standard sorting methods in the Java API  To learn how to implement the following sorting.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
Simple Iterative Sorting Sorting as a means to study data structures and algorithms Historical notes Swapping records Swapping pointers to records Description,
Adapted from instructor resource slides Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All.
Sorts Tonga Institute of Higher Education. Introduction - 1 Sorting – The act of ordering data Often, we need to order data.  Example: Order a list of.
Fundamentals of Algorithms MCS - 2 Lecture # 15. Bubble Sort.
Comparison of Optimization Algorithms By Jonathan Lutu.
New Mexico Computer Science For All Sorting Algorithms Maureen Psaila-Dombrowski.
COMP 1001: Introduction to Computers for Arts and Social Sciences Sorting Algorithms Wednesday, June 1, 2011.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Sorting and Searching by Dr P.Padmanabham Professor (CSE)&Director
Data Structures - CSCI 102 Selection Sort Keep the list separated into sorted and unsorted sections Start by finding the minimum & put it at the front.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
ICS201 Lecture 21 : Sorting King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department.
Sorting. Sorting Sorting is important! Things that would be much more difficult without sorting: –finding a telephone number –looking up a word in the.
Sorting Fundamental Data Structures and Algorithms Aleks Nanevski February 17, 2004.
Lists and Sorting Algorithms Exploring Computer Science – Lesson 2-7.
CPS120: Introduction to Computer Science Sorting.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Assignment 5 is posted. Exercise 8 is very similar to what you will be doing with assignment 5. Exam.
CPS120: Introduction to Computer Science Sorting.
Sort Algorithm.
CMSC201 Computer Science I for Majors Lecture 23 – Sorting
IGCSE 6 Cambridge Effectiveness of algorithms Computer Science
Lists and Sorting Algorithms
Sorting Algorithms.
Quick-Sort 9/13/2018 1:15 AM Quick-Sort     2
CSE 143 Lecture 23: quick sort.
Mergesort: The power of divide and conquer
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Binary Search Back in the days when phone numbers weren’t stored in cell phones, you might have actually had to look them up in a phonebook. How did you.
2008/12/03: Lecture 20 CMSC 104, Section 0101 John Y. Park
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
8/04/2009 Many thanks to David Sun for some of the included slides!
slides adapted from Marty Stepp
Sorting "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting Hat, Harry Potter.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CPS120: Introduction to Computer Science
Quick-Sort 4/25/2019 8:10 AM Quick-Sort     2
Data Structures & Algorithms
CPS120: Introduction to Computer Science
Sorting Algorithms 2.1 – Algorithms.
Mod 3 Lesson 2 Me First! Sorting
Design and Analysis of Algorithms
Presentation transcript:

Lists and Sorting Algorithms Exploring Computer Science – Lesson 2-7

Objectives The students will be able to: Define sorted and unsorted lists. Describe various sorting algorithms. Compare various sorting algorithms.

Journal Entry List examples of where it matters whether items in a list are in order. 5 minutes

Sorting – Part 1 – Finding the Lowest Weight Mix them up so that you no longer know the order of the weights. Find the lightest weight. What is the easiest way of doing this? How many comparisons does it take?

Sorting – Part 2 – Sorting 3 Weights Choose 3 weights at random and sort them into order from lightest to heaviest using only the scales. How did you do this? What is the minimum number of comparisons you can make? Why?

Rules for Remaining Sorts Each sorting algorithm will done 3 times. Pick a person to count the number of comparisons. That person will count the comparisons for all three of times that sort is performed. A different person will do the counting for the next sorting algorithm. Each of the remaining members of the group will do one of the three times that sort is performed.

Sorting – Part 3 – Selection Sort One method a computer might use is called selection sort. This is how selection sort works. First find the lightest weight in the set and put it to one side. Next, find the lightest of the weights that are left, and put it next to the first one. Repeat this until all the weights have been moved. How many comparison did it take to sort the bags? Record the result. Mix up the bags and do this two more times. Record how many comparisons it takes to sort the bags.

Sorting – Part 4 – Quicksort Quicksort is a lot faster than selection sort, particularly for larger lists. In fact, it is one of the best methods known. Choose one of the objects at random and compare each of the remaining objects with it. Put those that are lighter on the left, the chosen object in the middle, and the heavier ones on the right. Choose one of the groups and repeat this procedure. Do the same for the other group. Remember to keep the one you know in the center. Keep repeating this procedure on the remaining groups until no group has more than one object in it. Once all the groups have been divided down to single objects, the objects will be in order from lightest to heaviest. How many comparison did it take to sort the bags? Record the result. Mix up the bags and do this two more times. Record how many comparisons it takes to sort the bags.

Sorting – Part 5 – Bubble Sort Bubble sort involves going through the list again and again. Start with the first 2 bags. If they are in the wrong order than switch them. Now compare bags 2 and 3. If they are in the wrong order than switch them. Keep swapping any bags side-by-side that are in the wrong order. The list is sorted when no swaps occur during a pass through the list. How many comparison did it take to sort the bags? Record the result. Mix up the bags and do this two more times. Record how many comparisons it takes to sort the bags.

Sorting – Part 6 - Summary Complete the to questions in part 6 of the homework. Turn this in (1 per group) before you leave today.

Why is this important? Information is much easier to find in a sorted list. Telephone directories, dictionaries and book indexes all use alphabetical order, and life would be far more difficult if they didn’t. If a list of numbers (such as a list of expenses) is sorted into order, the extreme cases are easy to see because they are at the beginning and end of the list. Duplicates are also easy to find, because they end up together. Computers spend a lot of their time sorting things into order, so computer scientists have to find fast and efficient ways of doing this. Some of the slower methods such as insertion sort, selection sort and bubble sort can be useful in special situations, but the fast ones such as quicksort are usually used.

Why is this important? Quicksort uses a concept called recursion. This means you keep dividing a list into smaller parts, and then performing the same kind of sort on each of the parts. This particular approach is called divide and conquer. The list is divided repeatedly until it is small enough to conquer. For quicksort, the lists are divided until they contain only one item. It is trivial to sort one item into order! Although this seems very involved, in practice it is dramatically faster than other methods.