3.3 Fundamentals of data representation

Slides:



Advertisements
Similar presentations
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
Advertisements

Practice Quiz Question
Sorting A fundamental operation in computer science (many programs need to sort as an intermediate step). Many sorting algorithms have been developed Choose.
Chapter 9: Searching, Sorting, and Algorithm Analysis
CPS120: Introduction to Computer Science Searching and Sorting.
1 Divide & Conquer Algorithms. 2 Recursion Review A function that calls itself either directly or indirectly through another function Recursive solutions.
CMPS1371 Introduction to Computing for Engineers SORTING.
CHAPTER 11 Sorting.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
Sorting and Searching Arrays CSC 1401: Introduction to Programming with Java Week 12 – Lectures 1 & 2 Wanda M. Kunkle.
ALGORITHM ANALYSIS AND DESIGN INTRODUCTION TO ALGORITHMS CS 413 Divide and Conquer Algortihms: Binary search, merge sort.
Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.
1 Decrease-and-Conquer Approach Lecture 06 ITS033 – Programming & Algorithms Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing.
Sorting HKOI Training Team (Advanced)
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified for use by MSU Dept. of Computer Science.
New Mexico Computer Science For All Sorting Algorithms Maureen Psaila-Dombrowski.
Chapter 8 Sorting and Searching Goals: 1.Java implementation of sorting algorithms 2.Selection and Insertion Sorts 3.Recursive Sorts: Mergesort and Quicksort.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
Chapter 9 Sorting. The efficiency of data handling can often be increased if the data are sorted according to some criteria of order. The first step is.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
CPS120: Introduction to Computer Science Sorting.
Sorting Algorithms Written by J.J. Shepherd. Sorting Review For each one of these sorting problems we are assuming ascending order so smallest to largest.
CMPT 238 Data Structures More on Sorting: Merge Sort and Quicksort.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 23 Sorting.
OCR A Level F453: Data structures and data manipulation Data structures and data manipulation a. explain how static data structures may be.
CPS120: Introduction to Computer Science Sorting.
Searching and Sorting Searching algorithms with simple arrays
Chapter 23 Sorting Jung Soo (Sue) Lim Cal State LA.
Advanced Sorting.
Sort Algorithm.
Lecture 25: Searching and Sorting
Introduction to Algorithms: Divide-n-Conquer Algorithms
3.3 Fundamentals of data representation
Alternate Version of STARTING OUT WITH C++ 4th Edition
Searching and Sorting Algorithms
Subject Name: Design and Analysis of Algorithm Subject Code: 10CS43
3.3 Fundamentals of data representation
Decrease-and-Conquer Approach
Introduction to Search Algorithms
Warmup What is an abstract class?
Section 10.3a Merge Sort.
Sorting Chapter 13 presents several common algorithms for sorting an array of integers. Two slow but simple algorithms are Selectionsort and Insertionsort.
Lesson Objectives Aims Understand the following “standard algorithms”:
3.3 Fundamentals of data representation
Teach A level Computing: Algorithms and Data Structures
Divide-and-Conquer The most-well known algorithm design strategy:
Sorting Algorithms Written by J.J. Shepherd.
Bubble Sort Bubble sort is one way to sort an array of numbers. Adjacent values are swapped until the array is completely sorted. This algorithm gets its.
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.
Unit-2 Divide and Conquer
Welcome to CIS 068 ! Lesson 9: Sorting CIS 068.
“Human Sorting” It’s a “Problem Solving” game:
Sorting Algorithms Ellysa N. Kosinaya.
MSIS 655 Advanced Business Applications Programming
IT 4043 Data Structures and Algorithms
Divide-and-Conquer The most-well known algorithm design strategy:
Principles of Computing – UFCFA3-30-1
Sorting Chapter 13 presents several common algorithms for sorting an array of integers. Two slow but simple algorithms are Selectionsort and Insertionsort.
Chapter 4.
Analysis of Algorithms
CPS120: Introduction to Computer Science
Divide & Conquer Algorithms
CPS120: Introduction to Computer Science
CSC 380: Design and Analysis of Algorithms
CSCE 3110 Data Structures & Algorithm Analysis
CSCE 3110 Data Structures & Algorithm Analysis
Principles of Computing – UFCFA3-30-1
Core Assessments Core #1: This Friday (5/4) Core #2: Tuesday, 5/8.
“Human Sorting” It’s a “Problem Solving” game:
Quick Sort & Merge Sort Technique
Presentation transcript:

3.3 Fundamentals of data representation 3.1.4 Sorting algorithms 2 Lesson

Objectives Understand and explain how the merge sort algorithm works. Compare and contrast merge sort and bubble sort algorithms.

Introduction to the merge sort In the previous lesson, we looked at the idea of applying the bubble sort algorithm when ordering datasets. We concluded that the bubble sort was a simple but inefficient algorithm. Now we are going to look at a related but more sophisticated algorithm – the ‘merge sort’. youtube.com/watch?v=XaqR3G_NVoo&nohtml5=False Watch video from 0:20 minutes to 2:15 minutes. Note: there are an odd number of female dancers to sort.

How does a merge sort work? A merge sort is a method of arranging data by splitting a list into discrete elements and merging the elements together until an ordered list is obtained. Merge sorts are classed as as ‘divide-and-conquer’ algorithms. Divide (the problem into a small number of pieces), Conquer (solve each piece, by repeatedly applying divide-and-conquer to it), Combine (the pieces together into a solution).

Visual demonstration of a merge sort youtube.com/watch?v=HsZ-YRQM8sE&nohtml5=False Watch video from 0:40 minutes to 2:26 minutes.

Merge sorts We will stick to examples where an even number of elements are sorted. The merge sort starts off by repeatedly splitting the array in half until there are only individual elements left. Array 5 8 4 2 19 34 56 7 Split 5 8 4 2 19 34 56 7 Split 5 8 4 2 19 34 56 7 5 8 4 2 5 8 4 2

Merge sorts It is helpful to view the elements vertically for the next step. Merging occurs by making a ‘bottom up’ comparison and swapping values. 5 5 8 8 Now try Quiz 1 2 4 5 8 4 2 4 2 2 4 5 7 8 19 34 56 19 19 34 34 Note that for GCSE, it is not necessary to know how the more complex sorts are actioned. 7 19 34 56 56 7 56 7

Merge sorts Our example is a simple one – the array contained just eight elements and is easily split into pairs. The full algorithm must cope with the possibility of odd numbers of array elements, of much larger arrays and numbers which do not easily split into pairs. As with the searching algorithms, a more complex process requires fewer steps to complete than the simpler but more basic alternatives. The binary search involves bisecting a dataset until a match is made and a similar process occurs here in the merge sort.

Merge sorts We talk about the recursive operation of components of the underlying algorithm, i.e. it repeats itself where required. Recursive programming can consume a lot of memory and that is the price paid for having a more efficient algorithm.

Comparing sorting algorithms A quick review of the two sorting algorithms that we have seen in use so far. Bubble Merge What comparisons might be made of these two techniques?

Comparing sorting algorithms Bubble Advantages Mechanism easier to comprehend. Disadvantages Inefficient - uses ‘blunt’ approach’ to sorting with the number of iterations required rapidly expanding as the size of the data to be sorted grows. Merge Very quick in comparison to the bubble sort technique. More complex algorithm but relies on a recursive algorithm which can consume large amounts of memory.

To round things off… That brings us to the end of two separate topics – Searching Sorting Both of which have exhibited similar characteristics in that a clear trade-off between the efficiency and complexity of the underlying processes can be demonstrated. Now complete Quiz 1 in order to round off this final lesson.