{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Chapter 1 - SHEN's CLASS NOTES-F06 Chapter 1 Introduction...

This preview shows pages 1–6. Sign up to view the full content.

SHEN’s CLASS NOTES-F06 1 Chapter 1 Introduction 1.1 Algorithms and problems An algorithm is a well-defined computational procedure to solve a computational problem (or problem for short). An algorithm must be correct. A good algorithm must be readable, time-efficient, space- efficient. A problem defines the requirements that valid output values must satisfy for a given set of input values. Usually, we are only interested in those problems that allow infinitely many different sets and sizes of input values.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
SHEN’s CLASS NOTES-F06 2 For example, the sorting problem takes n numbers as input set and requires the n numbers be arranged in descending or ascending order as the valid output, where the n can be any positive integer. For a particular set of input values, the problem is referred as an instance of the problem. Therefore, a problem must contain infinitely many instances. Solving a problem is to find a valid output for any given input, which is done by an algorithm. 1.2 Relationship between an algorithm and a data structure A data structure is a way to store and organize data in order to facilitate accesses and modifications.
SHEN’s CLASS NOTES-F06 3 An efficient algorithm relies upon efficient data structure. No single data structure works well for all purposes. It is important to get familiar with commonly used data structures that will be overviewed in Chapters 10-14 of the textbook. 1.3 Relationship between an algorithm and a program A program is a piece of code written in a particular language such as Pascal, C, C++, Java, or even some assembly language. Therefore, programs are language dependent or even machine dependent. A program can often be viewed as a detailed implementation of an algorithm with some limitations such as memory capacity, the largest number allowed, the largest size of an array, etc.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
SHEN’s CLASS NOTES-F06 4 An algorithm is of more abstract notion. It is language independent, machine independent. An algorithm is well defined as far as its steps can clearly implemented by any known language. Algorithms and programs are very closed related. We often use a known real language such as Pascal, C, C++ to describe an algorithm. Then, the algorithm looks like a program. However, in such a program, the grammar of the language will not be strictly followed and some notations may be changed to make the algorithm more readable. Such a language is called a pseudo language. Example 1. Problem: sorting n numbers Input: A[1], A[2], …, A[ n ] Output: arrange the n numbers such that A[1] A[2] A[ n ].
5 Algorithm Selection Sort (A[1. . n ]); 1 for ( i = 1, i n , i ++) 2 do { key = i 3 for ( j = i , j n , j ++) 4 do if A[ j ] < A[ key ] 5 then key j 6 A[ i ] A[ key ] 7 End We could call the language used in example 1 pseudo C++. However, this is not important to identify which language it looks like. We accept the presentation of an algorithm as far as its steps are clearly

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 28

Chapter 1 - SHEN's CLASS NOTES-F06 Chapter 1 Introduction...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online