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

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

View Full Document Right Arrow Icon
SHEN’s CLASS NOTES-F06 Chapter 1 Introduction 1.1Algorithms 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. 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
SHEN’s CLASS NOTES-F06 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.2Relationship 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. 2
Background image of page 2
SHEN’s CLASS NOTES-F06 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.3Relationship 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. 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
SHEN’s CLASS NOTES-F06 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 ]. 4
Background image of page 4
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 implementable. Example 2 shows another way to present the same sorting algorithm of Example 1. Example 2.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/12/2008 for the course CS 592 taught by Professor Shen during the Fall '05 term at University of Missouri-Kansas City .

Page1 / 30

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 Right Arrow Icon
Ask a homework question - tutors are online