| |
Mihai Bâce
mihai.bace@inf.ethz.ch
December 14, 2019 1
Informatik II
Tutorial 12
Mihai Bâce
Informatik II Tutorial 12 Mihai Bce mihai.bace@inf.ethz.ch Mihai - - PowerPoint PPT Presentation
Informatik II Tutorial 12 Mihai Bce mihai.bace@inf.ethz.ch Mihai Bce | | December 14, 2019 1 Overview Debriefing Exercise 11 Briefing Exercise 12 Mihai Bce | | December 14, 2019 2 U11 Time Complexity Notation Intuitive
| |
mihai.bace@inf.ethz.ch
December 14, 2019 1
Mihai Bâce
| | December 14, 2019 Mihai Bâce 2
| | December 14, 2019 Mihai Bâce 3
http://de.wikipedia.org/wiki/Landau-Symbole
Notation Name O(1) Constant O(log(n)) Logarithmic O((log(n))c) Polylogarithmic O(n) Linear O(n2) Quadratic O(nc) Polynomial O(cn) Exponential Notation Intuitive Meaning f ∈ O(g) f does not grow faster than g f ∈ Ω(g) f does not grow much slower than g f ∈ θ(g) f grows exactly as quickly as g
| | December 14, 2019 Mihai Bâce 4
| | December 14, 2019 Mihai Bâce 5
// Fragment 4
for (int i=0; i<n; i++) for (int j=0; j<i; j++) a++;
// Fragment 5
while(n >=1 ) n = n/2;
// Fragment 6
for (int i=0; i<n; i++) for (int j=0; j<n*n; j++) for (int k=0; k<j; k++) a++;
// Fragment 1
for (int i=0; i<n; i++) a++;
// Fragment 2
for (int i=0; i<2n; i++) a++; for (int j=0; j<n; j++) a++;
// Fragment 3
for (int i=0; i<n; i++) for (int j=0; j<n; j++) a++;
O(n5) O(n) O(logn) O(n2) O(n2) O(n)
| | December 14, 2019 Mihai Bâce 6
| | December 14, 2019 Mihai Bâce 7
~1,7 ~1,5
| | December 14, 2019 Mihai Bâce 8
| | December 14, 2019 Mihai Bâce 9
| | December 14, 2019 Mihai Bâce 10
Test position Max depth Current depth List of visited positions If position not visited, add to visited list Recursively check all the
from the current one
| | December 14, 2019 Mihai Bâce 11
| | December 14, 2019 Mihai Bâce 12
If pos is already visited Otherwise, add the pos to the path and check for termination Explore all other positions from this one Backtrack: we cannot find a solution from this position. Remove current position
| | December 14, 2019 Mihai Bâce 13
| | December 14, 2019 Mihai Bâce 14
§ value (previous (k)) ≤ value (k) in a MIN-Heap § Or ≥ in a MAX-Heap
| | December 14, 2019 Mihai Bâce 15
4 10 11 6 17 12 13 18 16 19 insert
4
1
6
2
10
3
12
4
13
5
11
6
17
7
18
8
16
9
19
10 11
| | December 14, 2019 Mihai Bâce 16
http://en.wikipedia.org/wiki/File:Heapsort-example.gif
| | December 14, 2019 Mihai Bâce 17
a) Much is up to you
n
u10a1.ISort you still (hopefully) have
n
ISort.sort: returns a sorted copy of the vector
n
Your MergeSort class should provide a way to select the number of parallel threads b) 1'000'000 Integers
n
A main class to perform the measurements
n
Here also U10 A1 offers a reference
n
An important indication of your measurements is the number of available CPU cores on your system (Google helps)
n
Don't forget the explanation!
| |
December 14, 2019 Mihai Bâce 18
| |
December 14, 2019 Mihai Bâce 19
public class HelloRunnable implements Runnable { public void run() { System.out.println("Hello from a thread!"); } public static void main(String args[]) { (new Thread(new HelloRunnable())).start(); } } public class HelloThread extends Thread { public void run() { System.out.println("Hello from a thread!"); } public static void main(String args[]) { (new HelloThread()).start(); } }
| |
December 14, 2019 Mihai Bâce 20
| | December 14, 2019 Mihai Bâce 21
§ The company “Springli” intends to bring a new chocolate on the market § Acceptance of all rectangular formats with a maximum of n bits must be tested § How many formats in terms of n must the company Springli test in the market? § Hint: § For n = 1, 2, 3, 4, 5, 6 exists 1, 3, 5, 8, 10, 14 formats. Springli Springli Springli Springli
| | December 14, 2019 Mihai Bâce 22
Springli
| | December 14, 2019 Mihai Bâce 23
Springli Springli Springli Springli Springli
| | December 14, 2019 Mihai Bâce 24
Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli
| | December 14, 2019 Mihai Bâce 25
Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli Springli
| | December 14, 2019 Mihai Bâce 26
| |
§ E-mail before to arrange an appointment
December 14, 2019 Mihai Bâce 27
| | December 14, 2019 Mihai Bâce 28
Image