×
Copy
Open
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Algorithms and Their Habitat
Slide 2
Slide 2 text
Vitalii Bobrov Lead JS Engineer @AngularWroclaw organizer ngGirls mentor @bobrov1989 https://bobrov.dev
Slide 3
Slide 3 text
Algorithms
Slide 4
Slide 4 text
unambiguous specification of how to solve a class of problems
Slide 5
Slide 5 text
Why should I care?!
Slide 6
Slide 6 text
They are EVERYWHERE
Slide 7
Slide 7 text
Maintain your library to find the way
Slide 8
Slide 8 text
Complexity
Slide 9
Slide 9 text
understand how application will scale
Slide 10
Slide 10 text
Big O
Slide 11
Slide 11 text
No content
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 text
TIME and SPACE Complexity estimate resources highlight bottlenecks force to find better solution
Slide 14
Slide 14 text
Data Normalization
Slide 15
Slide 15 text
WHEN? related state entities recursive state entities fast entity lookup
Slide 16
Slide 16 text
Data with Relations
Slide 17
Slide 17 text
Recursive Data
Slide 18
Slide 18 text
WHY? get entity by id get entities by related id reduce memory footprint
Slide 19
Slide 19 text
Data with relations - get entity O(n) O(n*m)
Slide 20
Slide 20 text
Recursive data - get entity memory O(n) time O(n)
Slide 21
Slide 21 text
No content
Slide 22
Slide 22 text
Normalized data
Slide 23
Slide 23 text
Normalized data - get entity O(1) O(1) O(n*m)
Slide 24
Slide 24 text
prepare index to get entities faster
Slide 25
Slide 25 text
Normalized data - index
Slide 26
Slide 26 text
Normalized data - get entity O(n)
Slide 27
Slide 27 text
HOW? do it yourself use library normalizr @ngrx/entity https://github.com/paularmstrong/normalizr https://ngrx.io/guide/entity
Slide 28
Slide 28 text
Memoization
Slide 29
Slide 29 text
WHEN? data selection repeated computations derived data
Slide 30
Slide 30 text
Fibonacci numbers
Slide 31
Slide 31 text
Call tree
Slide 32
Slide 32 text
WHY? reduce expensive calls frequently used data reduce callstack
Slide 33
Slide 33 text
Memoized
Slide 34
Slide 34 text
HOW? do it yourself use library reselect mem https://github.com/reduxjs/reselect https://github.com/sindresorhus/mem
Slide 35
Slide 35 text
Levenshtein Distance
Slide 36
Slide 36 text
calculates how many edits required to get one string from another
Slide 37
Slide 37 text
Distance matrix
Slide 38
Slide 38 text
No content
Slide 39
Slide 39 text
WHEN? auto-correction auto-completion smart suggestions
Slide 40
Slide 40 text
No content
Slide 41
Slide 41 text
No content
Slide 42
Slide 42 text
use Levenshtein distance for smart 404 page
Slide 43
Slide 43 text
HOW? https://bobrov.dev/blog/angular-smart-404-page/ https://bobrov.dev/ngx-smart-routing-demo/ get the list of available routes sort routes by Levenshtein distance to a user input suggest route with the smallest distance
Slide 44
Slide 44 text
Get all available routes
Slide 45
Slide 45 text
Sort by Levenshtein distance
Slide 46
Slide 46 text
Suggest route
Slide 47
Slide 47 text
No content
Slide 48
Slide 48 text
Create non-standard use-case
Slide 49
Slide 49 text
@bobrov1989 https://bobrov.dev