Docsity
Docsity

Prepara i tuoi esami
Prepara i tuoi esami

Studia grazie alle numerose risorse presenti su Docsity


Ottieni i punti per scaricare
Ottieni i punti per scaricare

Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium


Guide e consigli
Guide e consigli


Computational thinking secondo parziale, Appunti di Programmazione e Tecnologie Web

appunti in classe su secondo parziale

Tipologia: Appunti

2019/2020

Caricato il 26/12/2020

matildecoppoli
matildecoppoli 🇮🇹

4.4

(53)

21 documenti

1 / 5

Toggle sidebar

Questa pagina non è visibile nell’anteprima

Non perderti parti importanti!

bg1
17/11/20
SELECTION SORT
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/20
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:
1) Data: numeric, character, binary;
2) Program (phyton code)
The contents are defined by file’s creator: we have many types (text files, source files, executable files).
1
pf3
pf4
pf5

Anteprima parziale del testo

Scarica Computational thinking secondo parziale e più Appunti in PDF di Programmazione e Tecnologie Web solo su Docsity!

SELECTION SORT

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 :

  1. Data : numeric, character, binary; 2) Program (phyton code) The contents are defined by file’s creator: we have many types (text files, source files, executable files).

FILE ATTRIBUTES

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

- Directories or folders are files (are the same thing)

  • They contain pointers to set of files : so when you open a folder and you see a list of subfolders or files it means that the folder is a file that is shown as a container of other files
  • They can contain files and/or other directories
  • The are organized in a hierarchical fashion (tree)
  • The root of the tree is the origin of the file system:
    1. In OS X: / is the root
    2. In Windows: C is the root The sequence of directories from the root to a file is called file path. EXAMPLE OF DIRECTORY STRUCTURE This is a representation of a website. The root is the folder called “film and dintorni” and this folder contains 2 sub-folders and one file (attori, film and index.html where the name of the file is index and the extension is html), then the folder “attori” contains 2 sub-folders: “foto” and “bio”, where “foto” contains a sub-file “face.png” and “bio” contains 2 files “allen.html” and “keaton.html”. For instance “zelig.html” is a leaf or external node. A file is always a leaf because a file does not contain anything else, instead a folder if it is empty is a leaf otherwise it contains something else. A path is how we go from to “film e dintorni” to a file. /film-e-dintorni/ → the slash is used to enter a folder. The path to keaton.html is: /film-e-dintorni/attori/bio/keaton.html → this is true everywhere because we are starting from a specific folder, not from the root of the hardware. THE TERMINAL OR SHELL: HOW TO LOCATE A FILE What you want to ask when you open the terminal is “ where am I? ” → you use the pwd command that returns the path to the current position. In the figure we are into the folder “silvello” contained in the folder “Users”:

LIST OF DIRECTORIES AND FILES

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.