Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Algorithms and Their Habitat

Algorithms and Their Habitat

Algorithms are mysterious beasts that hard to catch in the source code. However, well-chosen data structures and efficient algorithms applied to a web app is a key to performance. I want to show how to fit the knowledge you got at the university can solve your daily routines.

Vitalii Bobrov

September 27, 2019

More Decks by Vitalii Bobrov

Other Decks in Programming


  1. Algorithms and Their Habitat

  2. Vitalii Bobrov Lead JS Engineer @ EPAM @AngularWroclaw organizer experimenter

    @bobrov1989 https://bobrov.dev
  3. Algorithms

  4. unambiguous specification of how to solve a class of problems

  5. Why should I care?!

  6. They are EVERYWHERE

  7. Complexity

  8. understand how application will scale

  9. Big O

  10. None
  11. None
  12. TIME and SPACE Complexity estimate resources highlight bottlenecks force to

    find better solution
  13. Data Normalization

  14. WHEN? related state entities recursive state entities fast entity lookup

  15. Data with Relations

  16. Recursive Data

  17. WHY? get entity by id get entities by related id

    reduce memory footprint
  18. Data with relations - get entity O(n) O(n*m)

  19. Recursive data - get entity memory O(n) time O(n)

  20. None
  21. Normalized data

  22. Normalized data - get entity O(1) O(1) O(n*m)

  23. prepare index to get entities faster

  24. Normalized data - index

  25. Normalized data - get entity O(n)

  26. HOW? do it yourself use library normalizr @ngrx/entity https://github.com/paularmstrong/normalizr https://ngrx.io/guide/entity

  27. Memoization

  28. WHEN? data selection repeated computations derived data

  29. Fibonacci numbers

  30. Call tree

  31. WHY? reduce expensive calls frequently used data reduce callstack

  32. Memoized

  33. HOW? do it yourself use library reselect mem https://github.com/reduxjs/reselect https://github.com/sindresorhus/mem

  34. Levenshtein Distance

  35. calculates how many edits required to get one string from

  36. Distance matrix

  37. None
  38. WHEN? auto-correction auto-completion smart suggestions

  39. None
  40. None
  41. use Levenshtein distance for smart 404 page

  42. “Helpful” UI

  43. https://ngx-smart-routing-demo.web.app

  44. HOW? https://bobrov.dev/blog/angular-smart-404-page/ https://ngx-smart-routing-demo.web.app get the list of available routes sort

    routes by Levenshtein
 distance to a user input suggest route with the smallest distance
  45. Get all available routes

  46. Sort by Levenshtein distance

  47. Suggest route

  48. Create non-standard use-case

  49. @bobrov1989 https://bobrov.dev