Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال) Chapter 1 Introduction to Algorithms.

Similar presentations


Presentation on theme: "1 Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال) Chapter 1 Introduction to Algorithms."— Presentation transcript:

1 1 Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال) Chapter 1 Introduction to Algorithms

2 2 Computational problems A computational problem specifies an input-output relationship  What does the input look like?  What should the output be for each input? Example 1:  Input: an integer number n  Output: Is the number odd ( هل الرقم فردي أو لا )? true Example 2:  Input: array of numbers  Output: the minimum number in the array Example 3:  Input: array of numbers  Output: the same array sorted (ascending تصاعديا ) 18372420 3 18372420 72201843 5

3 3 Algorithms Algorithm is: 1. A tool for solving a well-specified computational problem 2. A sequence of instructions describing how to do a task or process Algorithms must be:  Correct: For each input produce an appropriate output  Efficient: run as quickly as possible, and use as little memory as possible AlgorithmInput Output

4 4 The Problem-solving Process Problem specification Algorithm Program Executable (solution) Analysis Design Implementation Compilation

5 5 From Algorithms to Programs Problem C Program Algorithm Algorithm: A sequence of instructions describing how to do a task (or process)

6 6 Simple Algorithms Example1 (Min Algorithm) INPUT: a sequence of n numbers,  T is an array of n elements  T[1], T[2], …, T[n] OUTPUT: the smallest number among them Max, Min take time = n min = T[1] for i = 2 to n do { if T[i] < min min = T[i] } Output min 18372420

7 7 Simple Algorithms (cont.) Algorithms can be implemented in any programming language Usually we use “pseudo-code” to describe algorithms Example 2 (MAX algorithm): INPUT: a sequence of n numbers,  T is an array of n elements  T[1], T[2], …, T[n] OUTPUT: the largest (biggest) number among them Max = T[1] for i = 2 to n do { if T[i] > Max Max = T[i] } Output Max


Download ppt "1 Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال) Chapter 1 Introduction to Algorithms."

Similar presentations


Ads by Google