1 / 7

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

Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال). Chapter 1 Introduction to Algorithms. 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:

genica
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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 تصاعديا)

  3. Input Algorithm Output Algorithms • Algorithm is: • A tool for solving a well-specified computational problem • 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

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

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

  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

  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

More Related