Chapter 5 Algorithms (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.

Post on 04-Jan-2016

223 views 4 download

Transcript of Chapter 5 Algorithms (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.

Chapter 5Algorithms (1)

Introduction to CS

1st Semester, 2015 Sanghyun Park

Outline Informal Definition of an Algorithm FindLargest Three Basic Constructs Sorting Algorithms Searching Algorithms Recursion Algorithm Performance (next file) Time Complexity (next file) Asymptotic Notation (next file) Growth Rate (next file)

Informal Definition of AlgorithmUsed in Computer

Finding the Largest NumberAmong Five Integers

Defining Actions inFindLargest Algorithm

FindLargest Refined

Generalization of FindLargest

Three Basic Constructs

Flowcharts for Three Constructs

Pseudocode for Three Constructs

Concept of Subalgorithm

Summation

Product

Selection Sort

Example of Selection Sort (1/2)

Example of Selection Sort (2/2)

Selection Sort Algorithm

Bubble Sort

Example of Bubble Sort (1/2)

Example of Bubble Sort (2/2)

Insertion Sort

Example of Insertion Sort (1/2)

Example of Insertion Sort (2/2)

Search Concept

Example of Sequential Search (1/2)

Example of Sequential Search (2/2)

Sequential Search AlgorithmWhen List is Sorted

Example of Binary Search

Binary Search Algorithm

Iterative Definition of Factorial

Recursive Definition of Factorial

Tracing Recursive Solution toFactorial Problem