1 / 18

Algoritmi e Strutture Dati 8 crediti

Algoritmi e Strutture Dati 8 crediti. Calendario: 1 Ott. – 6 Dic. Aula: LuM250 Orario: Lun , Mar, Mer , Gio 15.30-17.30 Giorni di lezione disponibili 40 ~ 48 ore di teoria, ~ 18 ore di esercizi e 4 ore per le prove parziali I sessione esami: Dic 9-20 Gen 7-11.

Download Presentation

Algoritmi e Strutture Dati 8 crediti

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algoritmi e Strutture Dati8 crediti Calendario: 1 Ott. – 6 Dic. Aula: LuM250 Orario: Lun, Mar, Mer, Gio 15.30-17.30 Giorni di lezione disponibili 40 ~48 ore di teoria, ~18 ore di esercizi e 4 ore per le prove parziali I sessione esami: Dic9-20 Gen7-11

  2. 5 scritti (+ 2 compitini: uno a metà del corso ed uno a fine corso o assieme al primo appello). Indispensabile iscriversi nella lista di esame che verrà attivata su UNIWEB. Colloquio e registrazione: principalmente discussione dello scritto con qualche domanda di teoria. Si è ammessi al colloquio con almeno 17/30 come voto dello scritto.

  3. Testo: Introduzione agli Algoritmi e Strutture Dati (terza edizione). T.H.Cormen, C.E.Leiserson, R.L.Rivest, C.Stein. McGraw-Hill. oppure la versione inglese: IntroductiontoAlgorithms and Data Structures (terza edizione). T.H.Cormen, C.E.Leiserson, R.L.Rivest, C.Stein. MIT Press. Altro materiale didattico verrà messo nel sito: www.math.unipd.it/~colussi

  4. Programma Le prime 5 parti del testo (con poche omissioni): Fondamenti: notazione per gli algoritmi e primi esempi di algoritmi e di analisi degli algoritmi Ordinamento e statistiche d’ordine Strutture dati fondamentali Tecniche avanzate di progettazione ed analisi degli algoritmi Strutture dati avanzate

  5. INTRODUZIONE I problemi computazionali, gli algoritmi che li risolvono e le tecniche per sviluppare tali algoritmi Esempio1: problema dell’ordinamento Input: a1,a2,...,an Output: a'1,a'2,...,a'npermutazione (riarrangiamento) di a1,a2,...,an tale che a'1  a'2  ... a'n

  6. TECNICA INCREMENTALE

  7. A n 1 A n 1 j A A n n 1 1 j j key A n 1 i j key A n 1 j i key A n 1 j i A n 1 Soluzione1: Algoritmo Insertion-Sort. InsertionSort j

  8. Insertion-Sort(A) n= A.length forj= 2 ton key=A[j] // inseriamo A[j] nella sequenza // ordinata A[1..j-1] i=j - 1 whilei> 0 andA[i] > key A[i+1] =A[i] i=i – 1 A[i+1] =key

  9. Insertion-Sort(A) n= A.length forj= 2 ton key= A[j] // inseriamo A[j] nella // sequenza ordinata // A[1..j-1] i = j – 1 whilei > 0 andA[i] > key A[i+1] = A[i] i =i– 1 A[i+1] = key voidInsertion-Sort(vector<T> A) { inti, j, n = A.size(); T key; for (j= 1; j < n; j++) { key=A[j]; // inseriamo A[j] nella // sequenza ordinata // A[0..j-1] i=j – 1; while (i >= 0 &&A[i] > key) { A[i+1] =A[i]; i--; } A[i+1] =key; } }

  10. A key 5 2 8 4 7 1 3 6 Insertion-Sort(A) n = A.length forj = 2 ton // inserisce A[j] nella // sequenza ordinata // A[1..j-1] key = A[j] i = j – 1 whilei > 0 andA[i] > key A[i+1] = A[i] i = i – 1 A[i+1] = key 5 # 8 4 7 1 3 6 2 # 5 8 4 7 1 3 6 2 5 8 4 7 1 3 6 2 5 # 4 7 1 3 6 8 2 5 # 4 7 1 3 6 2 5 8 4 7 1 3 6 2 5 8 # 7 1 3 6 4 2 # 5 8 7 1 3 6 2 4 5 8 7 1 3 6 2 4 5 8 # 1 3 6 7 2 4 5 # 8 1 3 6 2 4 5 7 8 1 3 6

  11. A key 2 4 5 7 8 1 3 6 Insertion-Sort(A) n = A.lenght forj = 2 ton // inserisce A[j] nella // sequenza ordinata // A[1..j-1] key = A[j] i = j – 1 whilei > 0 andA[i] > key A[i+1] = A[i] i = i – 1 A[i+1] = key 2 4 5 7 8 # 3 6 1 # 2 4 5 7 8 3 6 1 2 4 5 7 8 3 6 1 2 4 5 7 8 # 6 3 1 2 # 4 5 7 8 6 1 2 3 4 5 7 8 6 1 2 3 4 5 7 8 # 6 1 2 3 4 5 # 7 8 1 2 3 4 5 6 7 8

  12. A A i 1 1 n n j j i A n 1 j A 1 n j i A 1 n j Analisi di Insertion-Sort: correttezza Correttezza InsertionSort Insertion-Sort(A) n = A.length forj = 2 ton key = A[j] i = j - 1 whilei > 0 andA[i] > key A[i+1] = A[i] i = i – 1 A[i+1] = key

  13. Analisi di Insertion-Sort: complessità Insertion-Sort(A) // n = A.length// forj = 2 ton// key = A[j] // i = j -1 // whilei > 0 andA[i] > key// A[i+1] = A[i] // i = i – 1 // A[i+1] = key//

  14. caso migliore:

  15. caso peggiore:

  16. caso medio:

  17. TECNICA DIVIDE ET IMPERA

  18. 5 2 8 0 4 7 1 9 3 2 6 5 2 8 0 4 7 1 9 3 2 6 5 2 8 0 4 7 1 9 3 2 6 5 2 0 4 1 9 Soluzione2: Algoritmo Merge-Sort 0 1 2 2 3 4 5 6 7 8 9 5 2 8 0 4 7 1 9 3 2 6 5 2 8 0 4 7 1 9 3 2 6 0 2 4 5 7 8 5 2 8 0 4 7 1 2 3 6 9 1 9 3 2 6 5 2 8 2 5 8 0 4 7 0 4 7 1 3 9 1 9 3 2 6 2 6 5 2 2 5 8 8 0 4 0 4 7 7 1 9 1 9 3 3 2 2 6 6 5 5 2 2 0 0 4 4 1 1 9 9

More Related