Feedback: Journal 2 Progress Difficulties: absolute and relative - - PowerPoint PPT Presentation

feedback journal 2
SMART_READER_LITE
LIVE PREVIEW

Feedback: Journal 2 Progress Difficulties: absolute and relative - - PowerPoint PPT Presentation

ICC Module Computation: Computation & Algorithms I Feedback: Journal 2 Progress Difficulties: absolute and relative error floating point numbers Saturday session (Registration) Length of Friday session: ideally 45min


slide-1
SLIDE 1

ICC Module Computation: Computation & Algorithms I

1

Feedback: Journal 2

§ Progress § Difficulties:

  • absolute and relative error
  • floating point numbers
  • Saturday session (Registration)

§ Length of Friday session: ideally

  • 45min recap and examples
  • 45min questions

§ Questions on the Chat

  • repeat for live audience
  • In Zoom use Q&A today

§ Repetition of material § Do we have to know the history presented in the book p:81-p:84? Non (please ask in Piazza)

Average: 82%

slide-2
SLIDE 2

ICC Module Computation: Computation & Algorithms I

2

§ During the week: comments and questions in Piazza (You can write to all, instructors, or just me) § During the lecture:

  • Zoom Q&A
  • Turning Point

Feedback from you

https://participant.turningtechnologies.eu/fr/join

  • r

https://go.epfl.ch/turningpoint Session: ICCSV2020

slide-3
SLIDE 3

How easy is it to use Turning Point?

  • A. Really easy
  • B. Easy
  • C. Difficult
  • D. Very difficult

Question

slide-4
SLIDE 4

ICC Module Computation: Computation & Algorithms I

4

Information, Computation, and Communication

Algorithm 1

slide-5
SLIDE 5

ICC Module Computation: Computation & Algorithms I

5

§ “Algorithm’ is arguably the single most important concept in our world. If we want to understand our life and our future, we should make every effort to understand what an algorithm is, and how algorithms are connected with emotions.”

Yuval Noah Harari, Homo Deus: A Brief History of Tomorrow

Shaping the Future

slide-6
SLIDE 6

ICC Module Computation: Computation & Algorithms I

6

§ An algorithm is an effective method, expressed as a finite list of well-defined instructions for calculating a function.

[Wikipedia]

§ Algorithms exist well before computers: already in ancient history (e.g., Egyptian division, Euclid’s algorithm for greatest- common-divisor) What is an Algorithm?

slide-7
SLIDE 7

ICC Module Computation: Computation & Algorithms I

7

§ Binary addition § Binary to decimal conversion and vice versa § Procedure to compute the 2s complement § Solving a quadratic equation (e.g., 3x2 + 5x + 2) § Sorting a list of elements § Searching for an element in a list § Identifying gene in a DNA-sequence § Pagerank/Edgerank

Examples

slide-8
SLIDE 8

ICC Module Computation: Computation & Algorithms I

8

§ Name and description of inputs and output § Variables (Place holder) to refer to a single element or a list of elements § Access an element in a list (parenthèse/crochet): L(1),L[1],A[4] § Access a sub-list: L(1:4), A[5:6] § Assignments (Affectation) : § Mathematical operators: § Reference to another algorithm:

Pseudo-Code

slide-9
SLIDE 9

ICC Module Computation: Computation & Algorithms I

9

§ Control structures (if, for, while) § Termination statement:

Pseudo-Code (Cnt.)

Tests Loops Conditional Loops

slide-10
SLIDE 10

ICC Module Computation: Computation & Algorithms I

10

  • 1. Understand an algorithm
  • 2. Write an algorithm
  • 3. Analyze an algorithm

Our Tasks

slide-11
SLIDE 11

ICC Module Computation: Computation & Algorithms I

11

Task 1: Understanding an Algorithm

What computation does this algorithm perform for L = {3, 6, 2, 1, 10, 9}?

slide-12
SLIDE 12

What is the output of algo1 if L = {3, 6, 2, 1, 10, 9}?

  • A. 1
  • B. 3
  • C. 6
  • D. 15

Quiz

slide-13
SLIDE 13

ICC Module Computation: Computation & Algorithms I

13

§ Problem: computing the GC-Content in a given DNA seq. § GC-content (or guanine-cytosine content) is the percentage of bases in a DNA (or RNA) molecule that are either guanine (G) or cytosine (C). Recall that a strand of DNA is a sequence of A, T, C, and G’s. § E.g., GC-content of ACCGC = 4/5=0.8 GC-content of ATACTAAA = 1/8=0.125 § Basic instructions: access element in list, compare element in list to G/C, addition and division

Task 2: Writing an Algorithm

slide-14
SLIDE 14

ICC Module Computation: Computation & Algorithms I

14

GC-Content

slide-15
SLIDE 15

ICC Module Computation: Computation & Algorithms I

15

§ A codon is a sequence of three DNA or RNA nucleotides that corresponds to a specific amino acid

  • r a stop signal during protein synthesis.

§ Of the 64 codons, 61 represent amino acids, and three are stop signals. For example, the RNA codon UAA is a stop codon.

Find Stop Codon

§ Problem: Given a RNA sequence of length n, find the start position of a UAA stop codon.

slide-16
SLIDE 16

ICC Module Computation: Computation & Algorithms I

16

slide-17
SLIDE 17

ICC Module Computation: Computation & Algorithms I

17

Task 3: Analysis of an Algorithm

§ Key Questions about an Algorithm

  • Is it correct?
  • Is it efficient?
slide-18
SLIDE 18

ICC Module Computation: Computation & Algorithms I

18

  • 1. Does the algorithm terminate for all input?
  • 2. Does it give us the result we aim for?
  • In the common case
  • In corner cases (e.g., empty list, value 0)
  • In all cases

Strategies to analyze correctness:

  • Testing, i.e., run the algorithm with different inputs

and compare the output with the expected output

  • Mathematical reasoning (CS-550)

Correctness

slide-19
SLIDE 19

ICC Module Computation: Computation & Algorithms I

19

Be Aware of the Corner Cases!

§ What happens if n=0?

slide-20
SLIDE 20

ICC Module Computation: Computation & Algorithms I

20

§ How much time and space (memory) does it need? We focus on time

  • complexity. (Number of elementary instructions)

§ In general the complexity is always given in terms of the total input size, e.g., if an algorithm has two inputs x, y, the complexity is a function of the size of x and y. We focus on one input. § Actually running time can depend a lot on specific input: best, average worst-case behavior. We focus on worst-case behavior. § Finally, for small input values usually all algorithms are fast. We are interested in the complexity on large inputs, the complexity when the size of the input goes towards infinity, called the asymptotic complexity (Big Theta or Big O notation)

Complexity of an Algorithm

slide-21
SLIDE 21

ICC Module Computation: Computation & Algorithms I

21

§ The runtime of an algorithm is computed in terms of instructions that can be performed in constant time. We assume that the following instructions can be performed in constant time:

  • Assignments (Affectation)
  • Mathematical operators (e.g., a+b) using numbers with a fixed

number of bits (e.g., 32 or 64)

  • Access an element in a list
  • Access a sub-list

§ Question to answer: How many of these instructions does an algorithm use (or ”read”)? § Caution! In one of the exercises we assume a non-fixed number of bits and therefore addition is not performed in constant time.

Elementary Instructions

slide-22
SLIDE 22

ICC Module Computation: Computation & Algorithms I

22

§ Compute the number of instructions per line

Complexity: Step 1

Line Instructions Cost 1 1 assignment 1 2 1 assignments, 1 comparison, (1 addition) 3 3 2 list access, 2 comparison 4 4 1 addition, 1 assignment 2 5 1 division, 1 return 2

The precise costs per line (e.g., value 2, 3 or 5) are not important because we will approximate the overall complexity later. Important is to know if the cost is constant or not, e.g., a line in which another algorithm is called.

slide-23
SLIDE 23

ICC Module Computation: Computation & Algorithms I

23

§ Compute how many times a line is execute or “read” (in the worst case)

Complexity: Step 2

Line Cost Repetitions 1 1 1 2 3 n 3 4 n 4 2 n 5 2 1

slide-24
SLIDE 24

ICC Module Computation: Computation & Algorithms I

24

§ Sum the costs・repetitions of all lines: !

!"# $

𝑑 𝑗 $ 𝑠(𝑗) = 1 + 3𝑜 + 4𝑜 + 2𝑜 + 2 = 9𝑜 + 3

Complexity: Step 3

Line Cost Repetitions 1 1 1 2 3 n 3 4 n 4 2 n 5 2 1

slide-25
SLIDE 25

ICC Module Computation: Computation & Algorithms I

25

§ Approximate with Big O or Big Theta notation

Complexity: Step 4

slide-26
SLIDE 26

ICC Module Computation: Computation & Algorithms I

26

It is important to know how complexity evolves according to the input size. For this, compare asymptotic orders of magnitude (when the size of the input data goes to the infinite) using the Landau notations O(..) or Θ(..) For two functions f and g from ℝ to ℝ, 𝑔 ∈ 𝑃 𝑕 or (𝑔 = 𝑃(𝑕) ) if and only if In this case, we say that f is (in) “big-oh” of g. This means that f grows asymptotically no faster than g.

Complexity: Notation O(...)

slide-27
SLIDE 27

ICC Module Computation: Computation & Algorithms I

27

Example of Growth

f (n) = n2 + 100n + logn + 1000 Table with the contributions of the different terms:

n f (n) n2 100n log n 1000 value % value % value % value % 1 1’101 1 0.1 100 9.1 0.0 1000 90.82 10 2’101 100 4.8 1’000 47.6 1 0.0 1000 47.6 100 21’002 10’000 47.6 10’000 47.6 2 0.0 1000 4.8 1000 1’101’003 106 90.8 105 9.1 3 0.0 1000 0.1 10’000 101’001’004 108 99.0 106 1.0 4 0.0 1000 0.0 ...

slide-28
SLIDE 28

ICC Module Computation: Computation & Algorithms I

28

f (n) = n2 + 100n + logn + 1000

1e+08 1e+07 1e+06 100000 10000 1000 100 10 1 1 10 100 1000 10000 f(x) x*x 100*x log(x) 1000

Example of Growth (continued)

f(n) = O (n) f(n) = Θ (n)

slide-29
SLIDE 29

ICC Module Computation: Computation & Algorithms I

29

We use the smallest of the possible “Big O” noted as Θ (Big Theta) Examples:

  • f(n)=n is O(n2) but it is also O(n)
  • f(n)=12 is O(n2), O(n), but especially O(1)

Different complexity classes characterize algorithms (n is the input size) : § complexity constant O(1): number of elements does not influence algorithm § logarithmic complexity O(log n) § linear complexity O(n) § quasi-linear complexity O(n log(n)) § polynomial complexity e O(n2), ... O(nk ) § exponential complexity O(2n ), O(3n ), …

Comparison of Algorithms

slide-30
SLIDE 30

ICC Module Computation: Computation & Algorithms I

30

§ Approximate with Big O/Theta notation

Complexity: Step 4

Line Cost Repetitions 1 1 1 2 3 n 3 4 n 4 2 n 5 2 1

∃𝑑 > 0∃𝑦!∀𝑦 > 𝑦! 𝑔 𝑦 ≤ 𝑑 ) |𝑕 𝑦 | Recall: 𝑔 𝑜 = 9 ) 𝑜 + 3 with 𝑑 = 10 and 𝑜! = 2 ∀𝑜 > 𝑜!9 ) 𝑜 + 3 ≤ 𝑑 ) 𝑜 𝒈 𝒐 is in 𝑷(𝒐)

slide-31
SLIDE 31

Which of the following statements is false?

  • A. A
  • B. B
  • C. C
  • D. D
  • E. E
  • A. 10 $ 𝑜% + 5 $ 𝑜 is in 𝑃 𝑜&
  • B. 2 $ 𝑜' is in Θ 𝑜%
  • C. 10#( is in Θ 1
  • D. 10 + 2𝑜 + 𝑜 is in 𝑃 𝑜
  • E. 2 $ 𝑚𝑝𝑕% 𝑜 is in Θ 𝑚𝑝𝑕' 𝑜

Quiz

slide-32
SLIDE 32

ICC Module Computation: Computation & Algorithms I

32

Logarithms

𝑚𝑝𝑕" 𝑜 = 𝑚𝑝𝑕# 𝑜 𝑚𝑝𝑕# 𝑏 = 1 𝑚𝑝𝑕# 𝑏 𝑚𝑝𝑕# 𝑜 𝑚𝑝𝑕$! 𝑜 = 1 𝑚𝑝𝑕% 10 𝑚𝑝𝑕% 𝑜 log2 log10

slide-33
SLIDE 33

What is the complexity of this algorithm?

  • A. O(1)
  • B. O(log(n))
  • C. O(n)
  • D. O(n2)

Quiz

slide-34
SLIDE 34

ICC Module Computation: Computation & Algorithms I

34

Questions ?