0% found this document useful (0 votes)
5 views

Exhaustive Search and Naive Algorithm

The document discusses various algorithms including Exhaustive Search, Voronoi Diagrams, and the Naive String-Matching Algorithm. It explains the systematic approach of Exhaustive Search for problems like the Traveling Salesman Problem, Knapsack Problem, and Assignment Problem, highlighting their time complexity and applications. Additionally, it covers the principles, advantages, and challenges of Voronoi diagrams, as well as the Naive String-Matching Algorithm's methodology and efficiency.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Exhaustive Search and Naive Algorithm

The document discusses various algorithms including Exhaustive Search, Voronoi Diagrams, and the Naive String-Matching Algorithm. It explains the systematic approach of Exhaustive Search for problems like the Traveling Salesman Problem, Knapsack Problem, and Assignment Problem, highlighting their time complexity and applications. Additionally, it covers the principles, advantages, and challenges of Voronoi diagrams, as well as the Naive String-Matching Algorithm's methodology and efficiency.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

CSE408

Exhaustive Search, Voronoi


Diagrams, Naiva
String-Matching Algorithm,
Exhaustive Search
• Enumerate all possible solutions to problem.
• Systematically check each for validity.
• Stop when a valid solution found.
• Continue until all solutions are checked
• .Return the valid solutions if any.
• Otherwise, report no valid solutions exist.
Characteristics

• Systematic Exploration
• Guarantees a Solution Simple
• Implementation
• Time-Consuming
Algorithm

• Generate all possible configurations


systematically.
• Check each configuration for problem
requirements.
• Return solutions meeting all specified criteria.
Example 1: Traveling Salesman Problem
• Given n cities with distances.
• Evaluate all city permutations for shortest.
• Alternatively, find shortest Hamiltonian circuit.
• In weighted, connected graph, determine
path.
• Example: a 2 b
5 3
8 4

c 7 d

How do we represent a solution (Hamiltonian circuit)?


TSP by Exhaustive Search
Tour Cost
a→b→c→d→a 2+3+7+5 = 17
a→b→d→c→a 2+4+7+8 = 21
a→c→b→d→a 8+3+4+5 = 20
a→c→d→b→a 8+7+4+2 = 21
a→d→b→c→a 5+4+3+8 = 20
a→d→c→b→a 5+7+3+2 = 17

Efficiency:
Applications
Example 2: Knapsack Problem
Given n items:
– weights: w1 w2 … wn
– values: v1 v2 … vn
– a knapsack of capacity W
Find most valuable subset of the items that fit into the
knapsack

Example: Knapsack capacity W=16


item weight value
1 2 $20
2 5 $30
3 10 $50
Knapsack Problem by Exhaustive Search
Subset Total weight Total value
{1} 2 $20
{2} 5 $30
{3} 10 $50
{4} 5 $10
{1,2} 7 $50
{1,3} 12 $70
{1,4} 7 $30
{2,3} 15 $80
{2,4} 10 $40
{3,4} 15 $60
{1,2,3} 17 not feasible
{1,2,4} 12 $60
{1,3,4} 17 not feasible
{2,3,4} 20 not feasible
{1,2,3,4} 22 not feasible

Efficiency: Θ(2^n)
Each subset can be represented by a binary string (bit vector, Ch 5).
Applications
Example 3: The Assignment Problem

• List all possible job assignments.


• Calculate total cost for each assignment.
• Compare costs of all assignments.
• Track minimum cost and corresponding
assignment.
• Select assignment with lowest total cost.
• Output optimal assignment and minimal cost.
Assignment Problem by Exhaustive Search

9 2 7 8
6 4 3 7
C=
5 8 1 8
7 6 9 4

Assignment (col.#s) Total Cost


1, 2, 3, 4 9+4+1+4=18
1, 2, 4, 3 9+4+8+9=30
1, 3, 2, 4 9+3+8+4=24
1, 3, 4, 2 9+3+8+6=26
1, 4, 2, 3 9+7+8+9=33
1, 4, 3, 2 9+7+1+6=23

(
Time Complexity

• O(n!×n)
Applications
Challenges and Alternatives to
Exhaustive Search

•Exhaustive search works for small instances.


•Larger problems require more efficient algorithms.
•Euler circuits, shortest paths, spanning tree.
•Assignment problem can be solved optimally.
•Exhaustive search is exact but slow.
•Alternative algorithms provide faster solutions.
Vornoi diagram

• Partition plane with points into polygons.


• Each polygon has one generating point.
• Every point is closer to its generator.
• Voronoi diagram also called Dirichlet
tessellation.
• Cells are Dirichlet regions or Voronoi polygons.
• Thiessen polytopes represent each Voronoi
cell.
Principles of Voronoi Diagrams

• Generating points define the Voronoi diagram.


• Voronoi cells contain points closer to
generators.
• Edges are equidistant from two points.
• Each cell corresponds to one generating point.
• Cells share boundaries with neighbouring
regions.
• Diagram partitions space based on proximity.
Algorithm

• Initialize the Grid


• Iterate Through Each Grid Point
• Distance Calculation
• Assign the Grid Point to the Nearest Seed
• Repeat for All Points in the Grid
• Output the Voronoi Diagram
Advantages

• Efficient Spatial Partitioning


• Natural Representation of Proximity
• Simplicity
• Flexibility
Challenges

• Computational Complexity
• Non-Uniformity in Complex Spaces
• Boundary Issues
• Limited to Point-Based Analysis
• Sensitivity to Point Distribution
Applications
Naiva String-Matching Algorithm

• Naive algorithm finds pattern in text.


• Compares pattern at all possible positions.
• Checks each character of the text sequentially.
• Simple to implement and understand.
• Inefficient for large texts or patterns.
• Best for small-scale or simple tasks.
Algorithm

• Input text and pattern strings.


• Loop through each position in text.
• Compare substring with the pattern
characters.
• If match, return the position of match.
• If no match, move to next position.
• Repeat until the end of text.
• Example:
• Text: T="abcabcabc“
• Pattern: P="abc“
• Matches:
• Pattern P is found at positions 0, 3, and 6 in
the text.
Time Complexity:

• Best case: O(n)


• Worst case: O(nm)
Pros and Cons:

• Pros: Simple to implement and understand.


• Cons: Inefficient for large texts or patterns,
especially when there are many characters to
compare.
Applications

You might also like