Lecture #1:Characterization of types of algorithms: Off-line vs on-line algorithms; de-terministic vs randomized algorithms; exact vs approximation algorithms; se-quential vs parallel algorithms; centralized vs distributed algorithms. Thiscourse primarily deals with off-line, deterministic, exact, sequential,centralized algorithms.What bothers most of about this course (and similar other courses) is thefact that there are no algorithms to show how algorithms are designed. This areais somewhat similar to solving mathematics puzzles. Results are not guaranteedbased on effort or time spent.Types of Algorithms based on methods used:1. Divide and Conquer2. Greedy Methods3. Dynamic Programming4. Incremental Algorithms (also known as inductive algorithms)5. Improvement Algorithms6. Parametric algorithms7. Duality based algorithmsExample 1 Binary Search: Worst case effort: Θ(log2n)• Given a sorted array of n numbers, A[1, 2, ..., n], and a number x.Permitted operations: Given two numbers, x and y check which of thefollowing holds: (i)x = y; (ii)x < y; or (iii)x > yQuestion: Is x = A[j] for some j between 1 and n? If the answer is yes,output j; else output no (some times we may give an interval [i, i + 1]such that A[i] < x < A[i + 1]).BINARY-SEARCH(A[i, j], x)if j < i STOP.k ←i+j2if A[k] = x, STOPelse if A[k] < x, do BINARY-SEARCH(A[i, k], x)else do BINARY-SEARCH(A[k + 1, j], x)This is an example of divide and conquer where we get one subproblem ofhalf the size.Recursion encountered: t(n) = 1 + t(n2)1Example 2 Tower of Hanoi/Brahma: Effort: 2m− 1• Given three rods numbered 1,2, and 3 with m rings on rod 1 and noneon rods 2 and 3. The rings on rod 1 are stacked in order of size with thesmallest on top. (like the toy children play with)Permitted operations: Move the top ring on any rod to any other rodprovided that at no time a larger ring is on top of a smaller ring on anyrod.Question: Want to move the rings from rod 1 to rod 2 with minimumnumber of moves.Recursion: t(n) = 1 + 2t(n − 1)Example 3 Insertion Sort: (CLR has a pseudocode)• Effort:n(n−1)2in the worst case; (n − 1) in the best case.If we use Binary search in determining the location to insert, the worstcase effort becomes n−1i=1log2i and this is Θ(n log2n)Example 4 Merge Sort:: (CLR pages 12-15):• Effort: Θ(n log2n) in the worst case. This is an example of divide andconquer where we get two subproblems of half the size.Recursion: t(n) = 2t(n2) + Θ(n)Example 5 Tiling:• Given a square board of size 2kdivided into 22kequal size squares of size1 (like in a chess/checker board). An arbitrary square is declared special.Also given tiles which are squares of size 2 with one square removed.Question: Can we cover all the squares in the bigger board (except thespecial square) with tiles of the above type? If so, provide a method to do2this. See the picture below for the case with k = 2:This is also an example of Divide and conquer. Here we get 4 subproblemsof size 2k−1. But three of the problems are the
View Full Document