Download presentation
Presentation is loading. Please wait.
1
Principles of Computing – UFCFA3-30-1
Week-14 Instructor : Mazhar H Malik Global College of Engineering and Technology
2
Time and Space Complexity AND
Shortest Path Finding Algorithms
3
Classes of Algorithms Simple recursive algorithms.
Backtracking algorithms. Divide and conquer algorithms. Dynamic programming algorithms. Greedy algorithms. Evolutionary algorithms. Randomized algorithms.
4
Problem Formulation - Romania
Start Finish
5
Problem Formulation - Romania
Initial State Arad Goal State Bucharest Operator o driving between cities o state space consists of all 20 cities in the graph Goal Test o is the current state Bucharest? o a solution is a path from the initial to the goal state Path cost is a function of time/distance/risk/petrol/…
6
Uninformed Search Strategies
Uninformed strategies use only the information available in the problem definition, Also known as blind searching Breadth-first search Uniform-cost search Depth-first search Depth-limited search Iterative deepening search
7
Comparing Uninformed Search Strategies
Completeness Will a solution always be found if one exists? Time How long does it take to find the solution? Often represented as the number of nodes searched Space How much memory is needed to perform the search? Often represented as the maximum number of nodes stored at once Optimal Will the optimal (least cost) solution be found?
8
Comparing Uninformed Search Strategies
Time and space complexity are measured in b – maximum branching factor of the search tree m – maximum depth of the state space d – depth of the least cost solution AI: Chapter 3: Solving Problems by Searching 7
9
Breadth-First Search Recall from Data Structures the basic
algorithm for a breadth-first search on a graph or tree Expand the shallowest unexpanded node Place all new successors at the end of a FIFO queue
10
Breadth-First Search
11
Breadth-First Search
12
Breadth-First Search
13
Breadth-First Search
14
Properties of Breadth-First Search
Complete Yes if b (max branching factor) is finite Time – 1 + b + b2 + … + bd = O(bd) exponential in d Space O(bd) Keeps every node in memory This is the big problem; an agent that generates nodes at 10 MB/sec will produce 860 MB in 24 hours Optimal Yes (if cost is 1 per step); not optimal in general
15
Properties of Breadth-First Search
16
Breadth First Search outcome
The memory requirements are a breadth-first search bigger than is problem for execution time Exponential-complexity search problems cannot be solved by uniformed methods for any but the smallest instances
17
Depth-First Search Recall from Data Structures the basic algorithm for a depth-first search on a graph or tree Expand the deepest unexpanded node Unexplored successors are placed on a stack until fully explored
18
Depth-First Search
19
Depth-First Search
20
Depth-First Search
21
Depth-First Search
22
Depth-First Search
23
Depth-First Search
24
Depth-First Search
25
Depth-First Search
26
Depth-First Search
27
Depth-First Search
28
Depth-First Search
29
Depth-First Search
30
Depth-First Search Complete Time Space Optimal
No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated spaces along path Yes: in finite spaces Time O(bm) Not great if m is much larger than d But if the solutions are dense, this may be faster than breadth-first search Space O(bm)…linear space Optimal No
31
Depth-Limited Search A variation of depth-first search that uses a depth limit Alleviates the problem of unbounded trees Search to a predetermined depth l (“ell”) Nodes at depth l have no successors Same as depth-first search if l = ∞ Can terminate for failure and cutoff
32
Depth-Limited Search
33
Depth-Limited Search Complete Time Space Optimal Yes if l = d O(bl)
No if l = d
34
Summery
35
NP Complete Problem The list below contains some well-known problems that are NP-complete when expressed as decision problems. Boolean satisfiability problem (SAT) Knapsack problem. Hamiltonian path problem. Travelling salesman problem (decision version) Subgraph isomorphism problem. Subset sum problem. Clique problem. Vertex cover problem.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.