Homework page 102 questions 1, 4, and 10 page 106 questions 4 and 5 page 111 question 1 page 119 question 9.

Slides:



Advertisements
Similar presentations
Algorithm Design Techniques
Advertisements

Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin Introduction to the Design & Analysis of Algorithms, 2 nd ed., Ch. 1 Chapter 2.
Limitation of Computation Power – P, NP, and NP-complete
Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
Lecture 21 Paths and Circuits CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley. All rights reserved.
Chapter 4 sec. 2.  A famous and difficult problem to solve in graph theory.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 3 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
S. J. Shyu Chap. 1 Introduction 1 The Design and Analysis of Algorithms Chapter 1 Introduction S. J. Shyu.
The Design and Analysis of Algorithms
Theory of Algorithms: Brute Force James Gain and Edwin Blake {jgain | Department of Computer Science University of Cape Town August.
COSC 3100 Brute Force and Exhaustive Search Instructor: Tanvir 1.
Lecture 8 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Design and Analysis of Algorithms - Chapter 31 Brute Force A straightforward approach usually based on problem statement and definitions Examples: 1. Computing.
Analysis & Design of Algorithms (CSCE 321)
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.
1 -1 Chapter 1 Introduction Why Do We Need to Study Algorithms? To learn strategies to design efficient algorithms. To understand the difficulty.
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
The Theory of NP-Completeness
Design and Analysis of Algorithms - Chapter 31 Brute Force A straightforward approach usually based on problem statement and definitions Examples: 1. Computing.
Ch 13 – Backtracking + Branch-and-Bound
Lecture 6 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
1.1 Chapter 1: Introduction What is the course all about? Problems, instances and algorithms Running time v.s. computational complexity General description.
RAIK 283: Data Structures & Algorithms
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Chapter 12 Coping with the Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
IT 60101: Lecture #201 Foundation of Computing Systems Lecture 20 Classic Optimization Problems.
CSE 326: Data Structures NP Completeness Ben Lerner Summer 2007.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 3 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Theory of Algorithms: Brute Force. Outline Examples Brute-Force String Matching Closest-Pair Convex-Hull Exhaustive Search brute-force strengths and weaknesses.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
Brute Force A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved Examples: Computing.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 3 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
5-1-1 CSC401 – Analysis of Algorithms Chapter 5--1 The Greedy Method Objectives Introduce the Brute Force method and the Greedy Method Compare the solutions.
Chapter 3 Brute Force. A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved Examples:
LIMITATIONS OF ALGORITHM POWER
COMP108 Algorithmic Foundations Polynomial & Exponential Algorithms
Lecture 7 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
1 UNIT-I BRUTE FORCE ANALYSIS AND DESIGN OF ALGORITHMS CHAPTER 3:
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
MA/CSSE 473 Day 12 Amortization (growable Array) Knuth interview Brute Force Examples.
Ch3 /Lecture #4 Brute Force and Exhaustive Search 1.
Exhaustive search Exhaustive search is simply a brute- force approach to combinatorial problems. It suggests generating each and every element of the problem.
MA/CSSE 473 Day 11 Knuth interview Amortization (growable Array) Brute Force Examples.
Introduction to Algorithms: Brute-Force Algorithms.
Brute Force A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved Examples: Computing.
Brute Force II.
Limitation of Computation Power – P, NP, and NP-complete
Brute Force A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved Examples: Computing.
Brute Force Algorithms
Brute Force A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved Examples: Computing.
COMP108 Algorithmic Foundations Polynomial & Exponential Algorithms
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 3 String Matching.
Brute Force A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved Examples – based directly.
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 3 String Matching.
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 3 Brute Force Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Brute Force A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved Examples: Computing.
Brute Force A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved Examples: Computing.
Recall Some Algorithms And Algorithm Analysis Lots of Data Structures
3. Brute Force Selection sort Brute-Force string matching
3. Brute Force Selection sort Brute-Force string matching
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 36 P vs
3. Brute Force Selection sort Brute-Force string matching
Presentation transcript:

Homework page 102 questions 1, 4, and 10 page 106 questions 4 and 5 page 111 question 1 page 119 question 9

Brute Force A straightforward approach usually based on problem statement and definitions Examples: 1. Computing a n (a > 0, n a nonnegative integer) 2.Computing n! 3. Multiply two n by n matrices 4.Selection sort 5.Sequential search

String matching pattern: a string of m characters to search for text: a (long) string of n characters to search in Brute force algorithm: 1. Align pattern at beginning of text 2. moving from left to right, compare each character of pattern to the corresponding character in text until all characters are found to match (successful search); or a mismatch is detected 3. while pattern is not found and the text is not yet exhausted, realign pattern one position to the right and repeat step 2.

String Matching Pattern: GATTTCG (length = m = 7) Text: GATTTCG GATTTCATCAGATTTCGATACAGAT GATTTCG Text length = n = 25 Best Case: ? Worst Case: ?

Brute Force String Matching Pattern length = m; Text length = n; Best Case: GATTTCATCAGATTTCGATACAGAT GATTTCA O(m) The pattern is found right away, but you still have to do m comparison to verify that is was found.

Brute Force String Matching Pattern length = m; Text length = n; Worst Case: O(mn) How is this possible? AAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAB AAAAAABAAAAAABAAAAAABAAAAAABA AAAAAAA

Brute Force String Matching Pattern length = m; Text length = n; Average Case: Observation: If the number of symbols is relatively large (26 for example) then  Most shifts will happen after very few comparisons. In fact, there are very few pattern-text combinations that will cause  (m) comparisons for each shift. Note: There are always  (n) shifts if the pattern is not found

Brute Force String Matching Pattern length = m; Text length = n; Average Case: It has been shown (very convincing, not mathematically proven) (very convincing, not mathematically proven) that for both random text and human generated text that for both random text and human generated text the average case is O(m+n) = O(n) the average case is O(m+n) = O(n) Since n > m. Since n > m.

Brute force polynomial evaluation Problem: Find the value of polynomial p(x) = a n x n + a n-1 x n-1 +… + a 1 x 1 + a 0 at a point x = x 0 Algorithm: p := 0.0 for i := n down to 0 do power := 1 for j := 1 to i do power := power * x p := p + a[i] * power return p

Polynomial evaluation: improvement We can do better by evaluating from right to left: Algorithm:Efficiency: p := a[0] power := 1 for i := 1 to n do power := power * x p := p + a[i] * power return p

More brute force algorithm examples: Closest pair Problem: find closest among n points in k- dimensional space Problem: find closest among n points in k- dimensional space Algorithm: Compute distance between each pair of points Algorithm: Compute distance between each pair of points Efficiency: Efficiency:

More brute force algorithm examples: Convex hull Problem: find smallest convex polygon enclosing n points on the plane Problem: find smallest convex polygon enclosing n points on the plane Algorithm: For each pair of points p 1 and p 2 determine whether all other points lie to the same side of the straight line through p 1 and p 2 Algorithm: For each pair of points p 1 and p 2 determine whether all other points lie to the same side of the straight line through p 1 and p 2 Efficiency: Efficiency:

Brute force strengths Strengths: wide applicability wide applicability simplicity simplicity yields reasonable algorithms for some important problems yields reasonable algorithms for some important problemssearching string matching matrix multiplication yields standard algorithms for simple computational tasks yields standard algorithms for simple computational tasks sum/product of n numbers finding max/min in a list

Brute force weaknesses Weaknesses: rarely yields efficient algorithms rarely yields efficient algorithms some brute force algorithms unacceptably slow some brute force algorithms unacceptably slow not as constructive/creative as some other design techniques not as constructive/creative as some other design techniques

Exhaustive search A brute force solution to a problem involving search for an element with a special property, usually among combinatorial objects such a permutations, combinations, or subsets of a set.

Exhaustive search Method: construct a way of listing all potential solutions to the problem in a systematic manner construct a way of listing all potential solutions to the problem in a systematic manner all solutions are eventually listed no solution is repeated Evaluate solutions one by one, perhaps disqualifying infeasible ones and keeping track of the best one found so far Evaluate solutions one by one, perhaps disqualifying infeasible ones and keeping track of the best one found so far When search ends, announce the winner When search ends, announce the winner

Example 1: Traveling salesman problem Given n cities with known distances between each pair, find the shortest tour that passes through all the cities exactly once before returning to the starting city. Alternatively: Find shortest Hamiltonian circuit in a weighted connected graph.

Example 1: Traveling salesman problem Example: ab cd

Traveling salesman by exhaustive search a→b→c→d→a = 17 a→b→d→c→a = 21 a→c→b→d→a = 20 a→c→d→b→a = 21 a→d→b→c→a = 20 a→d→c→b→a = 17

Example 2: Knapsack Problem Given n items: weights: w 1 w 2 … w n weights: w 1 w 2 … w n values: v 1 v 2 … v n values: v 1 v 2 … v n a knapsack of capacity W a knapsack of capacity W Find the most valuable subset of the items that fit into the knapsack

Example 2: Knapsack Problem Example: item weight value Knapsack capacity W= $ $ $ $10

Knapsack by exhaustive search Subset Total weight Total value {1} 2 $20 {1} 2 $20 {2} 5 $30 {2} 5 $30 {3} 10 $50 {3} 10 $50 {4} 5 $10 {4} 5 $10 {1,2} 7 $50 {1,2} 7 $50 {1,3} 12 $70 {1,3} 12 $70 {1,4} 7 $30 {1,4} 7 $30 {2,3} 15 $80 {2,3} 15 $80 {2,4} 10 $40 {2,4} 10 $40 {3,4} 15 $60 {3,4} 15 $60 {1,2,3} 17 not feasible {1,2,3} 17 not feasible {1,2,4} 12 $60 {1,2,4} 12 $60 {1,3,4} 17 not feasible {1,3,4} 17 not feasible {2,3,4} 20 not feasible {2,3,4} 20 not feasible {1,2,3,4} 22 not feasible Efficiency:

Final comments: Exhaustive search algorithms run in a realistic amount of time only on very small instances In many cases there are much better alternatives! Euler circuits Euler circuits shortest paths shortest paths minimum spanning tree minimum spanning tree assignment problem assignment problem In some cases exhaustive search (or variation) is the only known solution

Homework page 102 questions 1, 4, and 10 page 106 questions 4 and 5 page 111 question 1 page 119 question 9