Biol

113
carlo zapponi @littleark Bioluminescent creatures of the deep sea GOTO Berlin Berlin 6 th November 2014 @GOTOber #gotober

description

Presentation for GOTO Berlin 2014. Sorting algorithms are computational processes used to organize elements of a sequence in a certain order. In the last months I have tried to understand and transform the data left behind sorting algorithms into elegant visual forms that could help highlight the unique characteristics of each algorithm and find hidden patterns. SORTING (http://sorting.at) is the result of this exploration. This session explored some of the most famous and interesting sorting algorithms through their history, visualization and implementation with D3.js and require.js

Transcript of Biol

Page 1: Biol

carlo zapponi

@littleark

Bioluminescent creatures of the deep sea

GOTO Berlin

Berlin 6th November 2014

@GOTOber #gotober

Page 2: Biol

Give your proposal a simple and

straightforward title.

Page 3: Biol

Clever or inappropriate titles

make it harder for people to

figure out what you’re really

talking about.

Page 4: Biol

Bioluminescent creatures

of the deep sea.

Page 5: Biol

what are we really

talking about today?

Page 6: Biol

ALGORITHMS

Page 7: Biol

SORTING ALGORITHMS

Page 8: Biol

hold on! don’t run away

because we’ll talk about…

Page 9: Biol

VISUALIZING

SORTING ALGORITHMS

Page 10: Biol

fun facts

Page 11: Biol

changing face of America

Page 12: Biol
Page 13: Biol

atlanta falcons

Page 14: Biol

https://twitter.com/mr_mdjones/status/524874356879790080/photo/1

Page 15: Biol

aquaman

Page 16: Biol
Page 22: Biol

I have a problem…

Page 23: Biol

carlo, what do you do?

Page 24: Biol

1st try

I am a data visualization designer.

Page 25: Biol
Page 26: Biol

2nd try

I study data and I transform them

into some type of visual stuff.

Page 27: Biol
Page 28: Biol

3rd and last try Out there, there is a lot of data generated by

people and the environment. Sometime it is

very scary to be put face to face with this giant

amount of data. My job is to take all the

information, understand it and transform it into

some type of interactive tool that simplify the

understanding of the data. Usually I generate a

web application that can be used by people

who have no knowledge of the data...

Page 29: Biol
Page 30: Biol

the answer I like

generate order before people’s

brains try to do it in their own.

Page 31: Biol

but what is data visualization?

Page 32: Biol

a tool for your eyes and brain to

perceive what lies beyond their

natural reach.

Alberto Cairo – the functional art, 2012

Page 33: Biol

FORM vs BEAUTY

Page 34: Biol

FORM FOLLOWS FUNCTION

Louis Sullivan, 1896

Page 35: Biol

Feeling good about an artefact

makes us better at using it to

accomplish a goal.

Don Norman, Emotional Design 2003

Page 36: Biol

FORM vs BEAUTY vs FUN

Page 37: Biol

FORM + BEAUTY + FUN

Page 38: Biol

FUN?

Page 39: Biol

FUN

+

FUNCTIONALITY

Page 40: Biol

FUNTIONALITY

Page 41: Biol

FUNTIONALITY

Experimenting with novel forms

is not just an impulse,

it’s a necessity.

Alberto Cairo – the functional art, 2012

Page 42: Biol

The mind and eye demand

stimulation and surprise.

Donis Dondis, A Primer of Visual Literacy, 1973

Page 43: Biol

FUN? GREAT, BUT HOW?

Page 44: Biol
Page 45: Biol

http://bl.ocks.org/mbostock/3231298

Page 46: Biol

http://bl.ocks.org/mbostock/3014589

Page 47: Biol

http://bl.ocks.org/mbostock/1345853

Page 48: Biol

it’s not just D3.js

Page 49: Biol

peoplemov.in

Page 50: Biol

worldshap.in

Page 51: Biol

bolid.es

Page 52: Biol

VISUALIZING

SORTING ALGORITHMS

Page 53: Biol

SORTING ALGORITHM

a computational process used

to organize elements of

a sequence in a certain order

Page 54: Biol

0 1 2 3 4 5 6 7 8 9

0 3 7 1 4 5 2 6 8 9

Page 55: Biol

it all started when…

Page 56: Biol

https://flic.kr/p/569Stq

Page 57: Biol
Page 58: Biol
Page 59: Biol

HOW CAN WE SHOW

SORTING ALGORITHMS?

Page 60: Biol

sorting-algorithms.com

Page 61: Biol

sorting-algorithms.com

Page 62: Biol

sortvis.com

Page 63: Biol

sortvis.com - quicksort

Page 64: Biol

sortvis.com – bubblesort

Page 65: Biol

Algorithms – 4th edition

Page 66: Biol

Algorithms – 4th edition

Page 67: Biol

visualization + audibilization

Page 68: Biol

sorting objects

Page 69: Biol

EARLY PROTOTYPES

Page 70: Biol
Page 71: Biol
Page 72: Biol
Page 73: Biol
Page 74: Biol
Page 75: Biol
Page 76: Biol
Page 77: Biol
Page 78: Biol
Page 79: Biol
Page 80: Biol

Kunstformen der Natur (1904, Ernst Haeckel, Art forms of nature)

Page 81: Biol

Kunstformen der Natur (1904, Ernst Haeckel, Art forms of nature)

Page 82: Biol

Kunstformen der Natur (1904, Ernst Haeckel, Art forms of nature)

Page 83: Biol

Kunstformen der Natur (1904, Ernst Haeckel, Art forms of nature)

Page 84: Biol

Art from code

Page 85: Biol

learning computer science

Page 86: Biol

the beauty of computer science

Page 87: Biol

the beauty of computer science

+

art of coding OR the coding of art

Page 88: Biol

the beauty of computer science

+

art of coding OR the coding of art

+

learning sorting algorithms better

Page 89: Biol

the beauty of computer science

+

art of coding OR the coding of art

+

learning sorting algorithms better

+

exploration with data visualization

Page 90: Biol

www.sorting.at

Page 91: Biol

www.sorting.at

Page 92: Biol

bubble sort O(n^2)

if the list is already sorted O(n)

always compare elements next to each other

also known as the “sinking sort”, “it has only a catchy name” (Donald Knuth)

Page 93: Biol

comb sort O(n^2)

improves bubblesort by eliminating turtles and rabbits

gap between compared elements is bigger than 1 and shrinks at every iteration

Page 94: Biol

selection sort O(n^2)

search for the smallest element and put it in first position

inefficiently looks for element to be positioned at their right position in the list

only n swaps, therefore is useful where swapping is expensive

Page 95: Biol

insertion sort O(n^2)

makes space to the current item by moving larger items to the right

shifting all elements is expensive

Page 96: Biol

shell sort O(n log n) – O(n )

variant of insertion sort based on pre-defined gaps

works on shrinking gaps, complexity based on the gaps

2 3/2

Page 97: Biol

quick sort O(n log n)

divide and conquer algorithm

based on partioning and pivot selection

all elements smaller than the pivot are moved before it, greater after it

Page 98: Biol

heap sort O(n log n)

improved selection sort by selecting largest element and placing at the end

uses a heap (b-tree) to rearrange the list

finding the next largest element takes O(log n)

Page 99: Biol

inversions count

An inversion is a pair of positions in a sequence where the

elements there located are out of their natural order.

It indicates the distance of that sequence from being sorted.

A pair of elements (A[ i ] , A[ j ]) of a sequence A is called an

inversion if i<j and A[ i ]>A[ j ].

Page 100: Biol

inversions count

0 3 7 1 4 5 2 6 8 9

Page 101: Biol

inversions count

(3,1),(3,2),(7,1),(7,4),(7,5),(7,2),(7,6),(4,2),(5,2)

0 3 7 1 4 5 2 6 8 9

Page 102: Biol

inversions count

0 1 2 3 4 5 6 7 8 9

0 3 7 1 4 5 2 6 8 9

(3,1),(3,2),(7,1),(7,4),(7,5),(7,2),(7,6),(4,2),(5,2)

0 3 7 1 4 5 2 6 8 9

Page 103: Biol

www.sorting.at

Page 104: Biol

based on require.js and D3.js

Page 105: Biol

asynchronous code loading

{

“name” : “Bubble Sort”,

“complexity“ : “O(n )”,

“wiki” : “http://en.wikipedia.org/wiki/Bubble_sort”,

“code” : function() {

var steps=[];

function bubblesort(array) {

//sorting code

//save each step

}

return function(array) {

bubblesort(array);

return steps;

}

}

}

2

Page 106: Biol

3 D3 TIPS

Page 107: Biol

d3.timer

to repeat batch of operations with requestAnimation frame

prevent path rendering from locking up the UI

d3.timer(function(elapsed){

element

.selectAll("path")

.attr("d",function(d,i){

//evaluate path_coordinates

return path_coordinates;

})

//evaluate flag of end of loop

return flag;

})

Page 108: Biol

attrTween(t) + stroke-dashoffset

to animate the drawing

The attrTween operator is used when you need a custom

interpolator, such as one that understands the semantics of

SVG path data

.transition()

.duration(DURATION)

.attrTween("stroke-dashoffset",function(d,i){

var len = this.getTotalLength();

return function(t) {

return len*(1-t);

}

})

Page 109: Biol

attrTween(t) + path.getPointAtLength(len*t)

to animate along a path

.transition()

.duration(DURATION)

.attrTween("transform",function(d){

return function(t){

var len = path.getTotalLength();

var p = path.getPointAtLength(len*t);

return "translate("+p.x+","+p.y]+")";

}

})

Page 110: Biol
Page 111: Biol

and now

the best interpretation of

sorting algorithms EVER

Page 112: Biol

Quick-sort with Hungarian ("Csángó") folk dance

Page 113: Biol

carlo zapponi

@littleark

www.makinguse.com

GOTO Berlin

@GOTOber #gotober