Fundamentals of Algorithms MCS - 2 Lecture # 7

Slides:



Advertisements
Similar presentations
Dynamic Programming 25-Mar-17.
Advertisements

Algorithm Design Techniques
Dynamic Programming.
Algorithm Design Methodologies Divide & Conquer Dynamic Programming Backtracking.
Introduction to Algorithms Greedy Algorithms
Traveling Salesperson Problem
Algorithm Design Techniques: Greedy Algorithms. Introduction Algorithm Design Techniques –Design of algorithms –Algorithms commonly used to solve problems.
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Types of Algorithms.
Algorithms + L. Grewe.
Problem Solving Dr. Andrew Wallace PhD BEng(hons) EurIng
Dynamic Programming.
5-1 Chapter 5 Tree Searching Strategies. 5-2 Satisfiability problem Tree representation of 8 assignments. If there are n variables x 1, x 2, …,x n, then.
Branch & Bound Algorithms
CS 345 Ch 4. Algorithmic Methods Spring, Misconceptions about CS Computer Science is the study of Computers. “Computer Science is no more about.
CS4413 Divide-and-Conquer
Introduction to Algorithms
Theory of Algorithms: Divide and Conquer
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Greedy Algorithms. 2 2 A short list of categories Algorithm types we will consider include: Simple recursive algorithms Backtracking algorithms Divide.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Chapter 10: Algorithm Design Techniques
MAE 552 – Heuristic Optimization Lecture 5 February 1, 2002.
5-1 Chapter 5 Tree Searching Strategies. 5-2 Breadth-first search (BFS) 8-puzzle problem The breadth-first search uses a queue to hold all expanded nodes.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
1 Algorithm Design Techniques Greedy algorithms Divide and conquer Dynamic programming Randomized algorithms Backtracking.
Backtracking.
ECE669 L10: Graph Applications March 2, 2004 ECE 669 Parallel Computer Architecture Lecture 10 Graph Applications.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Design and Analysis of Algorithms - Chapter 11 Algorithm An algorithm is a.
TK3043 Analysis and Design of Algorithms Introduction to Algorithms.
19-Aug-15 Simple Recursive Algorithms. 2 A short list of categories Algorithm types we will consider include: Simple recursive algorithms Backtracking.
Instructor: Dr. Sahar Shabanah Fall Lectures ST, 9:30 pm-11:00 pm Text book: M. T. Goodrich and R. Tamassia, “Data Structures and Algorithms in.
Lecture 23. Greedy Algorithms
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Minimum Spanning Trees
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
Exploring Algorithms Traveling Salesperson Problem I: Brute Force, Greedy, and Heuristics Except as otherwise noted, the content of this presentation is.
Dynamic Programming. Well known algorithm design techniques:. –Divide-and-conquer algorithms Another strategy for designing algorithms is dynamic programming.
Dr. Naveed Ahmad Assistant Professor Department of Computer Science University of Peshawar.
1 Summary: Design Methods for Algorithms Andreas Klappenecker.
Algorithm Paradigms High Level Approach To solving a Class of Problems.
Applications of Dynamic Programming and Heuristics to the Traveling Salesman Problem ERIC SALMON & JOSEPH SEWELL.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Algorithm Design Methods (II) Fall 2003 CSE, POSTECH.
Types of Algorithms. 2 Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We’ll talk about a classification.
Computer Sciences Department1.  Property 1: each node can have up to two successor nodes (children)  The predecessor node of a node is called its.
2016/3/13Page 1 Semester Review COMP3040 Dept. Computer Science and Technology United International College.
Data Structures and Algorithms Instructor: Tesfaye Guta [M.Sc.] Haramaya University.
CSE 250 – Data Structures. Today’s Goals  First review the easy, simple sorting algorithms  Compare while inserting value into place in the vector 
Various Problem Solving Approaches. Problem solving by analogy Very often problems can be solved by looking at similar problems. For example, consider.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
Greedy Algorithms.
TK3043 Analysis and Design of Algorithms
Major Design Strategies
Lecture 5 Dynamic Programming
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Types of Algorithms.
Lecture 5 Dynamic Programming
DYNAMIC PROGRAMMING.
Types of Algorithms.
CIT Nov-18.
Advanced Analysis of Algorithms
Backtracking and Branch-and-Bound
Types of Algorithms.
Dynamic Programming II DP over Intervals
Major Design Strategies
Major Design Strategies
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

Fundamentals of Algorithms MCS - 2 Lecture # 7

Types of Algorithms

Algorithms Classification Algorithms that use a similar problem-solving approach can be grouped together Simple recursive algorithms Backtracking algorithms Divide and conquer algorithms Dynamic programming algorithms Greedy algorithms Branch and bound algorithms Brute force algorithms Randomized algorithms

Simple Recursive Algorithms A recursive algorithm is an algorithm which calls itself with "smaller (or simpler)" input values, and which obtains the result for the current input by applying simple operations to the returned value for the smaller (or simpler) input. A simple recursive algorithm Solves the base cases directly Recurs with a simpler sub-problem Does some extra work to convert the solution to the simpler sub- problem into a solution to the given problem.

Example Recursive Algorithms To count the number of elements in a list If the list is empty, return zero; otherwise, Step past the first element, and count the remaining elements in the list Add one to the result To test if a value occurs in a list If the list is empty, return false; otherwise, If the first thing in the list is the given value, return true; otherwise Step past the first element, and test whether the value occurs in the remainder of the list

Backtracking Algorithms Backtracking algorithms are based on a depth-first recursive search and a refinement of the brute force approach. Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate c ("backtracks") as soon as it determines that c cannot possibly be completed to a valid solution. A backtracking algorithm Tests to see if a solution has been found, and if so, returns it; otherwise For each choice that can be made at this point, Make that choice Recur If the recursion returns a solution, return it If no choices remain, return failure.

Example Backtracking Algorithm Crossword example and Sudoku example Color Map example To color a map with no more than four colors color(Country n) If all countries have been colored (n > number of countries) return success; otherwise, For each color c of four colors, If country n is not adjacent to a country that has been colored c Color country n with color c recursively color country n+1 If successful, return success Return failure (if loop exits)

Divide and Conquer Algorithms A divide and conquer algorithm works by recursively breaking down a problem into two or more sub-problems of the same (or related) type, until these become simple enough to be solved directly. A divide and conquer algorithm consists of two parts Divide the problem into independent smaller sub-problems of the same type, and solve these sub-problems separately and recursively Combine the solutions to the sub-problems into a solution to the original problem Traditionally, an algorithm is only called divide and conquer if it contains two or more recursive calls. 2

Examples of Divide and Conquer Algorithm Binary Search Quick Sort Merge Sort Integer Multiplication Matrix Multiplication (Strassen's algorithm) Maximal Subsequence 3

Dynamic Programming Algorithms A dynamic programming algorithm remembers past results and uses them to find new results In general, to solve a given problem, we need to solve different parts of the problem (sub-problems), then combine the solutions of the sub- problems to reach an overall solution. Dynamic programming is generally used for optimization problems Multiple solutions exist, need to find the “best” one Requires “optimal substructure” and “overlapping sub-problems” Optimal substructure contains optimal solutions to sub-problems In overlapping sub-problems, solutions to sub-problems can be stored and reused in a bottom-up fashion This differs from Divide and Conquer, where sub-problems generally need not overlap

Examples of Dynamic Programming Algorithms Dijkstra's algorithm for the shortest path problem Fibonacci sequence A type of balanced 0–1 matrix Checkerboard Sequence alignment Tower of Hanoi puzzle Egg dropping puzzle Matrix chain multiplication

Greedy Algorithms An optimization problem is one in which you want to find, not just a solution, but the best solution A “greedy algorithm” sometimes works well for optimization problems A greedy algorithm works in phases: At each phase: You take the best you can get right now, without regard for future consequences You hope that by choosing a local optimum at each step, you will end up at a global optimum 2

Example of Greedy Algorithms Huffman Tree algorithm Travelling Salesman algorithm Malfatti’s circle problem Prim's algorithm Kruskal algorithm Dijkstra's Algorithm Change-making problem Greedy algorithms determine the minimum number of coins to give while making change. These are the steps a human would take to emulate a greedy algorithm to represent 36 cents using only coins with values {1, 5, 10, 20}. The coin of the highest value, less than the remaining change owed, is the local optimum.

Branch and Bound Algorithms Branch and bound algorithms are generally used for optimization problems As the algorithm progresses, a tree of sub-problems is formed The original problem is considered the “root problem” A method is used to construct an upper and lower bound for a given problem At each node, apply the bounding methods If the bounds match, it is considered a feasible solution to that particular sub-problem If bounds do not match, partition the problem represented by that node, and make the two sub-problems into children nodes Continue, using the best known feasible solution to trim sections of the tree, until all nodes have been solved or trimmed.

Example Branch and Bound Algorithm Travelling salesman problem A salesman has to visit each of n cities (at least) once each, and wants to minimize total distance travelled Consider the root problem to be the problem of finding the shortest route through a set of cities visiting each city once Split the node into two child problems: Shortest route visiting city A first Shortest route not visiting city A first Continue subdividing similarly as the tree grows

Brute Force Algorithm A brute force algorithm simply tries all possibilities until a satisfactory solution is found. Such an algorithm can be: Optimizing: Find the best solution. This may require finding all solutions, or if a value for the best solution is known, it may stop when any best solution is found Example: Finding the best path for a travelling salesman Satisficing: Stop as soon as a solution is found that is good enough Example: Finding a travelling salesman path that is within 10% of optimal

Randomized Algorithms A randomized algorithm is an algorithm which employs a degree of randomness as part of its logic. A randomized algorithm uses a random number at least once during the computation to make a decision Example: In Quicksort, using a random number to choose a pivot Example: Trying to factor a large prime by choosing random numbers as possible divisors

Good Luck ! ☻