
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























Ed Bosworth Computer Science Department Columbus State University Columbus, GA [email protected]
Some programming experience, maybe in Visual Basic or C++ Have seen some algorithms for searching and sorting Algebra, including logarithms and exponents. Factorial function: N! = N (N – 1) … N – 1) … ) … 2 1) …
Problem Sort a list by comparison, using a defined operator Traveling salesman Strategy Divide and conquer Algorithm Bubble Sort, Quick Sort, Merge Sort, etc. Breadth first search, depth first search, etc. Programs Implementation of an algorithm in a specific language
Characteristic: Try every solution and see if one works. Classic problem: Tiling a floor with irregularly shaped tiles Like a jigsaw puzzle if you do it “upside-down”, except you know that the puzzle can be completed. Heuristics: For jigsaw puzzles you use a number of clues, such as colors to aid in putting the puzzle together. Heuristics do not guarantee an answer, but often produce one.
Sample Problems Sort a list by comparison, using a defined ≥ operator. Traveling Salesman – route through each city exactly once. Matrix addition and matrix multiplication Sample Strategies Brute Force Divide and Conquer Dynamic Programming Greedy Sample Algorithms Bubble Sort, Quick Sort, Merge Sort, etc. Breadth-First Search (N – 1) … BFS), Depth-First Search (N – 1) … DFS)
Question: How to make the program run faster? Answers: Buy a bigger computer (N – 1) … Your boss has lots of money). Implement in a more efficient computer language. Devise a more efficient algorithm. We focus on developing a more efficient algorithm. Efficiency is measured in time complexity, which is different from total run time. Run time is dependent on the computer. This allows us to assess the algorithm independently of the computer and programming language implementation.
The “Big-O” and “Big-’ notation for positive functions; f(N – 1) … n) > 0. f(N – 1) … n) is O(N – 1) … g(N – 1) … n)) if there exist positive integers K and N such that for all n N, f(N – 1) … n) Kg(N – 1) … n). f(N – 1) … n) is (N – 1) … g(N – 1) … n)) if there exist positive integers K and N such that for all n N, f(N – 1) … n) Kg(N – 1) … n). Typical functions for g(N – 1) … n) logarithmic: ln(N – 1) … n), log1) … 0(N – 1) … n), etc. polynomial: n 2 , n 3 , etc. nlog(N – 1) … n) is “polynomial” exponential: 2 n , e n , n!, etc.
log1) … 0(N – 1) … n) is O(N – 1) … n) because for n > 1) … , log1) … 0(N – 1) … n) n. log1) … 0(N – 1) … n) and ln(N – 1) … n) are the same order because log1) … 0(N – 1) … n) = log1) … 0(N – 1) … e) ln(N – 1) … n) n 2
An algorithm A is said to be O(N – 1) … f(N – 1) … n)) if the input size is a positive integer n the number of basic steps is T(N – 1) … n) T(N – 1) … n) is O(N – 1) … f(N – 1) … n)) Bubble sort is O(N – 1) … n 2 ) Quick sort is O(N – 1) … nlog(N – 1) … n)), also O(N – 1) … n 2 ) Both are “polynomial”
Let problem X be solved by algorithms A1) … , A 2 , …., An. The time complexity of X is not greater than the minimum of the time complexities of A1) … , A 2 , …., An. The lower bound for a problem must be established theoretically, not just by comparing every algorithm known to solve it.
Consider three square matrices (N – 1) … N by N) A, B, C where C is either the sum or product of matrices A and B The basic structure for setting values for array C must be for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) c[i][j] = something It takes n 2 steps to fill the n by n array, so both the addition and multiplication problems are (N – 1) … n 2 ).
The standard algorithm for C = A * B can be expressed as for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) // The following step is executed n 2 times { c[i][j] = 0; for (int k = 0; k < n; k++) // This step is executed n 3 times. c[i][j] = c[i][j] + a[i][k] * b[k][j]; } The number of steps is n 3
) and O(N – 1) … n
)
Published by the French mathematician Edouard Lucas in 1) … 883. Question: How many steps to move N disks? RULES: Move all disks from peg 1) … to peg 2 Move one disk at a time Do not place a larger disk on top of a smaller disk.