Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Selection sort
- - metoda koja se preporucuje za mali broj elemenata (spora je)
- 8,2,4,9,5,6
- jedan kvadratic
- drugi -||-
- treci -||-
- "Leva saka je otisla dole..." - Z.M (2016)
- Prazan kvadratic dole
- Ovaj je leva ruka
- ovo je broj osam
- ovo ovde je broj 5
- broj 5 je preso na broj 8
- iz temp je preso na broj 5
- Metoda zamene
- Uporedjuje susedne elemente i zamenjuje ih ukoliko nisu u odgovarajucem redu
- - bubble sort
- - sink sort
- n^2/2 poredjenja i n^2/2 zamena u proseku i najgorem slucaju
- Najsporiji od svih O(n^2) algoritama
- http://www.pmf.ni.ac.rs/pmf/predmeti/7011/sortiranje.pdf
- Insertion sort
- I tako dalje i tako blize
- 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
- http://perun.pmf.uns.ac.rs/index.php?option=com_content&task=view&id=31&Itemid=39
- 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
- http://documents.tips/download/link/seminarski-metode-sortiranja-unutrasnje-i-spoljasne-sortiranje
- odradi kod i primere za InsertionSort i BubbleSort
- Sabiranje 2 broja (varijable, unos i niz od 5 clanova)
- Posle toga sortiranje
- Shell nismo radili
- SortiranjeMerge
- kompleksnost O(n log n)
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package sortiranjeinsert;
- /**
- *
- * @author VSSS
- */
- public class SortiranjeInsert {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- int[] niz = {8, 1, 6, 4, 7};
- for(int i = 0; i < niz.length; i++) System.out.print(" " + niz[i]);
- System.out.println();
- InsertionSort(niz);
- for(int i = 0; i < niz.length; i++) System.out.print(" " + niz[i]);
- // TODO code application logic here
- }
- public static void InsertionSort(int[] aArray) {
- int i, j, index;
- for(i = 1; i < aArray.length; i++) {
- index = aArray[i];
- j = i;
- while( (j > 0) && (aArray[j - 1] > index) ) {
- aArray[j] = aArray[j-1];
- j--;
- }
- aArray[j] = index;
- }
- }
- public static void MergeSort(int[] aArray) {
- mergeSort(aArray, 0, aArray.length - 1);
- }
- private static void mergeSort(int[] aArray, int aLeft, int aRight) {
- if(aRight > aLeft) {
- int middle = (aRight + aLeft) / 2;
- mergeSort(aArray, aLeft, middle);
- mergeSort(aArray, middle + 1, aRight);
- //merge(aArray, aLeft, middle + 1, aRight);
- }
- }
- }
- Quick sort metoda
- (Zavadi pa vladaj - podeli pa vladaj)
- deli niz u dva manja
- manji se dalje dele na isti nacin
- na kraju se spajaju
- sortira se tako sto se deli niz na 2 dela L i D po "pivotu"
- rekurzivno sortira podnizove L i D
- < pivot > pivot
- LLLLLLLLLLLLL DDDDDDDDDDDDDD
- 5, 3, 7, 9, 8, [11], 14, 23, 15, 15
- pivot je 11
- Quick Sort
- i++
- j--
- i tako sve dok se ne sretnu vrsi se zamena (leva strana manji, desna veci)
- Kad se sretnu pivot i element na tom mestu se menjaju.
- I tako dalje ide rekurzivno.
- static void quicksort(int[] a, int l, int r) {
- if(r <= l) return;
- int i = partition(a, l, r);
- quicksort(a, l, i - 1);
- quicksort(a, l + 1, r);
- }
- static int partition(int a[], int l, int r) {
- int i = l - 1; j = r; int v = a[r];
- for(;;) {
- while(a[++i] < v);
- while(v < a[--j]) if(j == l) break;
- if(i >= j) break;
- zameni(a, i, j);
- }
- zameni(a, i, r);
- return i;
- }
- Heap sort
- efikasnost algoritma je O(n log n)
- 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