+ All Categories
Home > Technology > #1 designandanalysis of algo

#1 designandanalysis of algo

Date post: 24-May-2015
Category:
Upload: brijida-charizma-ardona-navarro
View: 1,787 times
Download: 0 times
Share this document with a friend
Description:
CS202 Design and Analysis of Algorithm
Popular Tags:
22
Design And Analysis of Algorithms Topic #1: Algorithm Basics Prepared by: Brijida Charizma A. Navarro
Transcript
Page 1: #1 designandanalysis of algo

Design And Analysis of Algorithms

Topic #1: Algorithm Basics

Prepared by: Brijida Charizma A. Navarro

Page 2: #1 designandanalysis of algo

Introduction

As future computer

scientists, you will usually

more concerned with writing

complex program

algorithm.

Page 3: #1 designandanalysis of algo

AlgorithmsStep by step method of solving

some problemsSolution that can be executed by

a computerDerived from the name of the

nith-century Persian mathematician al-Khowarizmi.

Page 4: #1 designandanalysis of algo

AlgorithmA complete, step-by-step

procedure for solving a specific problem.

Page 5: #1 designandanalysis of algo

Pakiisip nga…..

Does the computer

understand an algorithm?

Page 6: #1 designandanalysis of algo

Properties of Algorithms

InputOutputPrecision

Page 7: #1 designandanalysis of algo

Properties of Algorithms

DeterminismFiniteness CorrectnessGenerality

Page 8: #1 designandanalysis of algo

Example

Make an algorithm that finds the maximum of

three numbers a, b and c.

Page 9: #1 designandanalysis of algo

Algorithm: Finding the maximum in a list of 3 numbers

1.x = a2. If b > x then x = b3. If c > x, then x=c.

a = 1, b = 5,c = 3

Page 10: #1 designandanalysis of algo

Two Main Tasks in the Study of Algorithms

Algorithm DesignAnalysis of Algorithms

Page 11: #1 designandanalysis of algo

Algorithm DesignTo solve problemsAn art more than a science

Page 12: #1 designandanalysis of algo

Analysis of AlgorithmsWill provide insights into

designing new algorithms

Page 13: #1 designandanalysis of algo

in analysis of algorithms, we ask ourselves the following questions:

1. Correctness. Given an algorithm for a problem, does it solve the problem?

2. Termination. Does the algorithm always stop after a finite number of steps?

3. Time Analysis. How many instructions does the algorithm execute?

4. Space Analysis. How much memory does the algorithm need to execute?

Page 14: #1 designandanalysis of algo

Exercise

1.Write an algorithm that finds the smallest element among a, b and c

Page 15: #1 designandanalysis of algo

Solution

1. x = a2. If b < x, then x = b.3. If c < x, then x = c.

Page 16: #1 designandanalysis of algo

2. ExerciseWhich properties of an algorithm

– input, output, precision, determinism, finiteness, correctness, generality – if any, are lacking in the following. Explain. The input is a set of S of integers and an integer m. The output is all subsets of S that sum to m.

Page 17: #1 designandanalysis of algo

Here’s the algorithm:

1.List all subsets of S and their sums.

2.Proceed through the subsets listed in step 1 and output each whose sum is m.

Page 18: #1 designandanalysis of algo

Answer:If the set S is an infinite set, the algorithm will

not terminate, so it lacks finiteness and output properties.

Line 1 is not precisely stated since how to list the subsets of S and their sums is not specified; thus the algorithm lacks the precision property.

The order of the subsets listed in line 1 depends on the method used to generate them, so the algorithm lacks the determinism property.

Since line 2 depends on the order of the subsets generated in line 1, the determinism property is lacking here as well.

Page 19: #1 designandanalysis of algo

Pseudocode for AlgorithmsMade of ordinary languagePrecision, structure and

universalityClosely resembles the actual

code of computer languages such as C++ and Java

Any version of pseudocode is acceptable as long as the instructions are unambiguous.

Page 20: #1 designandanalysis of algo

Algorithm Structure

Input Parameters: a, b, cOutput Parameter: x

max(a,b,c){ x = a if (b > x) // b is larger than x, update x x = b if (c > x) // c is larger than x, update x x = c}

Algorithm: Finding the Maximum of Three Numbers. This algorithm finds the largest of the numbers a, b, and c

Page 21: #1 designandanalysis of algo

TitleBrief description of the algorithmThe input and output parametersFunction containing the

instructions of the algorithm

Page 22: #1 designandanalysis of algo

Do this…………

Design an algorithm that will find the largest number in an array s

s[1],s[2],…,s[n]Note: an array is a group of data of the same type

Use while


Recommended