Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Algorithms. Basic course
Algorithms.
Basic course
Informal definition: a set of rules that precisely defines a
sequence of operations to accomplish a certain goal.
We create, follow and control the execution of
algorithms in our everyday life.
Everyday algorithms
Main properties of an algorithm:
Flexibility - an algorithm should be adaptable to solve a wide scope of problems.
Discreteness - the process should be divided into separate, well-described steps. One step at a
time.
Determinacy - the order of the steps of the algorithm and all actions inside each step must be
unambiguous.
Productivity - at the end of its execution, the algorithm must produce some result.
Stability - if an algorithm has correct input parameters, it must always produce the correct results.
Algorithm types
Randomized (stochastic) algorithm such algorithms make some choices randomly (or pseudo-randomly). This can be very useful in
finding approximate solutions to problems when finding exact solutions can be impractical (Monte Carlo, Las Vegas algorithms).
Heuristic algorithm can be used to find a solution close to the optimal solution in cases when finding the optimal solution is
impractical. These algorithms work by getting closer and closer to the optimal solution as they progress. In principle, if run for an infinite
period of time, they will find the optimal solution. Their advantage is that they can find a solution very close to the optimal solution in a
relatively short time.
Linear algorithm is a set of steps executed strictly one after another.
Branching algorithm uses at least one ‘if’-condition to make a decision in which of the two (or more) possible path programs its
execution should be continued.
Iterative algorithms use repetitive constructs like loops and sometimes additional data structures like stacks to solve the given
problems.
Recursive algorithm is one that invokes (makes reference to) itself repeatedly until a certain condition (also known as termination
condition) is met, which is a method common to functional programming.
Ways to describe an algorithm:
Verbal - an algorithm is verbally described in a human language;
Symbolic - an algorithm is written down using any algorithmic language;
Graphics - an algorithm is written down using block schemes.
Method to measure algorithm
To measure an algorithm, there is usually big O notation used.
In computer science, big O notation is used to classify algorithms according to
how their running time or memory space requirements grow as the input size
grows.
Advantages of Big O Notation
● Independent of computer architecture;
● Mostly independent of the interpreter or compiler;
● Easily understandable information.
Limitations of Big O Notation
There are numerous algorithms that are too difficult to analyze mathematically.
There may not be sufficient information to calculate the behaviour of the algorithm
in an average case.
The Big O notation sometimes ignores the important constants. For instance, if a
particular algorithm takes O(n3) time to run and another algorithm takes O(100n3)
time to run, then both algorithms would have equal time complexity according to
the Big O notation.
The Big O notation tells us how the algorithm grows with the size of the problem
and not the efficiency related to it.
Additional resources:
Books:
● Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson,
Ronald L. Rivest, and Clifford Stein
● Algorithm Design by Jon Kleinberg
Web resources:
● Algorithms. Course by Kevin Wayne

More Related Content

Algorithms. Basic course

  • 3. Informal definition: a set of rules that precisely defines a sequence of operations to accomplish a certain goal. We create, follow and control the execution of algorithms in our everyday life.
  • 5. Main properties of an algorithm: Flexibility - an algorithm should be adaptable to solve a wide scope of problems. Discreteness - the process should be divided into separate, well-described steps. One step at a time. Determinacy - the order of the steps of the algorithm and all actions inside each step must be unambiguous. Productivity - at the end of its execution, the algorithm must produce some result. Stability - if an algorithm has correct input parameters, it must always produce the correct results.
  • 6. Algorithm types Randomized (stochastic) algorithm such algorithms make some choices randomly (or pseudo-randomly). This can be very useful in finding approximate solutions to problems when finding exact solutions can be impractical (Monte Carlo, Las Vegas algorithms). Heuristic algorithm can be used to find a solution close to the optimal solution in cases when finding the optimal solution is impractical. These algorithms work by getting closer and closer to the optimal solution as they progress. In principle, if run for an infinite period of time, they will find the optimal solution. Their advantage is that they can find a solution very close to the optimal solution in a relatively short time. Linear algorithm is a set of steps executed strictly one after another. Branching algorithm uses at least one ‘if’-condition to make a decision in which of the two (or more) possible path programs its execution should be continued. Iterative algorithms use repetitive constructs like loops and sometimes additional data structures like stacks to solve the given problems. Recursive algorithm is one that invokes (makes reference to) itself repeatedly until a certain condition (also known as termination condition) is met, which is a method common to functional programming.
  • 7. Ways to describe an algorithm: Verbal - an algorithm is verbally described in a human language; Symbolic - an algorithm is written down using any algorithmic language; Graphics - an algorithm is written down using block schemes.
  • 8. Method to measure algorithm To measure an algorithm, there is usually big O notation used. In computer science, big O notation is used to classify algorithms according to how their running time or memory space requirements grow as the input size grows.
  • 9. Advantages of Big O Notation ● Independent of computer architecture; ● Mostly independent of the interpreter or compiler; ● Easily understandable information.
  • 10. Limitations of Big O Notation There are numerous algorithms that are too difficult to analyze mathematically. There may not be sufficient information to calculate the behaviour of the algorithm in an average case. The Big O notation sometimes ignores the important constants. For instance, if a particular algorithm takes O(n3) time to run and another algorithm takes O(100n3) time to run, then both algorithms would have equal time complexity according to the Big O notation. The Big O notation tells us how the algorithm grows with the size of the problem and not the efficiency related to it.
  • 11. Additional resources: Books: ● Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein ● Algorithm Design by Jon Kleinberg Web resources: ● Algorithms. Course by Kevin Wayne