New discoveries during the exploration of sorting: How I got my thesis topic By Spencer Morgan Reference: Algorithms, Sequential, Parallel, and Distributed.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

1 AVL-Trees (Adelson-Velskii & Landis, 1962) In normal search trees, the complexity of find, insert and delete operations in search trees is in the worst.
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
Sorting Comparison-based algorithm review –You should know most of the algorithms –We will concentrate on their analyses –Special emphasis: Heapsort Lower.
Quicksort Quicksort     29  9.
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,
© 2004 Goodrich, Tamassia Quick-Sort     29  9.
Sorting Chapter Sorting Consider list x 1, x 2, x 3, … x n We seek to arrange the elements of the list in order –Ascending or descending Some O(n.
Chapter 19: Searching and Sorting Algorithms
1 Sorting Problem: Given a sequence of elements, find a permutation such that the resulting sequence is sorted in some order. We have already seen: –Insertion.
Quick-Sort     29  9.
© 2004 Goodrich, Tamassia Quick-Sort     29  9.
CS 171: Introduction to Computer Science II Quicksort.
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.
© 2006 Pearson Addison-Wesley. All rights reserved10-1 Chapter 10 Algorithm Efficiency and Sorting CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck.
CSC 2300 Data Structures & Algorithms March 27, 2007 Chapter 7. Sorting.
2 -1 Analysis of algorithms Best case: easiest Worst case Average case: hardest.
CHAPTER 11 Sorting.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
CSC 2300 Data Structures & Algorithms March 20, 2007 Chapter 7. Sorting.
The Complexity of Algorithms and the Lower Bounds of Problems
Mergesort and Quicksort Chapter 8 Kruse and Ryba.
MergeSort Source: Gibbs & Tamassia. 2 MergeSort MergeSort is a divide and conquer method of sorting.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
1 Time Analysis Analyzing an algorithm = estimating the resources it requires. Time How long will it take to execute? Impossible to find exact value Depends.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Chapter 19: Searching and Sorting Algorithms
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 9: Algorithm Efficiency and Sorting Data Abstraction &
Chapter 10 B Algorithm Efficiency and Sorting. © 2004 Pearson Addison-Wesley. All rights reserved 9 A-2 Sorting Algorithms and Their Efficiency Sorting.
CS261 – Recitation 5 Fall Outline Assignment 3: Memory and Timing Tests Binary Search Algorithm Binary Search Tree Add/Remove examples 1.
Heapsort. Heapsort is a comparison-based sorting algorithm, and is part of the selection sort family. Although somewhat slower in practice on most machines.
Data Structures Using C++ 2E Chapter 10 Sorting Algorithms.
MA/CSSE 473 Day 21 AVL Tree Maximum height 2-3 Trees Student questions?
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
1 Searching Searching in a sorted linked list takes linear time in the worst and average case. Searching in a sorted array takes logarithmic time in the.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
© 2006 Pearson Addison-Wesley. All rights reserved10 B-1 Chapter 10 (continued) Algorithm Efficiency and Sorting.
1 Sorting Algorithms Sections 7.1 to Comparison-Based Sorting Input – 2,3,1,15,11,23,1 Output – 1,1,2,3,11,15,23 Class ‘Animals’ – Sort Objects.
Sorting Chapter Sorting Consider list x 1, x 2, x 3, … x n We seek to arrange the elements of the list in order –Ascending or descending Some O(n.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Average Case Analysis.
Chapter 8 Sorting and Searching Goals: 1.Java implementation of sorting algorithms 2.Selection and Insertion Sorts 3.Recursive Sorts: Mergesort and Quicksort.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Sorting.
Sorting and Searching by Dr P.Padmanabham Professor (CSE)&Director
Tree Data Structures. Heaps for searching Search in a heap? Search in a heap? Would have to look at root Would have to look at root If search item smaller.
Sorting 1. Insertion Sort
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
SORTING AND ASYMPTOTIC COMPLEXITY Lecture 13 CS2110 – Fall 2009.
Computer Sciences Department1. Sorting algorithm 4 Computer Sciences Department3.
329 3/30/98 CSE 143 Searching and Sorting [Sections 12.4, ]
WHICH SEARCH OR SORT IS BETTER?. COMPARING ALGORITHMS Time efficiency refers to how long it takes an algorithm to run Space efficiency refers to the amount.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
Decision Trees DEFINITION: DECISION TREE A decision tree is a tree in which the internal nodes represent actions, the arcs represent outcomes of an action,
Data Structures Using C++ 2E
Sorting by Tammy Bailey
B+ Tree.
Data Structures Using C++ 2E
Parallel Sorting Algorithms
Divide and Conquer.
MergeSort Source: Gibbs & Tamassia.
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
Searching.
ITEC 2620M Introduction to Data Structures
Parallel Sorting Algorithms
Searching CLRS, Sections 9.1 – 9.3.
Algorithm Efficiency and Sorting
CMPT 225 Lecture 10 – Merge Sort.
Presentation transcript:

New discoveries during the exploration of sorting: How I got my thesis topic By Spencer Morgan Reference: Algorithms, Sequential, Parallel, and Distributed by K. Berman & J. Paul, Thompson Course Technology, 2005

Quicksort Partitions around an element and recursively sorts the partitioned sets Efficient in the average case on large data sets Thought to be not as efficient as insertion sort on small data sets some implementations of Quicksort will switch to insertion sort when the partition size is small

Trying to improve the secondary sort Use a binary search to identify where the element will end up to reducing the number of comparisons. BPInsert

Move the search to the center The average location in the list is in the middle. Keeping the sorted area in the center will lessen the amount of movement (or assignments). But elements near the center move back and forth often occupying temporarily their resulting location SMInsert

Treesort Keep track of where elements need to go to avoid unnecessary moves back and forth. What resulted is a version of treesort where: 1. elements are added to a tree, and, 2. a map of where each element will end up is created, and 3. the map is processed putting the elements where they will end up

A major improvement Separating the assignments from the comparisons allows the two processes to be analyzed and improved independently.

Lower bound for worst-case complexity of comparison Lower bound for worst-case complexity of compares of any comparison- based sorting algorithm is log 2 n! or Ω(n log n). Proposition page 99 of Algorithms by Berman & Paul.

Lower bound for worst-case complexity of assignments Lower bound for worst-case complexity of assigns of any in-place sorting algorithm is Integer(3n/2). Worst-case will have all elements out of place To help conceptualize this, let’s consider different cases

2 Elements If there are two elements, three assignments are required: One to temp, one direct, and one from temp to temp 1 direct 1 from temp 2

3 Elements With three elements four assignments are required: One to temp, two direct, and one from temp to temp 1 direct 1 from temp direct 4

Define Circuit I define a circuit as: two or more out- of-place elements that that can be put into place with only one assignment to and from a temporary location If there are n elements in a circuit, the optimal number of assignments will be n+1 to put them in place The 2 & 3 element cases are each 1 circuit

Lower bound for assignments The lower bound for assignments is the number of elements out of place + the number of circuits.

More Elements With 4 elements out of place the worst-case is when there are 2 circuits of 2 elements (requiring 6 assignments). The worst case for assignments is when: 1. all elements are out of place, and 2. the number of circuits is maximized (because each circuit requires an extra assignment).

Lower bound for worst-case complexity of assignments The maximum number of circuits for any data set is Integer(n/2). The lower bound for assignments in the worst-case is n + Integer(n/2) or Integer(3n/2). This is significantly less than the lower bound of comparisons (n log n).

Equal elements Equal elements can allow more efficient assignments if the sort is not stable. This means equal elements do not have to keep the same position relative to each other The stable ordering has 2 circuits: (2 1,1) and (3 1,3 2,2 2 ) which requires 7 assignments to put in- place Spencer-Stable w/5

Improvements If some elements are already in a valid location (3 2 in our example) there is no need to move them. So we could leave them where they are This unstable ordering has 2 circuits: (2 1,1) and (3 1, 2 2 ) which requires 6 assignments to put in- place Spencer-Unstable w/5

Optimal Assignments Connecting circuits among equal elements will reduce comparisons This unstable ordering has 1 circuit: (2 1,1,3 1, 2 2 ) which requires 5 assignments Spencer-Optimal w/5

Possible Problems Optimal assignments have been attained But treesort has worst-case comparisons of order n 2

Alter the order of entry Add the center element and recursively add the left and right elements (the tree will be balanced with ordered data sets). Worst-case complexity is still n 2 comparisons; but the chances of having a data set like that in practice are reduced. Spencer not sequential

Splay Tree A splay tree can make comparisons more efficient (with even partially ordered data) by doing rotations to move the most recently accessed element to the root. But this can result in n 2 comparisons and rotations. Splay Killer

Splay 1 If only the first element is rotated some patterns can still be identified but with half the compares in our extreme case. But this is still poor performance and only has benefits over a regular tree in isolated cases. Splay1

Splay/2 only rotates every other node allows greater restructuring of the splay tree than Splay1 but only half as much as Splay Splay/2

Is the tree necessary? Since using the tree was what originally allowed me to dissociate the assignments for the comparisons, to this point, I have focused on using them But since the comparisons are now isolated from the assignments that constraint is not necessary

Mergesort Use a non-in-place (linked list) version of mergesort as the comparison step But this version of mergesort is stable and does not provide the necessary information about equal elements to achieve optimal assignments (or comparisons) BPMerge & Spencer-BPMerge

Improved Mergesort Use a version of mergesort that keeps track of equal elements If all elements are unique, it will have the same number of comparisons If there are equal elements, there can be a reduction of comparisons to as little as n-1. SMerge