cubeit tech - algorithms
TRANSCRIPT
![Page 1: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/1.jpg)
Introduction to Algorithms
![Page 2: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/2.jpg)
Why do you need algorithms?Good algorithmic training is VERY important for the programmer, but you don’t need to memorize all the algorithmsUnderstanding algorithms gives you:1) Ability to solve incomprehensible problems2) Habit to analyze the effectiveness of each of your solutions3) Ability to skillfully use the existing tools
One more reason: jobs
![Page 3: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/3.jpg)
Outline•Definition of algorithm• Formal properties of algorithms• Some classification of algorithms•Complexity of algorithms•ALGORITHMS
![Page 4: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/4.jpg)
Disclaimer
Some of the terms and words Google-translated.Sorry.
Source code is availigle on GitHub
![Page 5: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/5.jpg)
Definition of algorithm
Simple: Algorithm is a set of rules for solving a problem in a finite number of steps
Less simple:Algorithm is a finite set of unambiguous instructions that, given some set of initial conditions, can be performed in a prescribed sequence to achieve a certain goal and that has a recognizable set of end conditions.
![Page 6: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/6.jpg)
Formal properties of algorithms1) Finiteness2) Discreteness3) Clarity4) Accuracy5) Mass character6) Definitiveness
![Page 7: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/7.jpg)
FinitenessFiniteness (or effectiviness)
means that algorithm has a finite number of steps to received result.
![Page 8: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/8.jpg)
DiscretenessDiscreteness
means that algorithm has to be broken down into a sequence of steps performed
![Page 9: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/9.jpg)
ClarityClarity
means that algorithm must contain only the commands that are part of a set of commands that can perform a particular executor
![Page 10: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/10.jpg)
AccuracyAccuracy
means that any step of an algorithm should be definite and unambiguous
![Page 11: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/11.jpg)
Mass characterMass character
means that once algorithm is made up it must solve similar problems with different input data
![Page 12: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/12.jpg)
DefinitivenessDefinitiveness
means that the same set of input data will produce the same result, i.e. the result is uniquely determined by the initial data.
![Page 13: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/13.jpg)
Test yourselfI want to cut an orange. What’s the plan?
![Page 15: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/15.jpg)
ClassificationCouple of categories of algorithms (there are a plenty of them)
•Deterministic / Randomized• Exact / Approximation• Sequential / Parallel• etc.
![Page 16: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/16.jpg)
Complexity of algorithms1) Confusing explanation 2) Clear explanation (must read)
The idea is Big-O notation
Big-O notation is a relative representation of the complexity of an algorithm.
![Page 17: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/17.jpg)
![Page 18: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/18.jpg)
Algorithms: Strings/arraysAlgorithm #1: Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. (Note: The order of elements can be changed. It doesn't matter
what you leave beyond the new length.)
![Page 19: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/19.jpg)
Algorithms: Strings/arraysAlgorithm #2: Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array.
[1,3,5,6], 5 -> 2 [1,3,5,6], 2 -> 1 [1,3,5,6], 7 -> 4[1,3,5,6], 0 -> 0
![Page 20: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/20.jpg)
Algorithms: Strings/arraysAlgorithm #3: Anagrams
Given an array of strings, return all groups of strings that are anagrams.
An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; for example Torchwood can be rearranged into Doctor Who.If two strings are anagram to each other, their sorted sequence is the same. Therefore, this problem can be seen as a problem of
finding duplicate elements.
![Page 21: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/21.jpg)
Algorithms: MatrixAlgorithm: Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).
![Page 22: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/22.jpg)
Algorithms: Linked ListLinked list is a linear collection of data elements, called nodes pointing to the next node by means of pointer
Algorithm: Reverse Linked List
Reverse a singly linked list.
![Page 23: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/23.jpg)
Algorithms: Binary TreeBinary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child
Algorithm: Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree.
![Page 24: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/24.jpg)
Algorithms: SortingСhances that you will need to write a sorting algorithm are close to zero.
http://www.sorting-algorithms.com/https://www.youtube.com/watch?v=kPRA0W1kECg
![Page 25: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/25.jpg)
Today:• Learn some theory (definition properties, complexity)•Overview several algorithms
![Page 26: CubeIT Tech - Algorithms](https://reader036.vdocuments.pub/reader036/viewer/2022081604/589ed81a1a28ab39498b5373/html5/thumbnails/26.jpg)
Extra resources1) http://www.programcreek.com/2012/11/top-10-algorithms-for-cod
ing-interview/