2. Why do you need algorithms?
Good algorithmic training is VERY important for the programmer, but
you don’t need to memorize all the algorithms
Understanding algorithms gives you:
1) Ability to solve incomprehensible problems
2) Habit to analyze the effectiveness of each of your solutions
3) Ability to skillfully use the existing tools
One more reason: jobs
3. Outline
• Definition of algorithm
• Formal properties of algorithms
• Some classification of algorithms
• Complexity of algorithms
• ALGORITHMS
4. Disclaimer
Some of the terms and words Google-translated.
Sorry.
Source code is availigle on GitHub
5. 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.
6. Formal properties of algorithms
1) Finiteness
2) Discreteness
3) Clarity
4) Accuracy
5) Mass character
6) Definitiveness
15. Classification
Couple of categories of algorithms (there are a plenty of them)
•Deterministic / Randomized
•Exact / Approximation
•Sequential / Parallel
•etc.
16. Complexity of algorithms
1) 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.
17.
18. Algorithms: Strings/arrays
Algorithm #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.)
19. Algorithms: Strings/arrays
Algorithm #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
20. Algorithms: Strings/arrays
Algorithm #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.
22. Algorithms: Linked List
Linked 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.
23. Algorithms: Binary Tree
Binary 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.
24. 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
25. Today:
• Learn some theory (definition properties, complexity)
• Overview several algorithms
First, is the ability to solve the problem of incomprehensible.
The vague wording of vital problems to see the possible strict interpretation.
Comprehensively analyze the various options and choose the most suitable.
Obviously, it is not enough just to know the algorithms.
You must be able to "see them", to recognize the possibilities of their application.
Secondly, algorithmic training should get you the habit of analyzing the effectiveness of each of your solutions.
Third, algorithmic training should help skillfully use the existing tools. Databases are continuous data structures and algorithms. And conceptually quite simple and clear - search trees, hash table
For example, knowing that the database index - it's just a search tree, it is easy to understand which requests can be met quickly and which ones are doomed to full-scan.
1) SIMPLE: the algorithm must eventually terminate. Something endless is not an algorithm
Example: Do that – then that – then that. Not like do that or that – then that – but before you should do that
Example: if you need to perform a mathematical algorithm you will probably use calculator or something like that, you can only do mathematical operations with that (like division, multiplication, addition, substraction, power etc). Calculator cannot do barrel roll to do that math algorithm
I’ll try to give examples of that properties later
1) Finiteness – we need 5 steps to get result
2) Discreteness – each step is discrete
3) Clarity – we have comands like lay orange and cut
4) Accuracy - cut the orange in half vertically (NOT HORISONTALLY) but also that tutorial is specially designed for oranges.
5) Mass character – using that tutorial we can cut not only that but anyof the oranges in the world
6) Definiteness – if we follow these steps we will always have 6 pieces of orange in the end
I won’t spend a lot of time on classification.
Here I’d like to stress that in general algorithms never contain random processes. Here randomized means that in such of algorithms are used another algorithm for generating a sequence of numbers whose properties approximate the properties of sequences of random numbers.
2 – clear
3 – example of making a soup. We can put water to boil and peel and cut potatoes during that.
Обозначение логарифма:
log 𝑏 𝑁 = x
Эта запись равнозначна следующей: bx = N .
I want to show you some algorithms, explain them code programming
Strings/arrays are easy to understand, but the interview problems often require advanced algorithm to solve, such as dynamic programming, recursion, etc.
But it’s still important to know when one sorting algorithm is better than another