• Nie Znaleziono Wyników

Algorithms

N/A
N/A
Protected

Academic year: 2021

Share "Algorithms"

Copied!
2
0
0

Pełen tekst

(1)

Class 3 Introduction to computer science

Introduction to algorithms, flowcharts, pseudocode of an algorithms.

Recursive algorithm - one that invokes (makes reference to) itself re- peatedly until a certain condition matches, which is a method common to functional programming.

Iterative algorithms use repetitive constructs like loops and sometimes additional data structures like stacks to solve the given problems.

Usefull links:

— Flowcharts and pseudocodes http://www.allclearonline.com/applications/

DocumentLibraryManager/upload/program_intro.pdf

— Flowchart symbols http://www.wiley.com/college/busin/icmis/oakman/

outline/chap05/slides/symbols.htm

If You know some programming language (C,C++,Java,Pascal) You can use its syntax instead of described pseudocode syntax. Everything that wo- uld be understandable for me will be counts as a correct pseudocode.

Examples of some flowcharts:

— Algorithm which compute n! http://www.rff.com/n_factorial_flowchart.

htm.

— Euclid algorithm http://motivate.maths.org/conferences/conf124/

c124_Euclid.shtml

I reccomend to You program „RAPTOR” where You can create flow chart and execute it to can be sure that it is correct:

— Raptor’s webpage http://raptor.martincarlisle.com/

Tasks for classes

Task 1

Draw a flowchart of an algorithms which checks whether You win in a lotto lottery. You have a lotto ticket with 6 numbers sorted ascending, and You have to compare them with a 6 numbers draw by a lotto maschine (there are also given in ascending order). We are only interested whether we hit all six numbers or not.

I prepare a file with reading data in this problem, so You can use it http://www.staff.amu.edu.pl/~mw/DNIF/lotto.rap.

Task 2 Binary search is an algorithm for locating the position of an element in a sorted list by checking the middle, eliminating half of the list from consideration, and then performing the search on the remaining half.

Write in pseudocode iterative and recursive version of this algorithm.

If You’re not familiar with this algorithm you can read http://www.

articledashboard.com/Article/The-Binary-Search-Algorithm/1047768.

Task 3

1

(2)

Class 3 Introduction to computer science

Draw in RAPTOR a flowchart of an Insertion sort algorithm. You can re- ad about this algorithm here http://en.wikipedia.org/wiki/Insertion_

sort.

Task 4

Draw in RAPTOR a flowchart of an Bubble sort algorithm. You can read about this algorithm here http://en.wikipedia.org/wiki/Bubble_sort.

Task 5

Write a pseudocode of an iterative and recursive version of an algorithm that computes n-th elementh of a sequence defined by:

Fn:=

0 dla n = 0;

1 dla n = 1;

2 dla n = 2;

Fn−1+ Fn−2+ Fn−3 for n > 2.

(so the beginning of a sequence is as follows 0,1,2,3,6,11,20,...). Please im- plement in RAPTOR the iterative version, check what is the 25-th elementh of this sequence.

Additional information

There would be some taks in the final test to draw a flowchart and write pseudocode of a given algorithm (on paper). So there is no homework from this class.

2

Cytaty

Powiązane dokumenty

Conditions for a bounded set-valued measure AT to be a strict set­.. valued

The number of partitions of n into distinct non-consecutive odd parts excluding 3 with ones in the gaps is equal to the number of parti- tions of n + 1 into an odd number of

But Baker and Harman [2] intro- duced the alternative sieve procedure, developed by Harman [10] and by Baker, Harman and Rivat [3], to get a better exponent.. In this paper we

Now, for a real number r ­ 2 primitive unitary totient r-abundent and primitive unitary totient r-deficient numbers have been defined as-.. A positive integer n is called

We shall consider a regular case: the one-sided tangents to Γ at P 0 are not parallel to coordinate axes... A general form of such domains was described

You follow, respect and use 4 eyes principle to ensure quality of processes data and documents, and you ensure information validity of employee population data

You have in your hands a special issue of Foton (Photon), the journal for Polish physics teachers and their students, edited at the Marian Smoluchowski Institute of Physics of

Then we deal with a positive answer, in particular KL(ℵ n , 2), and we show that the negation of a relative of the free subset property for λ implies KL(λ, 2).. We thank