



Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Prepara i tuoi esami
Studia grazie alle numerose risorse presenti su Docsity
Prepara i tuoi esami con i documenti condivisi da studenti come te su Docsity
Trova i documenti specifici per gli esami della tua università
Preparati con lezioni e prove svolte basate sui programmi universitari!
Rispondi a reali domande d’esame e scopri la tua preparazione
Riassumi i tuoi documenti, fagli domande, convertili in quiz e mappe concettuali
Studia con prove svolte, tesine e consigli utili
Togliti ogni dubbio leggendo le risposte alle domande fatte da altri studenti come te
Esplora i documenti più scaricati per gli argomenti di studio più popolari
Ottieni i punti per scaricare
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
appunti in classe su secondo parziale
Tipologia: Appunti
1 / 5
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!




Example: A: <5, 2, 4, 6, 1, 3> Index 1 2 3 4 5 6 A 5 2 4 6 1 3 We change 1 with 5 because 1 is the min. 1, 2, 4, 6, 5, 3 You always scam all the list and then you exchange the value. Then you compare 2 with all the values and at the last index you have 4<3? False, so 3 is the new min, and you change it with 4. 1, 2, 3, 6, 5, 4 3 is the new min so you compare 6 with all the elements and at the last index you have 6<4? False, so you change it with 4 and you have: 1, 2, 3, 4, 5, 6 The complexity is quadratic because in the worst case you have 6^6. In terms of asymptotic running time selection sort and insertion sort are the same. Basically selection sort doesn’t make any difference between the worst case and all the other cases, whereas insertion sort is linear except for the worst case. SELECTION-SORT(A) n = len(A) for j = 1 to n-1 do minimum= j for i = j + 1 to n do if (A[i] < A[min]) then minimum = i exchange A[j] with A[minimum] When you reach n-1 the number n is sorted by definition that’s why you go on until n-1 and not until n. In pseudocode and python you don’t have to specify the update (j = j+1), because in the for loop is implicit in the to, so every time you start again the for, j is automatically updated. In the second iteration it would be j = 2 and then you start again. When you see multiple loops nested inside one other the complexity is quadratic. 24/11/ FILE SYSTEM WHAT’S A FILE? A file is a contiguous logical address space. This means that it is a sequence of bytes in our hard drive that is logical contiguous. This is the formal definition. A file is defined by its type :
We have the list of folders and files (folder or directory is a file) and we have other information: for instance the name and the hierarchical organization of the files. In the file system files, meaning directories and sigle flies, are organized hierarchically like in a tree : we have the root which is the source of your hard drive (windows C:/; in MAC //); folders and subfolders. Also the visualization is hierarchical. Then you get on the right the type of the file (folder, document, keynote, and so on). FILE INFORMATION (OSx) When you rightclick a file and you get to more information or properties of a file you open a tab with all the information about a file. In Mac for instance you have an overview of the file where you have the name, last modification and the size of the file; then you have the kind, size and path-to-file (where) = the path from the source to the file that you interested on → we need the path because the file path is what tells the program where to find a specific file. After the path you have date and time. Then there are info depending on the file type. Then name and extension of the file (make sure that your operating system are not hiding the extension). Open with says the program how to open the file. In the end you have the permissions that says who can read and write, who can read only or write only. The file is identified by a name and by an extension.
- Directories or folders are files (are the same thing)
Another fundamental command is ls (dir in windows) that returns the list of files and directories. You see everything inside the folder. When you write ls - la returns the list of files and directories with details : CHANGE DIRECTORY The command cd allows you to move from a directory to the other. To do this you use cd + filepath and then you ask where you are with the pwd command.