Download presentation
Presentation is loading. Please wait.
1
Creating and implementing algorithms
Vladimir Viies, Lembit Jürimägi, Margit Aarna Tallinn 2015
4
ALGORITHM CREATING 1 What is an algorithm? Why use it? How to use it?
5
but not just any instruction, instructions with certain properties.
WHAT IS AN ALGORITHM WHEN SOLVING TASKS WITH COMPUTERS? Instructions for solving the task. but not just any instruction, instructions with certain properties.
6
Examples: 1. Task: Find the largest number from {N} numbers
Instructions that aren’t an algorithm: Compare the numbers and choose the largest number Instructions that can be an algorithm : 1. Read the numbers (remember, write down etc.) – enter numbers. 2. Take the first number and mark it. 3. Compare marked number with next number(s) until a larger number is found or it has been compared with every number. 4. If during the comparison a larger number is found then mark it and repeat step 3.
7
Examples 2. Task: win 1 million in a lottery game
Instructions that aren’t an algorithm: buy a ticket until you win. Instructions that can be an algorithm: there is none. 3. Task : exchange 100 euro bank note into smaller bank notes Instructions that can be an algorithm: We have to specify more details. We need to explain, what “into smaller” means, which banknotes and how many we can use. If the task is vague then we need to put restrictions into place ourselves and consider these restrictions when creating an algorithm.
8
THE ALGORITHM PROPERTIES
ALGORITHM CREATING 2 THE ALGORITHM PROPERTIES Must specify inputs and outputs which are interrelated It should provide a solution in finite time Must be unequivocal ......
9
Algorithm graphical presentation tools 1 (flowchart)
ALGORITHM CREATING 3 ALGORITHM VISUALISATION Algorithm graphical presentation tools 1 (flowchart)
11
SFC elements of the schemes(1)
Algorithm with such a layout always has one start and one end All activities will take place in sequence! Each kind of activity has its own notation. This diagram shows the I / O, conditional and operation activities.
13
Algorithm realization, the language choice
Mis on algoritm?
14
// Program: erinevad arvud
// Author: viies // Course: iag0581 void main () { mitu arvu sisestan; loen mitu arvu - N; paaris ja paaritu=0; for (i = 1; i <= N; i = i + 1) loen arvu a(i); if (kas a(i) on paarisarv(jagub 2-ga)) paaris=paaris+1; } else paaritu=paaritu+1; väljasta paaris, paaritu; Editor SFC generated immediately the code in C language based on the description of the algorithm SFC runs!
15
Algorithm graphical presentation tools 2
ALGORITHM CREATING 4 Algorithm graphical presentation tools 2 (Jackson editor)
16
An algorithm moves from top down and from left to right
17
Structural approach is well suited to Jackson editor
DATA INPUT DATA PROCESSING RESULTS OUTPUT Structural approach is well suited to Jackson editor
18
Algorithm graphical presentation tools 4
ALGORITHM CREATING 5 Algorithm graphical presentation tools 4 (Using the UML activity diagram)
20
Finding extremes, and "bubblesort" method
ALGORITHM CREATING 6 Finding extremes, and "bubblesort" method
21
Extremes and sorting One frequent task when processing data is sorting and finding the maximum and minimum values. Such tasks always include two activities: “Exchanging places” of two values Comparing the two values The first includes one activity, but the second three activities.
22
Analogously can be found MINIMUM
A simple sorting algorithm, can also be used successfully to find extremes < MAXIMUM Analogously can be found MINIMUM
23
ALGORITHM CREATING 7 Shell sort algorithm
24
Shell sort algorithm (1)
(has less exchanges, presumes that data is partially sorted)
25
ALGORITHM CREATING 1.Insertion sort 2.Selection sort 3.Mergesort
28
We separate the task into sub-tasks and solve them later!
Output matrix row, on the basis of max element Matrix input A(i,j) i,j=1..N Max A(i,J) finding, max(i) Row separation on the base of max(i) We separate the task into sub-tasks and solve them later!
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.