lecture4

lecture4 - Discrete Computation Structures CSE 2353 Bhanu...

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

View Full Document Right Arrow Icon
Discrete Computation Structures CSE 2353 Bhanu Kapoor, PhD Department of Computer Science & Engineering Southern Methodist University, Dallas, TX [email protected] , 214-336-4973 September 08, 2009 Embrey 129, SMU, Dallas, Texas Lecture 04 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
Lecture 04 Agenda ± Introduction to Algorithms ± Bubble Sort, Insertion Sort, Merge Sort 2
Background image of page 2
Algorithms ± Definition: step-by-step problem-solving process in which a solution is arrived at in a finite amount of time ± All algorithms have the following properties: ² Input : For example, a set of numbers to find the sum of the numbers utput For example the sum of the numbers ² Output : For example, the sum of the numbers ² Precision : Each step of the algorithm is precisely defined ² Uniqueness : Results of each step are unique and depend on the put and results of previous step input and results of previous step ² Finiteness : Algorithm must terminate after executing a finite number of steps enerality Algorithm is general in that it applies to a set of inputs ² Generality : Algorithm is general in that it applies to a set of inputs
Background image of page 3

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

View Full DocumentRight Arrow Icon
Algorithms ± Pseudocode Conventions ² The symbol := is called the assignment operator xample: The statement x : a is read as “assign the ± Example: The statement x := a is read as assign the value a to x” or “x gets the value a” or “copy the value of a into x” ± x := a is also known as an assignment statement ² Control Structures ± One way-selection ² if booleanExpression then statement booleanExpression evaluates to true statement is ² If booleanExpression evaluates to true, statement is evaluated ± Two way-selection ² if booleanExpression then statement1 else statement2 ² If booleanExpression evaluates to true , statement1 executes, ² otherwise statement2 executes
Background image of page 4
Algorithms ± Pseudocode Conventions ² Control Structures he while loop takes the form: ± The while loop takes the form: ² while booleanExpression do loopBody ² The booleanExpression is evaluated. If it valuates to true loopBody executes Thereafter evaluates to true, loopBody executes. Thereafter loopBody continues to execute as long as booleanExpression is true ± The for loop takes the form: p ² for var := start to limit do loopBody ² var is an integer variable. The variable var is set to the value specified by start. If var limit, loopBody executes. After executing the loopBody , var is incremented by 1. The statement continues to execute until var > limit
Background image of page 5

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

View Full DocumentRight Arrow Icon
Algorithms ± Pseudocode Conventions ² Control Structures ± The do/while loop takes the form: ² do loopBody while booleanExpression ² The loopBody is executed first and then the booleanExpression is evaluated. The l opBody continues to execute as long as oop ody co t ues to e ecute as o g as the booleanExpression is true
Background image of page 6
Algorithms ± Pseudocode Conventions ² Block of Statement ± To consider a set of statements a single statement, the statements are written between the words begin and end begin statement1 tatement2 statement2 ...
Background image of page 7

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

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

This note was uploaded on 11/11/2009 for the course CSE 2353 taught by Professor Bhanukapoor during the Spring '09 term at SMU.

Page1 / 82

lecture4 - Discrete Computation Structures CSE 2353 Bhanu...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online