2. 2
CHAPTER 1: INTRODUCTIONCHAPTER 1: INTRODUCTION
What is an Algorithm
Steps in Designing and Implementing
an Algorithm
Important Problem Types
Fundamental Data Structures
4. Sorting
The sorting problem is to rearrange the
items of a given list in nondecreasing
order.
Specially chosen piece of information that
guides sorting is called a key.
4
5. Why Sort?
ranking Internet search results
ranking students by their GPAscores.
sorting makes many questions about the
list easier to answer.
The most important of them is searching
sorting is used as an auxiliary step in several
important algorithms ,
e.g., geometric algorithms and Data Compression,
Greedy Approach
5
6. Different Algorithms Different
Time Complexities
Good sorting algorithms that sort an arbitrary
array of size n using about n log2 n
comparisons
6
7. Properties of Sorting Algorithms
Stable Algorithm
preserves the relative order of any two equal
elements in its input.
In- place Algorithm
algorithm is does not require extra memory,
except, possibly, for a few memory units.
7
9. Searching
The searching problem deals with
finding a given value, called a search
key, in a given set or a multiset
9
10. For searching, too, there is no single
algorithm that fits all situations best.
Some algorithms work faster with more
memory requirement
Some are very fast but applicable only to
sorted arrays
Applications where the underlying data
may change frequently relative to the
number of searches to be considered
10
11. String Processing
A string is a sequence of characters
from an alphabet
Applications: searching for a given word in
a text called string matching
11
13. Graph Problems
A graph can be thought of as a
collection of points called vertices,
some of which are connected by line
segments called edges. (informal
definition)
Applications:
transportation
Communication
social and economic networks
project scheduling
games.
13
14. Basic graph algorithms:
Graph-traversal algorithms
Shortest-path algorithms
Topological sorting for graphs with directed
edges
14
15. Example Problems:
Graph-coloring problem
Event scheduling
Traveling Salesman Problem (TSP)
route planning
Circuit board and VLSI chip fabrication
X-ray crystallography
genetic engineering
15
18. Combinatorial Problems
Problems that ask, explicitly or implicitly,
to find a combinatorial object that satisfies
certain constraint:
a permutation
a combination
a subset
Additional properties:
Maximum Value
Minimum Value
Eg. TSP
18
19. Difficulties faced in solving combinatorial
problems:
The number of combinatorial objects typically
grows extremely fast with a problem’s size
There are no known algorithms for solving most
such problems exactly in an acceptable amount
of time. (This statement is neither proved nor
disproved)
19
20. Geometric Problems
Geometric algorithms deal with
geometric objects such as points,
lines, and polygons
Applications:
Computer graphics
Robotics
Tomography
Classic problems:
Closest-pair problem
Convex-hull problem 20
21. Numerical Problems
Numerical problems involve mathematical
objects of continuous nature: solving
equations and systems of equations,
computing definite integrals, evaluating
functions, and so on.
21
22. Majority of such mathematical problems
can be solved only approximately
Problems require manipulating real
numbers, which can be represented in a
computer only approximately
A large number of arithmetic operations -
lead to an accumulation of the round-off
error - drastically distort an output
produced by a seemingly sound algorithm
22
23. Requirement of Applications:
information storage, retrieval
transportation through networks
presentation to users
23
24. Check if you are Clear with:
Sorting
Searching
String processing
Graph problems
Combinatorial problems
Geometric problems
Numerical problems
24