KEMBAR78
Algorithms - a brief introduction | PDF
Algorithms
a brief introduction
Giacomo Belocchi
Liceo Scientifico 'Giovanni Vailati', Genzano di Roma
14-15-16/02/2018
Who am I?
● Ex Vailati student (2009-2014)
● Computer Engineering Bachelor Degree @Università degli
Studi di ROMA 'Tor Vergata' (2014-2017)
● Computer Engineering Master Degree @Università degli
Studi di ROMA 'Tor Vergata' (2017-present)
● Researcher @CNIT (2017-present): new version of the TCP
protocol & network programmability at transport layer
Some numbers…
● On January 2017 there were 1 062 660 523 registered
hosts on DNS servers [11: Internet System Consortium]
● Global mobile traffic grown by 70% in the last year, and
average mobile connection @ ≥10Mbps in 32 countries
[12: The Akamai’s state of Internet]
● The global average Internet connection speed reached
7.2 Mbps, while global broadband adoption above 10
Mbps was 45% [12]
● 77% of Americans have a smartphone in 2018 [14]
… more numbers
● 73.98% of Italians, 81.45% of Americans, 90.84% of
English have a personal computer [13: The world bank]
Used in a vast variety of fields…
● Education
● Health and medicine
● Science
● Business
● Recreation and entertainment
● Government
● Defense [15]
It’s hard to find a field where it’s not used!
[16]
So many users, so many technologies but...
Chris Bishop
Distinguished Scientist, Microsoft
Research Cambridge
Vice President, The Royal Institution
of Great Britain
Professor of Computer Science,
University of Edinburgh
Computing is transforming our society in ways that are
as profound as the changes wrought by physics and
chemistry in the previous two centuries. Indeed, there is
hardly an aspect of our lives that hasn't already been
influenced, or even revolutionized, by digital technology. Given
the importance of computing to modern society, it is therefore
somewhat paradoxical that there is so little awareness
of the fundamental concepts that make it all possible.
The study of these concepts lies at the heart of
computer science, [...] it is rarely taught in high school.
While an introduction to subjects such as physics and
chemistry is generally considered mandatory, it is often
only at the college or university level that computer
science can be studied in its own right. Furthermore, what
is often taught in schools as “computing” or “ICT”
(information and communication technology) is generally
little more than skills training in the use of software
packages.
[1]
Top500 survey [4]
Sunway TaihuLight,
National Supercomputer Center,
Wuxi, Jiangsu, China
Today
●
Sunway TaihuLight: 93 Petaflops = 93*1015
(1000000000000000)
● 1 FLOP = 1 floating point op / 1 s
● Intel® Core™ i9-7980XE Extreme Edition: 1 Tetaflops =
10¹²
● 10 000 times slower but very fast too!
181 years ago, in 1837...
Charles Babbage, English polymath(mathematician,
philosopher, inventor and mechanical engineer)
The Analytical Engine incorporated an arithmetic logic unit,
control flow in the form of conditional branching and loops,
and integrated memory, making it the first design for a
general-purpose computer that could be described in
modern terms as Turing-complete
“Even steam-powered, the analytical engine would have
been able to compute any computable function” [7]
Von Neumann 1945 [8]
John von Neumann, Hungarian-American mathematician,
physicist, and computer scientist.
● CPU: control (decide what instruction to execute), ALU
(performs basic Arithmetical and logic operations)
● Memory: to store the data alongside the program which use
them
● I/O deivces
A computer is an engine that can execute some set of basic
operations, stored in a program (i.e. an algorithm)
Old but gold! Still used today...
Alan Turing 1936
Alan Mathison Turing, English computer scientist, mathematician,
logician, cryptanalyst, philosopher, and theoretical biologist.
Alan Turing presents the notion of a universal machine, later
called the Turing machine, capable of computing anything
that is computable. The central concept of the modern
computer was based on his ideas.
Computable = can be expressed as an algorithm
Formally defined in his paper “On Computable Numbers, with an
Application to the Entscheidungsproblem”
In short Turing defined the mathematical concept of the Turing
machine and Von Neumann the modern realization of it!
A computer is simply an executor of algorithms.
It’s a Turing machine, it can execute every
program that can be expressed as an algorithm.
Every Turing machine is universal, it can execute
every program.
The only things that change is a more powerful
machine can execute the program faster,
because can execute instructions faster… but
every computer can execute the same basic
operations.
What is an algorithm?
A set of instructions defined step-by-step in a way that can
be executed mechanically, producing a well determined
result.
A sequence of computing steps, which receiving an input
return an output ( A: {input} → {output} ). [19]
Is a precise recipe that specifies the exact sequence of
steps required to solve a problem. [1]
The 0 example: ‘moka algorithm’ [19]
1. open the moka pot
2. fill the water chamber with water
3. put the basket filter
4. fill the basket with the coffee powder
5. screw the upper part on the basis
6. put the moka on an heat source
7. when the coffee is ready turn off the heat source
8. pour coffee in a cup
What I want to stress now
An Algorithm is a
solution to a practical
problem, executed on a
general purpose
machine
1st
problem: searching an item in a list [19]
Suppose we have a list of unsorted
numbers. I have to search a specific
number. How to solve the problem?
The pseudo-code
Algorithm linearSearch( list L, element x ) → bool
for each ( y ∈ L ) do
if ( y = x ) then return FOUND
Return NOT_FOUND
2 main ingredients: the if branch and the for each loop
Is it fast?
● We can measure time
● But it’s computer dependent!
Need of a computer independent metric:
● Based on the input size
● Measure number of steps required (i.e. number of
instructions)
An algorithm is a Sequence of computing steps,
that receiving an input return an output, so
given a certain input it will require some
number of instructions, i.e. some numbers of
steps…
So for the linear search?
Algorithm linearSearch( list L, element x ) → bool
for each ( y ∈ L ) do
if ( y = x ) then return FOUND
Return NOT_FOUND
● The if can be considered as 1 step
● How many time the step is repeated?
● It depends on the size of the input
● Let be N the # of the elements of the list. The if step is
repeated at most N times
● So we can say O(N) is the performance of this algorithm
2nd
problem: searching in a sorted list [19]
Suppose we have a sorted list and we
want to look for an item in the list. The
same as before, but we have that the
elements in the list are now sorted.
Can we solve the problem in a better way?
The pseudo-code [20]
Algorithm binarySearch( list L, element x ) → bool
a ← 1
b ← N
while( there are elements in the sub-list starting in a and
ending in b ) do
m ← ( a + b ) / 2
if( L[ m ] > x ) then b ← m - 1
else if( L[ m ] < x ) then a ← m + 1
else then return FOUND
return NOT_FOUND
3rd
problem: sorting a list
But searching on a ordered list requires the list to
be ordered! So sorting algorithms!
Suppose we have an unsorted list and we want to
make it ordered. So the input is the unsorted list
and the output will be the sorted list.
How can we do it?
The pseudo-code [19, 21, 22]
Algorithm bubbleSort( list L ) → void
while ( there are swaps )
for j from 1 to N
if( L[ j ] > L[ j + 1 ] ) then
swap( L[ j ], L[ j + 1 ] )
What are the performance? O( N² ). There are better algorithms!
4th
problem: ranking search results
Suppose we are searching for some web pages, for
example looking for a certain title.
We want that given a title, it will give us back all the pages
with that title.
We can use a search algorithm for an exact match for sure,
but we can make also more complex queries, but we don’t talk
about that here. The only modification of the algorithm, is
that instead of giving the first page found, it will give the
list of all the pages found.
Modified search algorithm
Algorithm linearSearchModified( list L, title t ) → list R
R ← {}
for each ( y ∈ L ) do
if ( y = t ) then insert page in R
Return R
So from a list of pages, e.g. all the pages of the web, and
a title we can obtain the list of all the pages with that
title.
We can obtain a list of the pages that matches a certain
query. But the # of pages that we get, can be very big.
We are rarely interested in all the results, we are rather
interested in the most relevant results.
The random surfer trick
● A web surfer, choose a random page
● Choose randomly one of the exiting links of the page and go
to the linked page
● Every time the random surfer visit a page, has a probability
of 15% to start a again the surf from a randomly chosen
page (the user get bored...)
Every page has a counter of the # of times the random user has
visited it.
random visitor authority = ‘% of time user spent on that
page in respect of all the time spent on the total of pages’
● hyper-link trick: the more incoming links I have, the
more likely the random user will visit me.
● authority trick: the more authority a page have, more
authority I obtain if that page links me. (more high is
the authority, more incoming link I have, more likely
the user will visit me, and so he will more likely visit
the pages that I link).
Problem? Web spammers, there’s lot of research in fixing that
issue!
Lawrence Edward Page & Sergey Brin
Founded Google on 4th
of September 4 in 1998. Pagerank is the
core of their search engine
Questions?
Thanks!
[1] John MacCormick, 9 Algorithms that changed the future
[2] https://www.top500.org/lists/2017/11/slides/ (Top500)
[3] https://en.wikipedia.org/wiki/TOP500
[4] https://www.top500.org/news/china-tops-supercomputer-
rankings-with-new-93-petaflop-machine/
[5]https://en.wikipedia.org/wiki/Analytical_Engine
[6] https://www.livescience.com/20718-computer-history.html
[7] https://www.newscientist.com/article/mg20827915.500-lets-
build-babbages-ultimate-mechanical-computer/
[8] https://en.wikipedia.org/wiki/Von_Neumann_architecture
[9] https://en.wikipedia.org/wiki/Turing%27s_proof
[10] https://www.cs.virginia.edu/~robins/Turing_Paper_1936.pdf
[11]http://ftp.isc.org/www/survey/reports/2017/01/(Internet
Systems Consortium)
[12] https://content.akamai.com/gl-en-pg9135-q1-soti-
connectivity.html (The Akamai’s state of the Internet)
[13]https://tcdata360.worldbank.org/indicators/entrp.household.comp
uter?country=ITA&indicator=3427&viz=choropleth&years=2016 The
world bank
[14] http://www.pewinternet.org/fact-sheet/mobile/
[15] http://ecomputernotes.com/fundamental/introduction-to-
computer/uses-of-computer
[16] https://www.gartner.com/smarterwithgartner/top-trends-in-the-
gartner-hype-cycle-for-emerging-technologies-2017/
[17] https://storiografia.me/2013/11/10/ada-lovelace-e-il-primo-
programma-di-calcolo-della-storia/
[18]http://aulascienze.scuola.zanichelli.it/ieri-oggi-scienza/ada-
lovelace-e-il-primo-algoritmo/
[19] Camil Demetrescu, Irene Finocchi, Giuseppe F. Italiano,
Algoritmi e strutture dati
[20] http://rosettacode.org/wiki/Binary_search
[21] http://www.algorithmist.com/index.php/Bubble_sort
[22] https://en.wikipedia.org/wiki/Bubble_sort

Algorithms - a brief introduction

  • 1.
    Algorithms a brief introduction GiacomoBelocchi Liceo Scientifico 'Giovanni Vailati', Genzano di Roma 14-15-16/02/2018
  • 2.
    Who am I? ●Ex Vailati student (2009-2014) ● Computer Engineering Bachelor Degree @Università degli Studi di ROMA 'Tor Vergata' (2014-2017) ● Computer Engineering Master Degree @Università degli Studi di ROMA 'Tor Vergata' (2017-present) ● Researcher @CNIT (2017-present): new version of the TCP protocol & network programmability at transport layer
  • 3.
    Some numbers… ● OnJanuary 2017 there were 1 062 660 523 registered hosts on DNS servers [11: Internet System Consortium] ● Global mobile traffic grown by 70% in the last year, and average mobile connection @ ≥10Mbps in 32 countries [12: The Akamai’s state of Internet] ● The global average Internet connection speed reached 7.2 Mbps, while global broadband adoption above 10 Mbps was 45% [12] ● 77% of Americans have a smartphone in 2018 [14]
  • 4.
    … more numbers ●73.98% of Italians, 81.45% of Americans, 90.84% of English have a personal computer [13: The world bank]
  • 5.
    Used in avast variety of fields… ● Education ● Health and medicine ● Science ● Business ● Recreation and entertainment ● Government ● Defense [15] It’s hard to find a field where it’s not used!
  • 6.
  • 8.
    So many users,so many technologies but... Chris Bishop Distinguished Scientist, Microsoft Research Cambridge Vice President, The Royal Institution of Great Britain Professor of Computer Science, University of Edinburgh
  • 9.
    Computing is transformingour society in ways that are as profound as the changes wrought by physics and chemistry in the previous two centuries. Indeed, there is hardly an aspect of our lives that hasn't already been influenced, or even revolutionized, by digital technology. Given the importance of computing to modern society, it is therefore somewhat paradoxical that there is so little awareness of the fundamental concepts that make it all possible. The study of these concepts lies at the heart of computer science, [...] it is rarely taught in high school. While an introduction to subjects such as physics and chemistry is generally considered mandatory, it is often only at the college or university level that computer science can be studied in its own right. Furthermore, what is often taught in schools as “computing” or “ICT” (information and communication technology) is generally little more than skills training in the use of software packages. [1]
  • 10.
    Top500 survey [4] SunwayTaihuLight, National Supercomputer Center, Wuxi, Jiangsu, China
  • 11.
    Today ● Sunway TaihuLight: 93Petaflops = 93*1015 (1000000000000000) ● 1 FLOP = 1 floating point op / 1 s ● Intel® Core™ i9-7980XE Extreme Edition: 1 Tetaflops = 10¹² ● 10 000 times slower but very fast too!
  • 12.
    181 years ago,in 1837... Charles Babbage, English polymath(mathematician, philosopher, inventor and mechanical engineer) The Analytical Engine incorporated an arithmetic logic unit, control flow in the form of conditional branching and loops, and integrated memory, making it the first design for a general-purpose computer that could be described in modern terms as Turing-complete “Even steam-powered, the analytical engine would have been able to compute any computable function” [7]
  • 14.
    Von Neumann 1945[8] John von Neumann, Hungarian-American mathematician, physicist, and computer scientist.
  • 16.
    ● CPU: control(decide what instruction to execute), ALU (performs basic Arithmetical and logic operations) ● Memory: to store the data alongside the program which use them ● I/O deivces A computer is an engine that can execute some set of basic operations, stored in a program (i.e. an algorithm) Old but gold! Still used today...
  • 17.
    Alan Turing 1936 AlanMathison Turing, English computer scientist, mathematician, logician, cryptanalyst, philosopher, and theoretical biologist.
  • 18.
    Alan Turing presentsthe notion of a universal machine, later called the Turing machine, capable of computing anything that is computable. The central concept of the modern computer was based on his ideas. Computable = can be expressed as an algorithm Formally defined in his paper “On Computable Numbers, with an Application to the Entscheidungsproblem” In short Turing defined the mathematical concept of the Turing machine and Von Neumann the modern realization of it!
  • 19.
    A computer issimply an executor of algorithms. It’s a Turing machine, it can execute every program that can be expressed as an algorithm. Every Turing machine is universal, it can execute every program. The only things that change is a more powerful machine can execute the program faster, because can execute instructions faster… but every computer can execute the same basic operations.
  • 20.
    What is analgorithm? A set of instructions defined step-by-step in a way that can be executed mechanically, producing a well determined result. A sequence of computing steps, which receiving an input return an output ( A: {input} → {output} ). [19] Is a precise recipe that specifies the exact sequence of steps required to solve a problem. [1]
  • 21.
    The 0 example:‘moka algorithm’ [19] 1. open the moka pot 2. fill the water chamber with water 3. put the basket filter 4. fill the basket with the coffee powder 5. screw the upper part on the basis 6. put the moka on an heat source 7. when the coffee is ready turn off the heat source 8. pour coffee in a cup
  • 23.
    What I wantto stress now An Algorithm is a solution to a practical problem, executed on a general purpose machine
  • 24.
    1st problem: searching anitem in a list [19] Suppose we have a list of unsorted numbers. I have to search a specific number. How to solve the problem?
  • 26.
    The pseudo-code Algorithm linearSearch(list L, element x ) → bool for each ( y ∈ L ) do if ( y = x ) then return FOUND Return NOT_FOUND 2 main ingredients: the if branch and the for each loop
  • 27.
    Is it fast? ●We can measure time ● But it’s computer dependent! Need of a computer independent metric: ● Based on the input size ● Measure number of steps required (i.e. number of instructions)
  • 28.
    An algorithm isa Sequence of computing steps, that receiving an input return an output, so given a certain input it will require some number of instructions, i.e. some numbers of steps… So for the linear search?
  • 29.
    Algorithm linearSearch( listL, element x ) → bool for each ( y ∈ L ) do if ( y = x ) then return FOUND Return NOT_FOUND ● The if can be considered as 1 step ● How many time the step is repeated? ● It depends on the size of the input ● Let be N the # of the elements of the list. The if step is repeated at most N times ● So we can say O(N) is the performance of this algorithm
  • 30.
    2nd problem: searching ina sorted list [19] Suppose we have a sorted list and we want to look for an item in the list. The same as before, but we have that the elements in the list are now sorted. Can we solve the problem in a better way?
  • 32.
    The pseudo-code [20] AlgorithmbinarySearch( list L, element x ) → bool a ← 1 b ← N while( there are elements in the sub-list starting in a and ending in b ) do m ← ( a + b ) / 2 if( L[ m ] > x ) then b ← m - 1 else if( L[ m ] < x ) then a ← m + 1 else then return FOUND return NOT_FOUND
  • 34.
    3rd problem: sorting alist But searching on a ordered list requires the list to be ordered! So sorting algorithms! Suppose we have an unsorted list and we want to make it ordered. So the input is the unsorted list and the output will be the sorted list. How can we do it?
  • 38.
    The pseudo-code [19,21, 22] Algorithm bubbleSort( list L ) → void while ( there are swaps ) for j from 1 to N if( L[ j ] > L[ j + 1 ] ) then swap( L[ j ], L[ j + 1 ] ) What are the performance? O( N² ). There are better algorithms!
  • 39.
    4th problem: ranking searchresults Suppose we are searching for some web pages, for example looking for a certain title. We want that given a title, it will give us back all the pages with that title. We can use a search algorithm for an exact match for sure, but we can make also more complex queries, but we don’t talk about that here. The only modification of the algorithm, is that instead of giving the first page found, it will give the list of all the pages found.
  • 40.
    Modified search algorithm AlgorithmlinearSearchModified( list L, title t ) → list R R ← {} for each ( y ∈ L ) do if ( y = t ) then insert page in R Return R So from a list of pages, e.g. all the pages of the web, and a title we can obtain the list of all the pages with that title. We can obtain a list of the pages that matches a certain query. But the # of pages that we get, can be very big. We are rarely interested in all the results, we are rather interested in the most relevant results.
  • 46.
    The random surfertrick ● A web surfer, choose a random page ● Choose randomly one of the exiting links of the page and go to the linked page ● Every time the random surfer visit a page, has a probability of 15% to start a again the surf from a randomly chosen page (the user get bored...) Every page has a counter of the # of times the random user has visited it.
  • 49.
    random visitor authority= ‘% of time user spent on that page in respect of all the time spent on the total of pages’ ● hyper-link trick: the more incoming links I have, the more likely the random user will visit me. ● authority trick: the more authority a page have, more authority I obtain if that page links me. (more high is the authority, more incoming link I have, more likely the user will visit me, and so he will more likely visit the pages that I link). Problem? Web spammers, there’s lot of research in fixing that issue!
  • 50.
    Lawrence Edward Page& Sergey Brin Founded Google on 4th of September 4 in 1998. Pagerank is the core of their search engine
  • 51.
  • 52.
  • 53.
    [1] John MacCormick,9 Algorithms that changed the future [2] https://www.top500.org/lists/2017/11/slides/ (Top500) [3] https://en.wikipedia.org/wiki/TOP500 [4] https://www.top500.org/news/china-tops-supercomputer- rankings-with-new-93-petaflop-machine/ [5]https://en.wikipedia.org/wiki/Analytical_Engine [6] https://www.livescience.com/20718-computer-history.html [7] https://www.newscientist.com/article/mg20827915.500-lets- build-babbages-ultimate-mechanical-computer/ [8] https://en.wikipedia.org/wiki/Von_Neumann_architecture [9] https://en.wikipedia.org/wiki/Turing%27s_proof [10] https://www.cs.virginia.edu/~robins/Turing_Paper_1936.pdf [11]http://ftp.isc.org/www/survey/reports/2017/01/(Internet Systems Consortium)
  • 54.
    [12] https://content.akamai.com/gl-en-pg9135-q1-soti- connectivity.html (TheAkamai’s state of the Internet) [13]https://tcdata360.worldbank.org/indicators/entrp.household.comp uter?country=ITA&indicator=3427&viz=choropleth&years=2016 The world bank [14] http://www.pewinternet.org/fact-sheet/mobile/ [15] http://ecomputernotes.com/fundamental/introduction-to- computer/uses-of-computer [16] https://www.gartner.com/smarterwithgartner/top-trends-in-the- gartner-hype-cycle-for-emerging-technologies-2017/ [17] https://storiografia.me/2013/11/10/ada-lovelace-e-il-primo- programma-di-calcolo-della-storia/
  • 55.
    [18]http://aulascienze.scuola.zanichelli.it/ieri-oggi-scienza/ada- lovelace-e-il-primo-algoritmo/ [19] Camil Demetrescu,Irene Finocchi, Giuseppe F. Italiano, Algoritmi e strutture dati [20] http://rosettacode.org/wiki/Binary_search [21] http://www.algorithmist.com/index.php/Bubble_sort [22] https://en.wikipedia.org/wiki/Bubble_sort