Download presentation

Presentation is loading. Please wait.

1
**Theory of Computer Science - Algorithms**

2
**Theory of Computer Science - Algorithms**

Algorithm is a sequence of elementary operations that give solution to any problem from a specific class of problems in a finite number of steps. elementary operations - one command precisely defined all elementary operations should be precisely defined: x<y precise definition x<<y without additional comment it is not precise definition any problem from a specific class of problems - not a specific, one problem but specific class of problems finite numbers of steps - algorithm must end and give a result

3
**Theory of Computer Science - Algorithms**

Features of a good algorithms finiteness - executed algorithm must have the end specificness - all operations and their order should be precisely defined efficiency - algorithm must give a result in a shortest way generality - algorithm must give solution to any problem from a specific class of problems correctness - must give a correct solution

4
**Theory of Computer Science - Algorithms**

Basic way in creating algorithms: problem definition problem analysis preparation of rules create concise procedure for solving problem

5
**Theory of Computer Science - Algorithms**

Ways of describing algorithms: Recursive - mathematical function Natural language Flow chart – block diagram Formal languages

6
**Theory of Computer Science - Algorithms**

Recursive function - example: factorial n Problem is defined by itself: n! = n * (n-1)! if n = 1 then n!=1 and 0!=1 4!=4 * (4-1)! = 4 * 3! 3!= 3 * 2! 2!= 2 * 1!= 2 * 1

7
**Theory of Computer Science - Algorithms**

Ways of describing algorithms: Recursive - mathematical function n! = n * (n-1)! advantage: high precision disadvantage: can describe only few kinds of problems

8
**Theory of Computer Science - Algorithms**

Natural language - example Give an algorithm of finding the value: y = Max{ xi }, where 1 ≤ i ≤ n 1. i ← 1, go to 2 2. y ← xi, go to 3 3. whether i = n ? If yes – the end, if no – go to 4 4. i ← i + 1, go to 5 5. whether xi > y ? If yes – go to 2, if no– go to 3

9
**Theory of Computer Science - Algorithms**

Natural language – example: y = Max{ xi }, where 1 ≤ i ≤ n sequence x: quantity of x elements: n = 4 index of processing element: i=? present maximum: y=? 1. i ← 1, go to 2 2. y ← xi, go to 3 3. whether i = n ? If yes – the end, if no – go to 4 4. i ← i + 1, go to 5 5. whether xi > y ? If yes – go to 2, if no– go to 3

10
**Theory of Computer Science - Algorithms**

Ways of describing algorithms: Natural language advantage: easy to understand, simplicity, no need to use special conventions, wide vocabulary disadvantage: lack of precision, possibility of misunderstanding

11
**Theory of Computer Science - Algorithms**

Flow chart -block diagram computational transaction, process decision - testing condition begining and the end of algorithm input/output operations connecting element, direction

12
**Theory of Computer Science - Algorithms**

Flow chart– example: y = Max{ xi }, where 1 ≤ i ≤ n

13
**Theory of Computer Science - Algorithms**

Ways of describing algorithms: Flow chart formal way of describing algorithm advantage: precise, can be used at every level of software development, flexible disadvantage: technical difficulty of representing large algorithms

14
**Theory of Computer Science - Algorithms**

Formal languages – example: y = Max{ xi }, where 1 ≤ i ≤ n The same algorithm presenting with Pascal function Max( x : array of integer ) : integer; var i, y : integer; begin y := x[ 1 ]; for i := 2 to n do if x[ i ] > y then y := x[ i ]; Max := y; end;

15
**Theory of Computer Science - Algorithms**

Formal languages – example: y = Max{ xi }, where 1 ≤ i ≤ n The same algorithm presenting with C int Max( int *x ) { int i; int y = x[0]; for( i = 1; i < n; i++ ) if( x[i] > y ) y = x[i]; return y; }

16
**Theory of Computer Science - Algorithms**

Ways of describing algorithms: Formal languages – programming languages advantage: precision, executive disadvantage: you have to know the language – difficulty of learning the language

17
**Theory of Computer Science - Algorithms**

Sequence algorithm The previous algorithm was a sequence algorithm. instructions are executed one after one n + 1 – amount of algorithm’s operations Oi – operation number i t( x ) – moment of time when is executed operation x This is always true that: moment of time, when is the end of previous operation, is in the some time or earlier, then the beginning of next operation.

18
**Theory of Computer Science - Algorithms**

Parallel algorithm At least 2 operations can be executed in the some time n + 1 – amount of algorithm’s operations Oi – operation number i t( x ) – moment of time when is executed operation x There is moment of time, when the end of previous operation, is later, then the beginning of next operation.

19
**Theory of Computer Science - Algorithms**

Way of comparing algorithms: Time complexity How much time is required to execute algorithm (usually we don’t measure time but steps) Space/memory complexity How much memory space is required, to execute the algorithm

20
**Theory of Computer Science - Algorithms**

Conclusions In most cases the increase in space complexity, causes the decrease in time complexity and vice versa. Processed data, have implication on execution time and needed memory. Pessimistic and average efficiency, have implication on algorithm’s application. In parallel algorithms, amount of processors, have implication on time execution. The more processors, the shorter time. But there is limited amount of processors, for each algorithm, where if we use more processors above this limit, it doesn’t increase the time.

Similar presentations

Presentation is loading. Please wait....

OK

College of Information Technology & Design

College of Information Technology & Design

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on automobile related topics to economics Upload and view ppt online student Download ppt on bermuda triangle Run ppt on mac Ppt on type 1 diabetes mellitus Ppt on surface area and volume for class 9 free download Ppt on group development model Ppt on yoga and aerobics classes Convert pdf to ppt online free without email Ppt on market friendly state for retirement