SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
Advanced Topics in Sorting



                                                               ‣    selection
                                                               ‣    duplicate keys
                                                               ‣    system sorts
                                                               ‣    comparators



Reference:   http://www.cs.princeton.edu/algs4                  Except as otherwise noted, the content of this presentation
                                                                is licensed under the Creative Commons Attribution 2.5 License.




Algorithms in Java, 4th Edition   · Robert Sedgewick and Kevin Wayne · Copyright © 2008             ·       May 2, 2008 10:45:30 AM
Selection


Goal. Find the kth largest element.
Ex. Min (k = 0), max (k = N-1), median (k = N/2).


Applications.
•   Order statistics.
•   Find the “top k.”


Use theory as a guide.
•   Easy O(N log N) upper bound.
•   Easy O(N) upper bound for k = 1, 2, 3.
•   Easy Ω(N) lower bound.


Which is true?
•   Ω(N log N) lower bound?           is selection as hard as sorting?

•   O(N) upper bound?                 is there a linear-time algorithm for all k?




                                                                                    2
Quick-select


Partition array so that:
•   Element a[i] is in place.
•   No larger element to the left of i.
•   No smaller element to the right of i.


Repeat in one subarray, depending on i; finished when i equals k.


        public static Comparable select(Comparable[] before int k)
                                                      a,                                               v
        {
                                                             lo                                        hi
            StdRandom.shuffle(a);
            int lo = 0, hi = a.length - 1;
            while (hi > lo)                                  if a[k] is here,       if a[k] is here,
            {                                                   set hi to i-1         set lo to i+1
                int i = partition(a, lo, hi);
                if      (i < k) lo = i + 1;                  after        v     v             v
                else if (i > k) hi = i - 1;
                else            return a[k];                         lo         i                      hi

            }
            return a[k];
        }


                                                                                                            3
Quick-select: mathematical analysis


Proposition. Quick-select takes linear time on average.
Pf sketch.
•   Intuitively, each partitioning step roughly splits array in half:
    N + N/2 + N/4 + … + 1 ~ 2N compares.
•   Formal analysis similar to quicksort analysis yields:

             CN = 2 N + k ln ( N / k) + (N - k) ln (N / (N - k))




Ex. (2 + 2 ln 2) N compares to find the median.




Remark. Quick-select might use ~ N2/2 compares, but as with quicksort,
the random shuffle provides a probabilistic guarantee.


                                                                         4
Theoretical context for selection


Challenge. Design a selection algorithm whose running time is linear in the
worst-case.


Theorem. [Blum, Floyd, Pratt, Rivest, Tarjan, 1973] There exists a compare-
based selection algorithm that takes linear time in the worst case.

Remark. Algorithm is too complicated to be useful in practice.




Use theory as a guide.
•   Still worthwhile to seek practical linear-time (worst-case) algorithm.
•   Until one is discovered, use quick-select if you don’t need a full sort.




                                                                               5
Generic methods


In our select() implementation, client needs a cast.


        Double[] a = new Double[N];
        for (int i = 0; i < N; i++)
           a[i] = StdRandom.uniform();
                                                                hazardous cast
        Double median = (Double) Quick.select(a, N/2);
                                                                required




The compiler is also unhappy.


        % javac Quick.java
        Note: Quick.java uses unchecked or unsafe operations.
        Note: Recompile with -Xlint:unchecked for details.




Q. How to fix?
                                                                                 6
Generic methods


Safe version. Compiles cleanly, no cast needed in client.


 public class Quick         generic type variable
 {                          (value inferred from argument a[])
     public static <Key extends Comparable<Key>> Key select(Key[] a, int k)
     { /* as before */ }

                                                      return type matches array type
     public static <Key extends Comparable<Key>> void sort(Key[] a)
     { /* as before */ }

     private static <Key extends Comparable<Key>> int partition(Key[] a, int lo, int hi)
     { /* as before */ }

     private static <Key extends Comparable<Key>> boolean less(Key v, Key w)
     { /* as before */ }

     private static <Key extends Comparable<Key>> void exch(Key[] a, int i, int j)
     { Key swap = a[i]; a[i] = a[j]; a[j] = swap; }

 }            can declare variables of generic type




Remark. Obnoxious code needed in system sort; not in this course (for brevity).
                                                                                           7
‣   selection
‣   duplicate keys
‣   comparators
‣   applications




                     8
Duplicate keys


Often, purpose of sort is to bring records with duplicate keys together.
•   Sort population by age.
•   Find collinear points.        see Assignment 3

•   Remove duplicates from mailing list.
•   Sort job applicants by college attended.
                                                     sorted by time       sorted by city (unstable)              sorted by cit
                                                 Chicago 09:00:00        Chicago 09:25:52                      Chicago 09
Typical characteristics of such applications.    Phoenix 09:00:03
                                                 Houston 09:00:13
                                                                         Chicago 09:03:13
                                                                         Chicago 09:21:05
                                                                                                               Chicago 09
                                                                                                               Chicago 09

•   Huge file.
                                                 Chicago 09:00:59
                                                 Houston 09:01:10
                                                                         Chicago 09:19:46
                                                                         Chicago 09:19:32
                                                                                                               Chicago 09
                                                                                                               Chicago 09

•
                                                 Chicago 09:03:13        Chicago 09:00:00                      Chicago 09
    Small number of key values.                  Seattle 09:10:11        Chicago 09:35:21                      Chicago 09
                                                 Seattle 09:10:25        Chicago 09:00:59                      Chicago 09
                                                 Phoenix 09:14:25        Houston 09:01:10                      Houston 09
                                                 Chicago 09:19:32        Houston 09:00:13             NOT      Houston 09
                                                 Chicago 09:19:46        Phoenix 09:37:44             sorted   Phoenix 09
                                                 Chicago 09:21:05        Phoenix 09:00:03                      Phoenix 09
                                                 Seattle 09:22:43        Phoenix 09:14:25                      Phoenix 09
                                                 Seattle 09:22:54        Seattle 09:10:25                      Seattle 09
                                                 Chicago 09:25:52        Seattle 09:36:14                      Seattle 09
                                                 Chicago 09:35:21        Seattle 09:22:43                      Seattle 09
                                                 Seattle 09:36:14        Seattle 09:10:11                      Seattle 09
                                                 Phoenix 09:37:44        Seattle 09:22:54                      Seattle 09

                                                                      Stability when sorting on a second key
                                                                            key

                                                                                                               9
Duplicate keys


Mergesort with duplicate keys. Always ~ N lg N compares.


Quicksort with duplicate keys.
•   Algorithm goes quadratic unless partitioning stops on equal keys!
•   1990s C user found this defect in qsort().


                                 several textbook and system implementations
                                 also have this defect




                                                                               10
Duplicate keys: the problem


Assume all keys are equal. Recursive code guarantees this case predominates!


Mistake. Put all keys equal to the partitioning element on one side.
Consequence. ~ N2 / 2 compares when all keys equal.

      B A A B A B B B C C C                  A A A A A A A A A A A




Recommended. Stop scans on keys equal to the partitioning element.
Consequence. ~ N lg N compares when all keys equal.

      B A A B A B C C B C B                  A A A A A A A A A A A




Desirable. Put all keys equal to the partitioning element in place.
      A A A B B B B B C C C                  A A A A A A A A A A A
                                                                               11
3-way partitioning


Goal. Partition array into 3 parts so that:
•   Elements between lt and gt equal to partition element v.
•   No larger elements to left of lt.
•   No smaller elements to right of gt.



                  before   v

                           lo                             hi



                   after        <v         =v        >v

                           lo        lt         gt        hi

                                3-way partitioning


Dutch national flag problem. [Edsger Dijkstra]
•   Convention wisdom until mid 1990s: not worth doing.
•   New approach discovered when fixing mistake in C library qsort().
•   Now incorporated into qsort() and Java system sort.
                                                                        12
3-way partitioning: Dijkstra's solution


3-way partitioning.
•   Let v be partitioning element a[lo].
•   Scan i from left to right.
    - a[i] less than v : exchange a[lt] with a[i] and increment both lt and i
    - a[i] greater than v : exchange a[gt] with a[i] and decrement gt
    - a[i] equal to v : increment i


                                            before   v

All the right properties.                            lo                                          hi



•
                                            during        <v        =v                      >v
    In-place.
•
                                                                  lt     i             gt
    Not much code.                                                                          >v
                                             after         <v                =v
•   Small overhead if no equal keys.                 lo            lt             gt             hi

                                                               3-way partitioning




                                                                                                      13
3-way partitioning: trace




                        v                          a[]
            lt    i   gt      0   1   2   3   4   5 6     7   8   9 10 11
             0    0   11      R   B   W   W   R   W   B   R   R   W   B   R
             0    1   11      R   B   W   W   R   W   B   R   R   W   B   R
             1    2   11      B   R   W   W   R   W   B   R   R   W   B   R
             1    2   10      B   R   R   W   R   W   B   R   R   W   B   W
             1    3   10      B   R   R   W   R   W   B   R   R   W   B   W
             1    3    9      B   R   R   B   R   W   B   R   R   W   W   W
             2    4    9      B   B   R   R   R   W   B   R   R   W   W   W
             2    5    9      B   B   R   R   R   W   B   R   R   W   W   W
             2    5    8      B   B   R   R   R   W   B   R   R   W   W   W
             2    5    7      B   B   R   R   R   R   B   R   W   W   W   W
             2    6    7      B   B   R   R   R   R   B   R   W   W   W   W
             3    7    7      B   B   B   R   R   R   R   R   W   W   W   W
             3    8    7      B   B   B   R   R   R   R   R   W   W   W   W
           3-way partitioning trace (array contents after each loop iteration)




                                                                                 14
3-way quicksort: Java implementation



  private static void sort(Comparable[] a, int lo, int hi)
  {
     if (hi <= lo) return;
     int lt = lo, gt = hi;
     Comparable v = a[lo];
     int i = lo;
     while (i <= gt)
                                                    before  v
     {
                                                           lo                                      hi
        int cmp = a[i].compareTo(v);
                                                   during     <v      =v                      >v
        if       (cmp < 0) exch(a, lt++, i++);
                                                                     lt    i             gt
        else if (cmp > 0) exch(a, i, gt--);
                                                     after      <v             =v             >v
        else               i++;
                                                           lo         lt            gt             hi
     }
                                                                3-way partitioning

      sort(a, lo, lt - 1);
      sort(a, gt + 1, hi);
  }




                                                                                                        15
3-way quicksort: visual trace




              equal to partitioning element




                         Visual trace of quicksort with 3-way partitioning




                                                                             16
Duplicate keys: lower bound


Proposition. [Sedgewick-Bentley, 1997] Quicksort with 3-way partitioning
is entropy-optimal.


Pf. [beyond scope of course]
•   Generalize decision tree.
•   Tie cost to Shannon entropy.


Ex. Linear-time when only a constant number of distinct keys.


Bottom line. Randomized quicksort with 3-way partitioning reduces running
time from linearithmic to linear in broad class of applications.




                                                                            17
‣   selection
‣   duplicate keys
‣   comparators
‣   applications




                     18
Natural order


Comparable interface: sort uses type’s natural order.


     public class Date implements Comparable<Date>
     {
        private final int month, day, year;

         public Date(int m, int d, int y)
         {
            month = m;
            day   = d;
            year = y;
         }
         …
         public int compareTo(Date that)
         {
            if (this.year < that.year ) return    -1;
            if (this.year > that.year ) return    +1;
            if (this.month < that.month) return   -1;   natural order
            if (this.month > that.month) return   +1;
            if (this.day   < that.day ) return    -1;
            if (this.day   > that.day ) return    +1;
            return 0;
         }
     }


                                                                        19
Generalized compare


Comparable interface: sort uses type’s natural order.


Problem 1. May want to use a non-natural order.
Problem 2. Desired data type may not come with a “natural” order.


Ex. Sort strings by:
•
                                                       pre-1994 order for digraphs
    Natural order.            Now is the time          ch and ll and rr

•   Case insensitive.         is Now the time

•   Spanish.                  café cafetero cuarto churro nube ñoño

•   British phone book.       McKinley Mackintosh


      String[] a;
      ...
      Arrays.sort(a);
      Arrays.sort(a, String.CASE_INSENSITIVE_ORDER);
      Arrays.sort(a, Collator.getInstance(Locale.SPANISH));


                          import java.text.Collator;
                                                                                     20
Comparators


Solution. Use Java's Comparator interface.


                 public interface Comparator<Key>
                 {
                    public int compare(Key v, Key w);
                 }




Remark. The compare() method implements a total order like compareTo().



Advantages. Decouples the definition of the data type from the
definition of what it means to compare two objects of that type.
•   Can add any number of new orders to a data type.
•   Can add an order to a library data type with no natural order.



                                                                          21
Comparator example


Reverse order. Sort an array of strings in reverse order.



      public class ReverseOrder implements Comparator<String>
      {
         public int compare(String a, String b)
         {
             return b.compareTo(a);
         }
      }


     comparator implementation




              ...
              Arrays.sort(a, new ReverseOrder());
              ...

     client



                                                                22
Sort implementation with comparators


To support comparators in our sort implementations:
•   Pass Comparator to sort() and less().
•   Use it in less().

                                             type variable
Ex. Insertion sort.                          (not necessarily Comparable)



          public static <Key> void sort(Key[] a, Comparator<Key> comparator)
          {
             int N = a.length;
             for (int i = 0; i < N; i++)
                for (int j = i; j > 0; j--)
                   if (less(comparator, a[j], a[j-1]))
                        exch(a, j, j-1);
                   else break;
          }

          private static <Key> boolean less(Comparator<Key> c, Key v, Key w)
          { return c.compare(v, w) < 0;    }

          private static <Key> void exch(Key[] a, int i, int j)
          { Key swap = a[i]; a[i] = a[j]; a[j] = swap; }


                                                                               23
Generalized compare


Comparators enable multiple sorts of a single file (by different keys).


Ex. Sort students by name or by section.

               Arrays.sort(students, Student.BY_NAME);
               Arrays.sort(students, Student.BY_SECT);



sort by name                                             then sort by section



  Andrews      3   A   664-480-0023    097 Little      Fox       1    A     884-232-5341   11 Dickinson

   Battle      4   C   874-088-1212   121 Whitman     Chen       2    A     991-878-4944    308 Blair

    Chen       2   A   991-878-4944    308 Blair     Andrews     3    A     664-480-0023    097 Little

    Fox        1   A   884-232-5341   11 Dickinson    Furia      3    A     766-093-9873    101 Brown

    Furia      3   A   766-093-9873    101 Brown     Kanaga      3    B     898-122-9643    22 Brown

    Gazsi      4   B   665-303-0266    22 Brown       Rohde      3    A     232-343-5555   343 Forbes

   Kanaga      3   B   898-122-9643    22 Brown      Battle      4    C     874-088-1212   121 Whitman

   Rohde       3   A   232-343-5555   343 Forbes      Gazsi      4    B     665-303-0266    22 Brown



                                                                                                          24
Generalized compare


Ex. Enable sorting students by name or by section.



     public class Student
     {
        public static final Comparator<Student> BY_NAME = new ByName();
        public static final Comparator<Student> BY_SECT = new BySect();

         private final String name;
         private final int section;
         ...
         private static class ByName implements Comparator<Student>
         {
             public int compare(Student a, Student b)
             { return a.name.compareTo(b.name); }
         }

         private static class BySect implements Comparator<Student>
         {
            public int compare(Student a, Student b)
            { return a.section - b.section; }
         }
     }                             only use this trick if no danger of overflow



                                                                                  25
Generalized compare problem


 A typical application. First, sort by name; then sort by section.



Arrays.sort(students, Student.BY_NAME);                 Arrays.sort(students, Student.BY_SECT);




   Andrews    3   A    664-480-0023    097 Little      Fox     1   A    884-232-5341   11 Dickinson

    Battle    4   C    874-088-1212   121 Whitman     Chen     2   A    991-878-4944    308 Blair

     Chen     2   A    991-878-4944    308 Blair     Kanaga    3    B   898-122-9643    22 Brown

     Fox      1   A    884-232-5341   11 Dickinson   Andrews   3   A    664-480-0023    097 Little

     Furia    3   A    766-093-9873    101 Brown      Furia    3   A    766-093-9873    101 Brown

    Gazsi     4   B    665-303-0266    22 Brown       Rohde    3   A    232-343-5555   343 Forbes

    Kanaga    3   B    898-122-9643    22 Brown      Battle    4    C   874-088-1212   121 Whitman

    Rohde     3   A    232-343-5555   343 Forbes      Gazsi    4    B   665-303-0266    22 Brown




 @#%&@!!. Students in section 3 no longer in order by name.


 A stable sort preserves the relative order of records with equal keys.
                                                                                                      26
Stability


Q. Which sorts are stable?
•   Selection sort?
•   Insertion sort?
•   Shellsort?
•   Quicksort?               sorted by time
                         Chicago 09:00:00
                                                  sorted by city (unstable)
                                                 Chicago 09:25:52
                                                                                         sorted by city (stable)
                                                                                       Chicago 09:00:00

•
                         Phoenix 09:00:03        Chicago 09:03:13                      Chicago 09:00:59
    Mergesort?           Houston 09:00:13        Chicago 09:21:05                      Chicago 09:03:13
                         Chicago 09:00:59        Chicago 09:19:46                      Chicago 09:19:32
                         Houston 09:01:10        Chicago 09:19:32                      Chicago 09:19:46
                         Chicago 09:03:13        Chicago 09:00:00                      Chicago 09:21:05
                         Seattle 09:10:11        Chicago 09:35:21                      Chicago 09:25:52
                         Seattle 09:10:25        Chicago 09:00:59                      Chicago 09:35:21
                         Phoenix 09:14:25        Houston 09:01:10                      Houston 09:00:13
                         Chicago 09:19:32        Houston 09:00:13             NOT      Houston 09:01:10            sorted
                         Chicago 09:19:46        Phoenix 09:37:44             sorted   Phoenix 09:00:03
                         Chicago 09:21:05        Phoenix 09:00:03                      Phoenix 09:14:25
                         Seattle 09:22:43        Phoenix 09:14:25                      Phoenix 09:37:44
                         Seattle 09:22:54        Seattle 09:10:25                      Seattle 09:10:11
                         Chicago 09:25:52        Seattle 09:36:14                      Seattle 09:10:25
                         Chicago 09:35:21        Seattle 09:22:43                      Seattle 09:22:43
                         Seattle 09:36:14        Seattle 09:10:11                      Seattle 09:22:54
                         Phoenix 09:37:44        Seattle 09:22:54                      Seattle 09:36:14

                                              Stability when sorting on a second key




Open problem. Stable, inplace, N log N, practical sort??
                                                                                                                            27
‣   selection
‣   duplicate keys
‣   comparators
‣   system sort




                     28
Sorting applications


Sorting algorithms are essential in a broad variety of applications:
•   Sort a list of names.
•   Organize an MP3 library.
•   Display Google PageRank results.                 obvious applications

•   List RSS news items in reverse chronological order.


•   Find the median.
•   Find the closest pair.
•   Binary search in a database.                     problems become easy once items
•   Identify statistical outliers.                   are in sorted order

•   Find duplicates in a mailing list.


•   Data compression.
•   Computer graphics.
•   Computational biology.
                                                     non-obvious applications
•   Supply chain management.
•   Load balancing on a parallel computer.
    ...
Every system needs (and has) a system sort!
                                                                                       29
Java system sorts


Java uses both mergesort and quicksort.
•   Arrays.sort() sorts array of Comparable or any primitive type.

•   Uses quicksort for primitive types; mergesort for objects.


          import java.util.Arrays;

          public class StringSort
          {
             public static void main(String[] args)
             {
                String[] a = StdIn.readAll().split("s+");
                Arrays.sort(a);
                for (int i = 0; i < N; i++)
                   StdOut.println(a[i]);
             }
          }




Q. Why use different algorithms, depending on type?


                                                                     30
Java system sort for primitive types


   Engineering a sort function. [Bentley-McIlroy, 1993]
   •   Original motivation: improve qsort().
   •   Basic algorithm = 3-way quicksort with cutoff to insertion sort.
   •   Partition on Tukey's ninther: median of the medians of 3 samples,
       each of 3 elements.
                                       approximate median-of-9




     nine evenly
spaced elements    R   L   A   P   M   C    G     A    X     Z   K   R   B   R   J   J   E

    groups of 3    R   A   M       G   X    K          B     J   E

        medians    M   K   E

        ninther    K




   Why use Tukey's ninther?
   •   Better partitioning than sampling.
   •   Less costly than random.
                                                                                             31
Achilles heel in Bentley-McIlroy implementation (Java system sort)


Based on all this research, Java’s system sort is solid, right?

                                                             more disastrous consequences in C
A killer input.
•   Blows function call stack in Java and crashes program.
•   Would take quadratic time if it didn’t crash first.



     % more 250000.txt           % java IntegerSort < 250000.txt
     0                           Exception in thread "main"
     218750                      java.lang.StackOverflowError
     222662                         at java.util.Arrays.sort1(Arrays.java:562)
     11                             at java.util.Arrays.sort1(Arrays.java:606)
     166672                         at java.util.Arrays.sort1(Arrays.java:608)
     247070                         at java.util.Arrays.sort1(Arrays.java:608)
     83339                          at java.util.Arrays.sort1(Arrays.java:608)
     ...                            ...



         250,000 integers        Java's sorting library crashes, even if
         between 0 and 250,000   you give it as much stack space as Windows allows




                                                                                                 32
Achilles heel in Bentley-McIlroy implementation (Java system sort)


McIlroy's devious idea. [A Killer Adversary for Quicksort]
•   Construct malicious input while running system quicksort,
    in response to elements compared.
•   If v is partitioning element, commit to (v < a[i]) and (v < a[j]), but don't
    commit to (a[i] < a[j]) or (a[j] > a[i]) until a[i] and a[j] are compared.


Consequences.
•   Confirms theoretical possibility.
•   Algorithmic complexity attack: you enter linear amount of data;
    server performs quadratic amount of work.


Remark. Attack is not effective if file is randomly ordered before sort.




Q. Why do you think system sort is deterministic?
                                                                                   33
System sort: Which algorithm to use?


Many sorting algorithms to choose from:


Internal sorts.
•   Insertion sort, selection sort, bubblesort, shaker sort.
•   Quicksort, mergesort, heapsort, samplesort, shellsort.
•   Solitaire sort, red-black sort, splaysort, Dobosiewicz sort, psort, ...


External sorts. Poly-phase mergesort, cascade-merge, oscillating sort.


Radix sorts. Distribution, MSD, LSD, 3-way radix quicksort.


Parallel sorts.
•   Bitonic sort, Batcher even-odd sort.
•   Smooth sort, cube sort, column sort.
•   GPUsort.


                                                                              34
System sort: Which algorithm to use?


Applications have diverse attributes.
•   Stable?
•   Multiple keys?
•   Deterministic?
•   Keys all distinct?
•   Multiple key types?
•   Linked list or arrays?
•   Large or small records?
•   Is your file randomly ordered?
•   Need guaranteed performance?                     many more combinations of
                                                     attributes than algorithms



Elementary sort may be method of choice for some combination.
Cannot cover all combinations of attributes.


Q. Is the system sort good enough?
A. Usually.
                                                                                  35
Sorting summary




              inplace?   stable?   worst    average    best                  remarks


 selection       x                 N2/2      N2/2      N2/2                N exchanges


 insertion       x         x       N2/2      N2/4        N      use for small N or partially ordered


   shell         x                   ?         ?         N           tight code, subquadratic

                                                                  N log N probabilistic guarantee
   quick         x                 N2/2     2 N ln N   N lg N
                                                                         fastest in practice
                                                                improves quicksort in presence of
3-way quick      x                 N2/2     2 N ln N     N
                                                                         duplicate keys

  merge                    x       N lg N   N lg N     N lg N        N log N guarantee, stable


   ???           x         x       N lg N   N lg N     N lg N            holy sorting grail




                                                                                                       36

Weitere ähnliche Inhalte

Was ist angesagt?

Compiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationCompiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationGuido Wachsmuth
 
Jinnai fukunaga-2016
Jinnai fukunaga-2016Jinnai fukunaga-2016
Jinnai fukunaga-2016Yuu Jinnai
 
20110319 parameterized algorithms_fomin_lecture01-02
20110319 parameterized algorithms_fomin_lecture01-0220110319 parameterized algorithms_fomin_lecture01-02
20110319 parameterized algorithms_fomin_lecture01-02Computer Science Club
 
The H.264 Integer Transform
The H.264 Integer TransformThe H.264 Integer Transform
The H.264 Integer TransformIain Richardson
 
A Walk in the GAN Zoo
A Walk in the GAN ZooA Walk in the GAN Zoo
A Walk in the GAN ZooLarry Guo
 
Sampling with Halton Points on n-Sphere
Sampling with Halton Points on n-SphereSampling with Halton Points on n-Sphere
Sampling with Halton Points on n-SphereDanny Luk
 
Cordic Code
Cordic CodeCordic Code
Cordic CodeMichelle_R
 
VHDL and Cordic Algorithim
VHDL and Cordic AlgorithimVHDL and Cordic Algorithim
VHDL and Cordic AlgorithimSubeer Rangra
 
To Swift 2...and Beyond!
To Swift 2...and Beyond!To Swift 2...and Beyond!
To Swift 2...and Beyond!Scott Gardner
 
Refactoring - improving the smell of your code
Refactoring - improving the smell of your codeRefactoring - improving the smell of your code
Refactoring - improving the smell of your codevmandrychenko
 
Quantum logic synthesis (srikanth)
Quantum logic synthesis (srikanth)Quantum logic synthesis (srikanth)
Quantum logic synthesis (srikanth)bitra11
 
Discrete Logarithmic Problem- Basis of Elliptic Curve Cryptosystems
Discrete Logarithmic Problem- Basis of Elliptic Curve CryptosystemsDiscrete Logarithmic Problem- Basis of Elliptic Curve Cryptosystems
Discrete Logarithmic Problem- Basis of Elliptic Curve CryptosystemsNIT Sikkim
 
Lecture6
Lecture6Lecture6
Lecture6voracle
 
Gate Computer Science Solved Paper 2007
Gate Computer Science Solved Paper 2007 Gate Computer Science Solved Paper 2007
Gate Computer Science Solved Paper 2007 Rohit Garg
 
Threshold and Proactive Pseudo-Random Permutations
Threshold and Proactive Pseudo-Random PermutationsThreshold and Proactive Pseudo-Random Permutations
Threshold and Proactive Pseudo-Random PermutationsAleksandr Yampolskiy
 
On Resolution Proofs for Combinational Equivalence
On Resolution Proofs for Combinational EquivalenceOn Resolution Proofs for Combinational Equivalence
On Resolution Proofs for Combinational Equivalencesatrajit
 
Speaker Diarization
Speaker DiarizationSpeaker Diarization
Speaker DiarizationHONGJOO LEE
 
Polynomial Kernel for Interval Vertex Deletion
Polynomial Kernel for Interval Vertex DeletionPolynomial Kernel for Interval Vertex Deletion
Polynomial Kernel for Interval Vertex DeletionAkankshaAgrawal55
 
Polylogarithmic approximation algorithm for weighted F-deletion problems
Polylogarithmic approximation algorithm for weighted F-deletion problemsPolylogarithmic approximation algorithm for weighted F-deletion problems
Polylogarithmic approximation algorithm for weighted F-deletion problemsAkankshaAgrawal55
 

Was ist angesagt? (20)

Compiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationCompiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register Allocation
 
Jinnai fukunaga-2016
Jinnai fukunaga-2016Jinnai fukunaga-2016
Jinnai fukunaga-2016
 
Seminar@KRDB 2012 - Montali - Verification of Relational Data-Centric Systems...
Seminar@KRDB 2012 - Montali - Verification of Relational Data-Centric Systems...Seminar@KRDB 2012 - Montali - Verification of Relational Data-Centric Systems...
Seminar@KRDB 2012 - Montali - Verification of Relational Data-Centric Systems...
 
20110319 parameterized algorithms_fomin_lecture01-02
20110319 parameterized algorithms_fomin_lecture01-0220110319 parameterized algorithms_fomin_lecture01-02
20110319 parameterized algorithms_fomin_lecture01-02
 
The H.264 Integer Transform
The H.264 Integer TransformThe H.264 Integer Transform
The H.264 Integer Transform
 
A Walk in the GAN Zoo
A Walk in the GAN ZooA Walk in the GAN Zoo
A Walk in the GAN Zoo
 
Sampling with Halton Points on n-Sphere
Sampling with Halton Points on n-SphereSampling with Halton Points on n-Sphere
Sampling with Halton Points on n-Sphere
 
Cordic Code
Cordic CodeCordic Code
Cordic Code
 
VHDL and Cordic Algorithim
VHDL and Cordic AlgorithimVHDL and Cordic Algorithim
VHDL and Cordic Algorithim
 
To Swift 2...and Beyond!
To Swift 2...and Beyond!To Swift 2...and Beyond!
To Swift 2...and Beyond!
 
Refactoring - improving the smell of your code
Refactoring - improving the smell of your codeRefactoring - improving the smell of your code
Refactoring - improving the smell of your code
 
Quantum logic synthesis (srikanth)
Quantum logic synthesis (srikanth)Quantum logic synthesis (srikanth)
Quantum logic synthesis (srikanth)
 
Discrete Logarithmic Problem- Basis of Elliptic Curve Cryptosystems
Discrete Logarithmic Problem- Basis of Elliptic Curve CryptosystemsDiscrete Logarithmic Problem- Basis of Elliptic Curve Cryptosystems
Discrete Logarithmic Problem- Basis of Elliptic Curve Cryptosystems
 
Lecture6
Lecture6Lecture6
Lecture6
 
Gate Computer Science Solved Paper 2007
Gate Computer Science Solved Paper 2007 Gate Computer Science Solved Paper 2007
Gate Computer Science Solved Paper 2007
 
Threshold and Proactive Pseudo-Random Permutations
Threshold and Proactive Pseudo-Random PermutationsThreshold and Proactive Pseudo-Random Permutations
Threshold and Proactive Pseudo-Random Permutations
 
On Resolution Proofs for Combinational Equivalence
On Resolution Proofs for Combinational EquivalenceOn Resolution Proofs for Combinational Equivalence
On Resolution Proofs for Combinational Equivalence
 
Speaker Diarization
Speaker DiarizationSpeaker Diarization
Speaker Diarization
 
Polynomial Kernel for Interval Vertex Deletion
Polynomial Kernel for Interval Vertex DeletionPolynomial Kernel for Interval Vertex Deletion
Polynomial Kernel for Interval Vertex Deletion
 
Polylogarithmic approximation algorithm for weighted F-deletion problems
Polylogarithmic approximation algorithm for weighted F-deletion problemsPolylogarithmic approximation algorithm for weighted F-deletion problems
Polylogarithmic approximation algorithm for weighted F-deletion problems
 

Andere mochten auch

Qr codes para tech radar
Qr codes para tech radarQr codes para tech radar
Qr codes para tech radarSri Prasanna
 
Serverless (Distributed computing)
Serverless (Distributed computing)Serverless (Distributed computing)
Serverless (Distributed computing)Sri Prasanna
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data StructuresSHAKOOR AB
 
Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)Sri Prasanna
 

Andere mochten auch (6)

Qr codes para tech radar
Qr codes para tech radarQr codes para tech radar
Qr codes para tech radar
 
Map Reduce
Map ReduceMap Reduce
Map Reduce
 
Serverless (Distributed computing)
Serverless (Distributed computing)Serverless (Distributed computing)
Serverless (Distributed computing)
 
Hashing
HashingHashing
Hashing
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)Clock Synchronization (Distributed computing)
Clock Synchronization (Distributed computing)
 

Ă„hnlich wie Advanced Sorting Techniques

IOEfficientParalleMatrixMultiplication_present
IOEfficientParalleMatrixMultiplication_presentIOEfficientParalleMatrixMultiplication_present
IOEfficientParalleMatrixMultiplication_presentShubham Joshi
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++Mohammad Shaker
 
GeneIndex: an open source parallel program for enumerating and locating words...
GeneIndex: an open source parallel program for enumerating and locating words...GeneIndex: an open source parallel program for enumerating and locating words...
GeneIndex: an open source parallel program for enumerating and locating words...PTIHPA
 
Lp seminar
Lp seminarLp seminar
Lp seminarguestdff961
 
MapReduce Algorithm Design
MapReduce Algorithm DesignMapReduce Algorithm Design
MapReduce Algorithm DesignGabriela Agustini
 
Nondeterministic testing of Sequential Quantum Logic Propositions on a Quant...
Nondeterministic testing of Sequential Quantum Logic  Propositions on a Quant...Nondeterministic testing of Sequential Quantum Logic  Propositions on a Quant...
Nondeterministic testing of Sequential Quantum Logic Propositions on a Quant...Matthew Leifer
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...Andrey Karpov
 
Functional Design Explained (David Sankel CppCon 2015)
Functional Design Explained (David Sankel CppCon 2015)Functional Design Explained (David Sankel CppCon 2015)
Functional Design Explained (David Sankel CppCon 2015)sankeld
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Leonardo Borges
 
Fine Grained Complexity
Fine Grained ComplexityFine Grained Complexity
Fine Grained ComplexityAkankshaAgrawal55
 
Concurrency in Distributed Systems : Leslie Lamport papers
Concurrency in Distributed Systems : Leslie Lamport papersConcurrency in Distributed Systems : Leslie Lamport papers
Concurrency in Distributed Systems : Leslie Lamport papersSubhajit Sahu
 
Applying Linear Optimization Using GLPK
Applying Linear Optimization Using GLPKApplying Linear Optimization Using GLPK
Applying Linear Optimization Using GLPKJeremy Chen
 
Quantum Computing Notes Ver 1.2
Quantum Computing Notes Ver 1.2Quantum Computing Notes Ver 1.2
Quantum Computing Notes Ver 1.2Vijayananda Mohire
 
Detailed cryptographic analysis of contact tracing protocols
Detailed cryptographic analysis of contact tracing protocolsDetailed cryptographic analysis of contact tracing protocols
Detailed cryptographic analysis of contact tracing protocolsChristian Spolaore
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Igalia
 

Ă„hnlich wie Advanced Sorting Techniques (20)

IOEfficientParalleMatrixMultiplication_present
IOEfficientParalleMatrixMultiplication_presentIOEfficientParalleMatrixMultiplication_present
IOEfficientParalleMatrixMultiplication_present
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++
 
Realtime Analytics
Realtime AnalyticsRealtime Analytics
Realtime Analytics
 
Analysis
AnalysisAnalysis
Analysis
 
GeneIndex: an open source parallel program for enumerating and locating words...
GeneIndex: an open source parallel program for enumerating and locating words...GeneIndex: an open source parallel program for enumerating and locating words...
GeneIndex: an open source parallel program for enumerating and locating words...
 
Lp seminar
Lp seminarLp seminar
Lp seminar
 
02 analysis
02 analysis02 analysis
02 analysis
 
MapReduce Algorithm Design
MapReduce Algorithm DesignMapReduce Algorithm Design
MapReduce Algorithm Design
 
Nondeterministic testing of Sequential Quantum Logic Propositions on a Quant...
Nondeterministic testing of Sequential Quantum Logic  Propositions on a Quant...Nondeterministic testing of Sequential Quantum Logic  Propositions on a Quant...
Nondeterministic testing of Sequential Quantum Logic Propositions on a Quant...
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
Functional Design Explained (David Sankel CppCon 2015)
Functional Design Explained (David Sankel CppCon 2015)Functional Design Explained (David Sankel CppCon 2015)
Functional Design Explained (David Sankel CppCon 2015)
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012
 
Fine Grained Complexity
Fine Grained ComplexityFine Grained Complexity
Fine Grained Complexity
 
Concurrency in Distributed Systems : Leslie Lamport papers
Concurrency in Distributed Systems : Leslie Lamport papersConcurrency in Distributed Systems : Leslie Lamport papers
Concurrency in Distributed Systems : Leslie Lamport papers
 
Applying Linear Optimization Using GLPK
Applying Linear Optimization Using GLPKApplying Linear Optimization Using GLPK
Applying Linear Optimization Using GLPK
 
Quantum Computing Notes Ver 1.2
Quantum Computing Notes Ver 1.2Quantum Computing Notes Ver 1.2
Quantum Computing Notes Ver 1.2
 
2019 GDRR: Blockchain Data Analytics - ChainNet: Learning on Blockchain Graph...
2019 GDRR: Blockchain Data Analytics - ChainNet: Learning on Blockchain Graph...2019 GDRR: Blockchain Data Analytics - ChainNet: Learning on Blockchain Graph...
2019 GDRR: Blockchain Data Analytics - ChainNet: Learning on Blockchain Graph...
 
Computer Science Final Project
Computer Science Final ProjectComputer Science Final Project
Computer Science Final Project
 
Detailed cryptographic analysis of contact tracing protocols
Detailed cryptographic analysis of contact tracing protocolsDetailed cryptographic analysis of contact tracing protocols
Detailed cryptographic analysis of contact tracing protocols
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
 

Mehr von Sri Prasanna

Qr codes para tech radar 2
Qr codes para tech radar 2Qr codes para tech radar 2
Qr codes para tech radar 2Sri Prasanna
 
About stacks
About stacksAbout stacks
About stacksSri Prasanna
 
About Stacks
About  StacksAbout  Stacks
About StacksSri Prasanna
 
About Stacks
About  StacksAbout  Stacks
About StacksSri Prasanna
 
About Stacks
About  StacksAbout  Stacks
About StacksSri Prasanna
 
About Stacks
About  StacksAbout  Stacks
About StacksSri Prasanna
 
About Stacks
About  StacksAbout  Stacks
About StacksSri Prasanna
 
About Stacks
About StacksAbout Stacks
About StacksSri Prasanna
 
About Stacks
About StacksAbout Stacks
About StacksSri Prasanna
 
Network and distributed systems
Network and distributed systemsNetwork and distributed systems
Network and distributed systemsSri Prasanna
 
Introduction & Parellelization on large scale clusters
Introduction & Parellelization on large scale clustersIntroduction & Parellelization on large scale clusters
Introduction & Parellelization on large scale clustersSri Prasanna
 
Mapreduce: Theory and implementation
Mapreduce: Theory and implementationMapreduce: Theory and implementation
Mapreduce: Theory and implementationSri Prasanna
 
Other distributed systems
Other distributed systemsOther distributed systems
Other distributed systemsSri Prasanna
 
Distributed file systems
Distributed file systemsDistributed file systems
Distributed file systemsSri Prasanna
 

Mehr von Sri Prasanna (20)

Qr codes para tech radar 2
Qr codes para tech radar 2Qr codes para tech radar 2
Qr codes para tech radar 2
 
Test
TestTest
Test
 
Test
TestTest
Test
 
assds
assdsassds
assds
 
assds
assdsassds
assds
 
asdsa
asdsaasdsa
asdsa
 
dsd
dsddsd
dsd
 
About stacks
About stacksAbout stacks
About stacks
 
About Stacks
About  StacksAbout  Stacks
About Stacks
 
About Stacks
About  StacksAbout  Stacks
About Stacks
 
About Stacks
About  StacksAbout  Stacks
About Stacks
 
About Stacks
About  StacksAbout  Stacks
About Stacks
 
About Stacks
About  StacksAbout  Stacks
About Stacks
 
About Stacks
About StacksAbout Stacks
About Stacks
 
About Stacks
About StacksAbout Stacks
About Stacks
 
Network and distributed systems
Network and distributed systemsNetwork and distributed systems
Network and distributed systems
 
Introduction & Parellelization on large scale clusters
Introduction & Parellelization on large scale clustersIntroduction & Parellelization on large scale clusters
Introduction & Parellelization on large scale clusters
 
Mapreduce: Theory and implementation
Mapreduce: Theory and implementationMapreduce: Theory and implementation
Mapreduce: Theory and implementation
 
Other distributed systems
Other distributed systemsOther distributed systems
Other distributed systems
 
Distributed file systems
Distributed file systemsDistributed file systems
Distributed file systems
 

KĂĽrzlich hochgeladen

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 

KĂĽrzlich hochgeladen (20)

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 

Advanced Sorting Techniques

  • 1. Advanced Topics in Sorting ‣ selection ‣ duplicate keys ‣ system sorts ‣ comparators Reference: http://www.cs.princeton.edu/algs4 Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License. Algorithms in Java, 4th Edition · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · May 2, 2008 10:45:30 AM
  • 2. Selection Goal. Find the kth largest element. Ex. Min (k = 0), max (k = N-1), median (k = N/2). Applications. • Order statistics. • Find the “top k.” Use theory as a guide. • Easy O(N log N) upper bound. • Easy O(N) upper bound for k = 1, 2, 3. • Easy Ω(N) lower bound. Which is true? • Ω(N log N) lower bound? is selection as hard as sorting? • O(N) upper bound? is there a linear-time algorithm for all k? 2
  • 3. Quick-select Partition array so that: • Element a[i] is in place. • No larger element to the left of i. • No smaller element to the right of i. Repeat in one subarray, depending on i; finished when i equals k. public static Comparable select(Comparable[] before int k) a, v { lo hi StdRandom.shuffle(a); int lo = 0, hi = a.length - 1; while (hi > lo) if a[k] is here, if a[k] is here, { set hi to i-1 set lo to i+1 int i = partition(a, lo, hi); if (i < k) lo = i + 1; after v v v else if (i > k) hi = i - 1; else return a[k]; lo i hi } return a[k]; } 3
  • 4. Quick-select: mathematical analysis Proposition. Quick-select takes linear time on average. Pf sketch. • Intuitively, each partitioning step roughly splits array in half: N + N/2 + N/4 + … + 1 ~ 2N compares. • Formal analysis similar to quicksort analysis yields: CN = 2 N + k ln ( N / k) + (N - k) ln (N / (N - k)) Ex. (2 + 2 ln 2) N compares to find the median. Remark. Quick-select might use ~ N2/2 compares, but as with quicksort, the random shuffle provides a probabilistic guarantee. 4
  • 5. Theoretical context for selection Challenge. Design a selection algorithm whose running time is linear in the worst-case. Theorem. [Blum, Floyd, Pratt, Rivest, Tarjan, 1973] There exists a compare- based selection algorithm that takes linear time in the worst case. Remark. Algorithm is too complicated to be useful in practice. Use theory as a guide. • Still worthwhile to seek practical linear-time (worst-case) algorithm. • Until one is discovered, use quick-select if you don’t need a full sort. 5
  • 6. Generic methods In our select() implementation, client needs a cast. Double[] a = new Double[N]; for (int i = 0; i < N; i++) a[i] = StdRandom.uniform(); hazardous cast Double median = (Double) Quick.select(a, N/2); required The compiler is also unhappy. % javac Quick.java Note: Quick.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Q. How to fix? 6
  • 7. Generic methods Safe version. Compiles cleanly, no cast needed in client. public class Quick generic type variable { (value inferred from argument a[]) public static <Key extends Comparable<Key>> Key select(Key[] a, int k) { /* as before */ } return type matches array type public static <Key extends Comparable<Key>> void sort(Key[] a) { /* as before */ } private static <Key extends Comparable<Key>> int partition(Key[] a, int lo, int hi) { /* as before */ } private static <Key extends Comparable<Key>> boolean less(Key v, Key w) { /* as before */ } private static <Key extends Comparable<Key>> void exch(Key[] a, int i, int j) { Key swap = a[i]; a[i] = a[j]; a[j] = swap; } } can declare variables of generic type Remark. Obnoxious code needed in system sort; not in this course (for brevity). 7
  • 8. ‣ selection ‣ duplicate keys ‣ comparators ‣ applications 8
  • 9. Duplicate keys Often, purpose of sort is to bring records with duplicate keys together. • Sort population by age. • Find collinear points. see Assignment 3 • Remove duplicates from mailing list. • Sort job applicants by college attended. sorted by time sorted by city (unstable) sorted by cit Chicago 09:00:00 Chicago 09:25:52 Chicago 09 Typical characteristics of such applications. Phoenix 09:00:03 Houston 09:00:13 Chicago 09:03:13 Chicago 09:21:05 Chicago 09 Chicago 09 • Huge file. Chicago 09:00:59 Houston 09:01:10 Chicago 09:19:46 Chicago 09:19:32 Chicago 09 Chicago 09 • Chicago 09:03:13 Chicago 09:00:00 Chicago 09 Small number of key values. Seattle 09:10:11 Chicago 09:35:21 Chicago 09 Seattle 09:10:25 Chicago 09:00:59 Chicago 09 Phoenix 09:14:25 Houston 09:01:10 Houston 09 Chicago 09:19:32 Houston 09:00:13 NOT Houston 09 Chicago 09:19:46 Phoenix 09:37:44 sorted Phoenix 09 Chicago 09:21:05 Phoenix 09:00:03 Phoenix 09 Seattle 09:22:43 Phoenix 09:14:25 Phoenix 09 Seattle 09:22:54 Seattle 09:10:25 Seattle 09 Chicago 09:25:52 Seattle 09:36:14 Seattle 09 Chicago 09:35:21 Seattle 09:22:43 Seattle 09 Seattle 09:36:14 Seattle 09:10:11 Seattle 09 Phoenix 09:37:44 Seattle 09:22:54 Seattle 09 Stability when sorting on a second key key 9
  • 10. Duplicate keys Mergesort with duplicate keys. Always ~ N lg N compares. Quicksort with duplicate keys. • Algorithm goes quadratic unless partitioning stops on equal keys! • 1990s C user found this defect in qsort(). several textbook and system implementations also have this defect 10
  • 11. Duplicate keys: the problem Assume all keys are equal. Recursive code guarantees this case predominates! Mistake. Put all keys equal to the partitioning element on one side. Consequence. ~ N2 / 2 compares when all keys equal. B A A B A B B B C C C A A A A A A A A A A A Recommended. Stop scans on keys equal to the partitioning element. Consequence. ~ N lg N compares when all keys equal. B A A B A B C C B C B A A A A A A A A A A A Desirable. Put all keys equal to the partitioning element in place. A A A B B B B B C C C A A A A A A A A A A A 11
  • 12. 3-way partitioning Goal. Partition array into 3 parts so that: • Elements between lt and gt equal to partition element v. • No larger elements to left of lt. • No smaller elements to right of gt. before v lo hi after <v =v >v lo lt gt hi 3-way partitioning Dutch national flag problem. [Edsger Dijkstra] • Convention wisdom until mid 1990s: not worth doing. • New approach discovered when fixing mistake in C library qsort(). • Now incorporated into qsort() and Java system sort. 12
  • 13. 3-way partitioning: Dijkstra's solution 3-way partitioning. • Let v be partitioning element a[lo]. • Scan i from left to right. - a[i] less than v : exchange a[lt] with a[i] and increment both lt and i - a[i] greater than v : exchange a[gt] with a[i] and decrement gt - a[i] equal to v : increment i before v All the right properties. lo hi • during <v =v >v In-place. • lt i gt Not much code. >v after <v =v • Small overhead if no equal keys. lo lt gt hi 3-way partitioning 13
  • 14. 3-way partitioning: trace v a[] lt i gt 0 1 2 3 4 5 6 7 8 9 10 11 0 0 11 R B W W R W B R R W B R 0 1 11 R B W W R W B R R W B R 1 2 11 B R W W R W B R R W B R 1 2 10 B R R W R W B R R W B W 1 3 10 B R R W R W B R R W B W 1 3 9 B R R B R W B R R W W W 2 4 9 B B R R R W B R R W W W 2 5 9 B B R R R W B R R W W W 2 5 8 B B R R R W B R R W W W 2 5 7 B B R R R R B R W W W W 2 6 7 B B R R R R B R W W W W 3 7 7 B B B R R R R R W W W W 3 8 7 B B B R R R R R W W W W 3-way partitioning trace (array contents after each loop iteration) 14
  • 15. 3-way quicksort: Java implementation private static void sort(Comparable[] a, int lo, int hi) { if (hi <= lo) return; int lt = lo, gt = hi; Comparable v = a[lo]; int i = lo; while (i <= gt) before v { lo hi int cmp = a[i].compareTo(v); during <v =v >v if (cmp < 0) exch(a, lt++, i++); lt i gt else if (cmp > 0) exch(a, i, gt--); after <v =v >v else i++; lo lt gt hi } 3-way partitioning sort(a, lo, lt - 1); sort(a, gt + 1, hi); } 15
  • 16. 3-way quicksort: visual trace equal to partitioning element Visual trace of quicksort with 3-way partitioning 16
  • 17. Duplicate keys: lower bound Proposition. [Sedgewick-Bentley, 1997] Quicksort with 3-way partitioning is entropy-optimal. Pf. [beyond scope of course] • Generalize decision tree. • Tie cost to Shannon entropy. Ex. Linear-time when only a constant number of distinct keys. Bottom line. Randomized quicksort with 3-way partitioning reduces running time from linearithmic to linear in broad class of applications. 17
  • 18. ‣ selection ‣ duplicate keys ‣ comparators ‣ applications 18
  • 19. Natural order Comparable interface: sort uses type’s natural order. public class Date implements Comparable<Date> { private final int month, day, year; public Date(int m, int d, int y) { month = m; day = d; year = y; } … public int compareTo(Date that) { if (this.year < that.year ) return -1; if (this.year > that.year ) return +1; if (this.month < that.month) return -1; natural order if (this.month > that.month) return +1; if (this.day < that.day ) return -1; if (this.day > that.day ) return +1; return 0; } } 19
  • 20. Generalized compare Comparable interface: sort uses type’s natural order. Problem 1. May want to use a non-natural order. Problem 2. Desired data type may not come with a “natural” order. Ex. Sort strings by: • pre-1994 order for digraphs Natural order. Now is the time ch and ll and rr • Case insensitive. is Now the time • Spanish. cafĂ© cafetero cuarto churro nube ñoño • British phone book. McKinley Mackintosh String[] a; ... Arrays.sort(a); Arrays.sort(a, String.CASE_INSENSITIVE_ORDER); Arrays.sort(a, Collator.getInstance(Locale.SPANISH)); import java.text.Collator; 20
  • 21. Comparators Solution. Use Java's Comparator interface. public interface Comparator<Key> { public int compare(Key v, Key w); } Remark. The compare() method implements a total order like compareTo(). Advantages. Decouples the definition of the data type from the definition of what it means to compare two objects of that type. • Can add any number of new orders to a data type. • Can add an order to a library data type with no natural order. 21
  • 22. Comparator example Reverse order. Sort an array of strings in reverse order. public class ReverseOrder implements Comparator<String> { public int compare(String a, String b) { return b.compareTo(a); } } comparator implementation ... Arrays.sort(a, new ReverseOrder()); ... client 22
  • 23. Sort implementation with comparators To support comparators in our sort implementations: • Pass Comparator to sort() and less(). • Use it in less(). type variable Ex. Insertion sort. (not necessarily Comparable) public static <Key> void sort(Key[] a, Comparator<Key> comparator) { int N = a.length; for (int i = 0; i < N; i++) for (int j = i; j > 0; j--) if (less(comparator, a[j], a[j-1])) exch(a, j, j-1); else break; } private static <Key> boolean less(Comparator<Key> c, Key v, Key w) { return c.compare(v, w) < 0; } private static <Key> void exch(Key[] a, int i, int j) { Key swap = a[i]; a[i] = a[j]; a[j] = swap; } 23
  • 24. Generalized compare Comparators enable multiple sorts of a single file (by different keys). Ex. Sort students by name or by section. Arrays.sort(students, Student.BY_NAME); Arrays.sort(students, Student.BY_SECT); sort by name then sort by section Andrews 3 A 664-480-0023 097 Little Fox 1 A 884-232-5341 11 Dickinson Battle 4 C 874-088-1212 121 Whitman Chen 2 A 991-878-4944 308 Blair Chen 2 A 991-878-4944 308 Blair Andrews 3 A 664-480-0023 097 Little Fox 1 A 884-232-5341 11 Dickinson Furia 3 A 766-093-9873 101 Brown Furia 3 A 766-093-9873 101 Brown Kanaga 3 B 898-122-9643 22 Brown Gazsi 4 B 665-303-0266 22 Brown Rohde 3 A 232-343-5555 343 Forbes Kanaga 3 B 898-122-9643 22 Brown Battle 4 C 874-088-1212 121 Whitman Rohde 3 A 232-343-5555 343 Forbes Gazsi 4 B 665-303-0266 22 Brown 24
  • 25. Generalized compare Ex. Enable sorting students by name or by section. public class Student { public static final Comparator<Student> BY_NAME = new ByName(); public static final Comparator<Student> BY_SECT = new BySect(); private final String name; private final int section; ... private static class ByName implements Comparator<Student> { public int compare(Student a, Student b) { return a.name.compareTo(b.name); } } private static class BySect implements Comparator<Student> { public int compare(Student a, Student b) { return a.section - b.section; } } } only use this trick if no danger of overflow 25
  • 26. Generalized compare problem A typical application. First, sort by name; then sort by section. Arrays.sort(students, Student.BY_NAME); Arrays.sort(students, Student.BY_SECT); Andrews 3 A 664-480-0023 097 Little Fox 1 A 884-232-5341 11 Dickinson Battle 4 C 874-088-1212 121 Whitman Chen 2 A 991-878-4944 308 Blair Chen 2 A 991-878-4944 308 Blair Kanaga 3 B 898-122-9643 22 Brown Fox 1 A 884-232-5341 11 Dickinson Andrews 3 A 664-480-0023 097 Little Furia 3 A 766-093-9873 101 Brown Furia 3 A 766-093-9873 101 Brown Gazsi 4 B 665-303-0266 22 Brown Rohde 3 A 232-343-5555 343 Forbes Kanaga 3 B 898-122-9643 22 Brown Battle 4 C 874-088-1212 121 Whitman Rohde 3 A 232-343-5555 343 Forbes Gazsi 4 B 665-303-0266 22 Brown @#%&@!!. Students in section 3 no longer in order by name. A stable sort preserves the relative order of records with equal keys. 26
  • 27. Stability Q. Which sorts are stable? • Selection sort? • Insertion sort? • Shellsort? • Quicksort? sorted by time Chicago 09:00:00 sorted by city (unstable) Chicago 09:25:52 sorted by city (stable) Chicago 09:00:00 • Phoenix 09:00:03 Chicago 09:03:13 Chicago 09:00:59 Mergesort? Houston 09:00:13 Chicago 09:21:05 Chicago 09:03:13 Chicago 09:00:59 Chicago 09:19:46 Chicago 09:19:32 Houston 09:01:10 Chicago 09:19:32 Chicago 09:19:46 Chicago 09:03:13 Chicago 09:00:00 Chicago 09:21:05 Seattle 09:10:11 Chicago 09:35:21 Chicago 09:25:52 Seattle 09:10:25 Chicago 09:00:59 Chicago 09:35:21 Phoenix 09:14:25 Houston 09:01:10 Houston 09:00:13 Chicago 09:19:32 Houston 09:00:13 NOT Houston 09:01:10 sorted Chicago 09:19:46 Phoenix 09:37:44 sorted Phoenix 09:00:03 Chicago 09:21:05 Phoenix 09:00:03 Phoenix 09:14:25 Seattle 09:22:43 Phoenix 09:14:25 Phoenix 09:37:44 Seattle 09:22:54 Seattle 09:10:25 Seattle 09:10:11 Chicago 09:25:52 Seattle 09:36:14 Seattle 09:10:25 Chicago 09:35:21 Seattle 09:22:43 Seattle 09:22:43 Seattle 09:36:14 Seattle 09:10:11 Seattle 09:22:54 Phoenix 09:37:44 Seattle 09:22:54 Seattle 09:36:14 Stability when sorting on a second key Open problem. Stable, inplace, N log N, practical sort?? 27
  • 28. ‣ selection ‣ duplicate keys ‣ comparators ‣ system sort 28
  • 29. Sorting applications Sorting algorithms are essential in a broad variety of applications: • Sort a list of names. • Organize an MP3 library. • Display Google PageRank results. obvious applications • List RSS news items in reverse chronological order. • Find the median. • Find the closest pair. • Binary search in a database. problems become easy once items • Identify statistical outliers. are in sorted order • Find duplicates in a mailing list. • Data compression. • Computer graphics. • Computational biology. non-obvious applications • Supply chain management. • Load balancing on a parallel computer. ... Every system needs (and has) a system sort! 29
  • 30. Java system sorts Java uses both mergesort and quicksort. • Arrays.sort() sorts array of Comparable or any primitive type. • Uses quicksort for primitive types; mergesort for objects. import java.util.Arrays; public class StringSort { public static void main(String[] args) { String[] a = StdIn.readAll().split("s+"); Arrays.sort(a); for (int i = 0; i < N; i++) StdOut.println(a[i]); } } Q. Why use different algorithms, depending on type? 30
  • 31. Java system sort for primitive types Engineering a sort function. [Bentley-McIlroy, 1993] • Original motivation: improve qsort(). • Basic algorithm = 3-way quicksort with cutoff to insertion sort. • Partition on Tukey's ninther: median of the medians of 3 samples, each of 3 elements. approximate median-of-9 nine evenly spaced elements R L A P M C G A X Z K R B R J J E groups of 3 R A M G X K B J E medians M K E ninther K Why use Tukey's ninther? • Better partitioning than sampling. • Less costly than random. 31
  • 32. Achilles heel in Bentley-McIlroy implementation (Java system sort) Based on all this research, Java’s system sort is solid, right? more disastrous consequences in C A killer input. • Blows function call stack in Java and crashes program. • Would take quadratic time if it didn’t crash first. % more 250000.txt % java IntegerSort < 250000.txt 0 Exception in thread "main" 218750 java.lang.StackOverflowError 222662 at java.util.Arrays.sort1(Arrays.java:562) 11 at java.util.Arrays.sort1(Arrays.java:606) 166672 at java.util.Arrays.sort1(Arrays.java:608) 247070 at java.util.Arrays.sort1(Arrays.java:608) 83339 at java.util.Arrays.sort1(Arrays.java:608) ... ... 250,000 integers Java's sorting library crashes, even if between 0 and 250,000 you give it as much stack space as Windows allows 32
  • 33. Achilles heel in Bentley-McIlroy implementation (Java system sort) McIlroy's devious idea. [A Killer Adversary for Quicksort] • Construct malicious input while running system quicksort, in response to elements compared. • If v is partitioning element, commit to (v < a[i]) and (v < a[j]), but don't commit to (a[i] < a[j]) or (a[j] > a[i]) until a[i] and a[j] are compared. Consequences. • Confirms theoretical possibility. • Algorithmic complexity attack: you enter linear amount of data; server performs quadratic amount of work. Remark. Attack is not effective if file is randomly ordered before sort. Q. Why do you think system sort is deterministic? 33
  • 34. System sort: Which algorithm to use? Many sorting algorithms to choose from: Internal sorts. • Insertion sort, selection sort, bubblesort, shaker sort. • Quicksort, mergesort, heapsort, samplesort, shellsort. • Solitaire sort, red-black sort, splaysort, Dobosiewicz sort, psort, ... External sorts. Poly-phase mergesort, cascade-merge, oscillating sort. Radix sorts. Distribution, MSD, LSD, 3-way radix quicksort. Parallel sorts. • Bitonic sort, Batcher even-odd sort. • Smooth sort, cube sort, column sort. • GPUsort. 34
  • 35. System sort: Which algorithm to use? Applications have diverse attributes. • Stable? • Multiple keys? • Deterministic? • Keys all distinct? • Multiple key types? • Linked list or arrays? • Large or small records? • Is your file randomly ordered? • Need guaranteed performance? many more combinations of attributes than algorithms Elementary sort may be method of choice for some combination. Cannot cover all combinations of attributes. Q. Is the system sort good enough? A. Usually. 35
  • 36. Sorting summary inplace? stable? worst average best remarks selection x N2/2 N2/2 N2/2 N exchanges insertion x x N2/2 N2/4 N use for small N or partially ordered shell x ? ? N tight code, subquadratic N log N probabilistic guarantee quick x N2/2 2 N ln N N lg N fastest in practice improves quicksort in presence of 3-way quick x N2/2 2 N ln N N duplicate keys merge x N lg N N lg N N lg N N log N guarantee, stable ??? x x N lg N N lg N N lg N holy sorting grail 36