MegastoRM

Untitled

Mar 21st, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.12 KB | None | 0 0
  1. Selection sort
  2.     - metoda koja se preporucuje za mali broj elemenata (spora je)
  3.     8,2,4,9,5,6
  4.  
  5.  
  6. jedan kvadratic
  7. drugi -||-
  8. treci -||-
  9.  
  10. "Leva saka je otisla dole..." - Z.M (2016)
  11.  
  12. Prazan kvadratic dole
  13. Ovaj je leva ruka
  14. ovo je broj osam
  15. ovo ovde je broj 5
  16. broj 5 je preso na broj 8
  17. iz temp je preso na broj 5
  18.  
  19.  
  20. Metoda zamene
  21. Uporedjuje susedne elemente i zamenjuje ih ukoliko nisu u odgovarajucem redu
  22.     - bubble sort
  23.     - sink sort
  24.  
  25.     n^2/2 poredjenja i n^2/2 zamena u proseku i najgorem slucaju
  26. Najsporiji od svih O(n^2) algoritama
  27.  
  28.  
  29. http://www.pmf.ni.ac.rs/pmf/predmeti/7011/sortiranje.pdf
  30.  
  31. Insertion sort
  32.  
  33.  
  34.  
  35. I tako dalje i tako blize
  36.  
  37. http://perun.pmf.uns.ac.rs/index.php?view=article&catid=23%3Aispiti&id=31%3Astrukture-podataka-i-algoritmi-ii&format=pdf&option=com_content&Itemid=39
  38.  
  39. http://perun.pmf.uns.ac.rs/index.php?option=com_content&task=view&id=31&Itemid=39
  40.  
  41. https://sr.wikipedia.org/sr/%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D0%B8_%D1%81%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%B0%D1%9A%D0%B0#.D0.A3.D0.BA.D1.80.D0.B0.D1.82.D0.BA.D0.BE_.D0.BE_.D0.BF.D0.BE.D0.B7.D0.BD.D0.B0.D1.82.D0.B8.D0.BC_.D0.B0.D0.BB.D0.B3.D0.BE.D1.80.D0.B8.D1.82.D0.BC.D0.B8.D0.BC.D0.B0_.D1.81.D0.BE.D1.80.D1.82.D0.B8.D1.80.D0.B0.D1.9A.D0.B0
  42.  
  43. http://documents.tips/download/link/seminarski-metode-sortiranja-unutrasnje-i-spoljasne-sortiranje
  44.  
  45. odradi kod i primere za InsertionSort i BubbleSort
  46.  
  47. Sabiranje 2 broja (varijable, unos i niz od 5 clanova)
  48. Posle toga sortiranje
  49.  
  50. Shell nismo radili
  51.  
  52. SortiranjeMerge
  53. kompleksnost O(n log n)
  54.  
  55. /*
  56.  * To change this license header, choose License Headers in Project Properties.
  57.  * To change this template file, choose Tools | Templates
  58.  * and open the template in the editor.
  59.  */
  60.  
  61. package sortiranjeinsert;
  62.  
  63. /**
  64.  *
  65.  * @author VSSS
  66.  */
  67. public class SortiranjeInsert {
  68.  
  69.     /**
  70.      * @param args the command line arguments
  71.      */
  72.     public static void main(String[] args) {
  73.         int[] niz = {8, 1, 6, 4, 7};
  74.        
  75.         for(int i = 0; i < niz.length; i++) System.out.print(" " + niz[i]);
  76.         System.out.println();
  77.        
  78.         InsertionSort(niz);
  79.        
  80.         for(int i = 0; i < niz.length; i++) System.out.print(" " + niz[i]);
  81.         // TODO code application logic here
  82.     }
  83.    
  84.     public static void InsertionSort(int[] aArray) {
  85.         int i, j, index;
  86.         for(i = 1; i < aArray.length; i++) {
  87.             index = aArray[i];
  88.             j = i;
  89.            
  90.             while( (j > 0) && (aArray[j - 1] > index) ) {
  91.                 aArray[j] = aArray[j-1];
  92.                 j--;
  93.             }
  94.             aArray[j] = index;
  95.         }
  96.     }
  97.    
  98.     public static void MergeSort(int[] aArray) {
  99.         mergeSort(aArray, 0, aArray.length - 1);
  100.     }
  101.    
  102.     private static void mergeSort(int[] aArray, int aLeft, int aRight) {
  103.         if(aRight > aLeft) {
  104.             int middle = (aRight + aLeft) / 2;
  105.             mergeSort(aArray, aLeft, middle);
  106.             mergeSort(aArray, middle + 1, aRight);
  107.             //merge(aArray, aLeft, middle + 1, aRight);
  108.         }
  109.     }
  110.    
  111.    
  112.    
  113. }
  114.  
  115.  
  116.  
  117. Quick sort metoda
  118.  
  119. (Zavadi pa vladaj - podeli pa vladaj)
  120. deli niz u dva manja
  121. manji se dalje dele na isti nacin
  122. na kraju se spajaju
  123.  
  124.  
  125. sortira se tako sto se deli niz na 2 dela L i D po "pivotu"
  126. rekurzivno sortira podnizove L i D
  127.  
  128. < pivot            > pivot
  129. LLLLLLLLLLLLL      DDDDDDDDDDDDDD
  130. 5, 3, 7, 9, 8, [11], 14, 23, 15, 15
  131. pivot je 11
  132.  
  133. Quick Sort
  134. i++
  135. j--
  136. i tako sve dok se ne sretnu vrsi se zamena (leva strana manji, desna veci)
  137. Kad se sretnu pivot i element na tom mestu se menjaju.
  138. I tako dalje ide rekurzivno.
  139.  
  140. static void quicksort(int[] a, int l, int r) {
  141.     if(r <= l) return;
  142.     int i = partition(a, l, r);
  143.     quicksort(a, l, i - 1);
  144.     quicksort(a, l + 1, r);
  145. }
  146.  
  147. static int partition(int a[], int l, int r) {
  148.     int i = l - 1; j = r; int v = a[r];
  149.     for(;;) {
  150.         while(a[++i] < v);
  151.         while(v < a[--j]) if(j == l) break;
  152.         if(i >= j) break;
  153.         zameni(a, i, j);
  154.     }
  155.     zameni(a, i, r);
  156.     return i;
  157. }
  158.  
  159. Heap sort
  160. efikasnost algoritma je O(n log n)
  161.  
  162. ima prosecnu efikasnost O(n log n) ali je najgori slucaj mnogo losiji O(n^2)
Advertisement
Add Comment
Please, Sign In to add comment