0% found this document useful (0 votes)
27 views11 pages

Really: See Page 2 Quoted

The document discusses algorithms and their properties. It defines an algorithm as a sequence of unambiguous instructions to solve a problem in a finite number of steps. It lists the main steps to develop an algorithm and some common problem types algorithms address, such as sorting, searching, string processing, and graph and geometric problems. Examples are given of pseudocode for algorithms, including the Euclid's algorithm for finding the greatest common divisor and a sequential search algorithm. For each algorithm, the inputs, outputs, and time complexity are described.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views11 pages

Really: See Page 2 Quoted

The document discusses algorithms and their properties. It defines an algorithm as a sequence of unambiguous instructions to solve a problem in a finite number of steps. It lists the main steps to develop an algorithm and some common problem types algorithms address, such as sorting, searching, string processing, and graph and geometric problems. Examples are given of pseudocode for algorithms, including the Euclid's algorithm for finding the greatest common divisor and a sequential search algorithm. For each algorithm, the inputs, outputs, and time complexity are described.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Chapter 1.

See page 2; quoted: ... a person does not really understand something until after teaching it to someone else

actually:

a person does not REALLY understand something until after teaching it to a computer.

An algorithm is a sequence of unambiguous instructions for solving a problem, i.e. for obtaining a required output for any legitimate input in a finite amount of time.

An algorithm is written in pseudocode, i.e. a mixture of a natural language and programming language-like construct if then if then else for do while do repeat until

1. 2. 3. 4. 5. 6. 7. 8. 9.

understand the problem ascertain the capabilities of the computational device choose between exact and approximate problem solving decide on appropriate data structures determine algorithm design techniques select the method of specifying an algorithm prove the algorithms correctness analyze the algorithm code the algorithm

the most important problem types are:


1. sorting
rearrange items of a given list in a specific order, based on some key

2. searching
find a given search key in a given set

3. string processing
search a word in a text

4. graph problems
includes graph traversal problems, shortest-path algorithms, topological sorting, graph coloring problems

5. combinatorial problems
e.g. traveling salesman

next

6. geometric problems
the closest-pair problem, the convex hull problem

7. numerical problems
solve equations & systems of equations, evaluate functions, etc.

Example:

ALGORITHM Euclid (m, n) // compute GCD(m, n) by Euclids algorithm // input: two non-negative, not-both-zero integers m and n // output: Greatest Common Divisor of m and n

while n 0 do r m mod n m n n r return m

Example:

ALGORITHM Euclid (m, n) // compute GCD(m, n) by Euclids algorithm


// input: two non-negative, not-both-zero integers m and n // output: Greatest Common Divisor of m and n

while n 0 do r m mod n m n n r return m Input : m and n Output: the greatest common divisor of m and n Time : ?

Example:
Algorithm sequential search (A[0..n-1], K) (see page 47)

// searches for a given value in a given array by sequential search // input: an array A[0..n-1] and a search key K // output: returns the index of the first element of A that matches K // or -1 if there are no matching elements i 0 while i < n and A[i] K do i i + 1 if i < n return i else return -1

Example:
Algorithm sequential search (A[0..n-1], K) (see page 47)
// searches for a given value in a given array by sequential search // input: an array A[0..n-1] and a search key K // output: returns the index of the first element of A that matches K // or -1 if there are no matching elements

i 0 while i < n and A[i] K do i i + 1 if i < n return i else return -1

Input: A[0..n-1], K Time: ?

output: j such that A[j] = K or 1

You might also like