Professional Documents
Culture Documents
Chapter 1
Chapter 1
Gedamu Alemu
alemugedamu@yahoo.com
Image processing and Computer vision SIG
Some of the sides are exported from different sources to clarify the topic
What is Algorithm
Definition and Basic Concept
Fundamental of Algorithmic Problem Solving
Understanding and choose b/n exact &approximate
problem solving
Important Problem Type
Sorting and searching
String processing and geometrical problem
Graph and Tree problem
Fundamental Data Structure
Liner data Structure
Non Liner Data stracture
Issues:
Correctness
space efficiency
time efficiency
optimality
Approaches:
theoretical analysis
empirical analysis
Introduction
5
Problem solving in computer Science
algorithm
Scope is limited I can not have a procedure for you to have very
happy life or becoming rich and famous
problem
Nonambiguity for each step
Range of inputs is specified carefully
The same algorithm can be represented in several ways
Several algorithms for the same problem may exist
Several algorithms with different ideas can solve the same
problem with different speed.
problem
algorithm
sorting
Statement of problem:
Input: A sequence of n numbers <a1, a2, …, an>
Output: A reordering of the input sequence <a´1, a´2, …, a´n> so that a´i ≤
a´j whenever i < j
Algorithms:
Selection sort
Insertion sort
Merge sort
(many others)
Proving correctness
Optimality
Analysis of Algorithms
Algorithms Examples
1-16
3- Digit Addition
Simply :
- Add the hundreds digit of the second number to the first number
- Add the tens digit to the result
- Add the unit digit to the result
Problem: Find gcd(m,n), the greatest common divisor of two nonnegative, not
both zero integers m and n
while n ≠ 0 do
r ← m mod n
m← n
n←r
return m
Computer Science and Engineering Program: DAA
Gedamu Alemu
29
Other methods for gcd(m , n) [cont.]
Middle-school procedure
Step 1 Find the prime factorization of m
Step 2 Find the prime factorization of n
Step 3 Find all the common prime factors
Step 4 Compute the product of all the common prime factors and return
it as gcd(m,n)
Example: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Algorithm
Understand the Problem
Decide on the machine to be used (sequential vs. parallel)
Design an algorithm: select a specific techniques such as divide and conquer .
Also, decide on how do you represent the algorithm for instance pseudocode ,
flowchart , etc..
Prove correctness may be by example or mathematically
Analyze the algorithm for instance in space and time efficiency
Searching
String processing
Graph problems
… ≤ a n.
´
Why sorting?
Help searching
Algorithms often use sorting as a key subroutine.
Sorting key
A specially chosen piece of information used to guide sorting. E.g., sort student
records by names.
Examples:
(i) searching for a word or phrase on WWW or in a Word
document
(ii) searching for a short read in the reference genomic
sequence
Data Structures:
An implementation of an ADT is a translation into
statements of a programming language,
─ the declarations that define a variable to be of that
ADT type
─ the operations defined on the ADT (using procedures
of the programming language)
Each data structure is built up from the basic data types of the
underlying programming language using the available data
structuring facilities, such as
arrays, records (structures in C), pointers, files, sets, etc.
3 4
Dense
Complete
0111 4
0001
0001
0000
1
5 2
6 7
9
3 4
8
Connected graphs
A graph is said to be connected if for every pair of its vertices u and v
there is a path from u to v.
Connected component
The maximum connected subgraph of a given graph.
Acyclic graph
A graph without cycles
DAG (Directed Acyclic Graph) 1 2
3 4
Forest
3
4 1 5
2
3 9
2 5 8