SlideShare a Scribd company logo
1 of 34
Advanced Artificial
Intelligence
MSCS 1
Lecture 5
Greedy search
• Greedy search is a variation of the A* algorithm, where g(node) is set
to zero, so that only h(node) is used to evaluate suitable paths. In this
way, the algorithm always selects the path that has the lowest
heuristic value or estimated distance (or cost) to the goal.
• Greedy search is an example of a best-first strategy.
• Greedy-search methods tend to be reasonably efficient, although in
the worst case, like depth-first search, it may never find a solution at
all.
Knapsack problem
• The knapsack problem is an interesting illustration of the use of
greedy search algorithms and their pitfalls. The fractional knapsack
problem can be expressed as follows:
• A man is packing items into his knapsack. He wants to take the most
valuable items he can, but there is a limit on how much weight he can
fit in his knapsack. Each item has a weight wi and is profit pi. He can
only fit a total weight of W in his knapsack.
Knapsack problem
• The items that he wants to take are things that can be broken up and still
retain their value (like flour or milk), and he is The items that he wants to
take are things that can be broken up and still retain their value (like flour
or milk), and he is able to take fractions of items. Hence, the problem is
called the fractional knapsack problem.
• In solving this problem, a greedy-search algorithm provides the best
solution.
• The problem is solved by calculating the value per unit weight of each item:
pi/wi, and then taking as much as he can carry of the item with the
greatest
value per unit weight. If he still has room, he moves on to the item with the
next highest value per unit weight, and so on.
Fractional Knapsack problem
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Items N = 7
Bag capacity M = 15
Fractional Knapsack problem
• Now we have a bag with capacity of 15. lets suppose 15 kg.
• Now we want to transfer this bag from one location to another.
• We are facing this problem in daily life.
• Now problem is to filling of the objects in a container.
• If you put all the objects in the bag with the capacity, there is no
problem.
• But the objects weight is more than the bag capacity, here the
problem start.
Fractional Knapsack problem
• We should maximize the profit.
• So this problem is optimization problem.
• Can we apply the greedy method to solve this problem?
• Yes, if it is suitable.
• So what are the constraints here?
• The bag capacity is 15, so all the objects which we want to transfer
should be <= 15.
Fractional Knapsack problem
• For this problem we have many solutions.
• The optimal result is to gain a maximum profit.
• X = {x1, x2, x3, x4, x5, x6, x7}
• We can say this problem is a fractional problem
• 0 ≤ X ≤ 1
Fractional Knapsack problem
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
• Items n = 7
• Bag capacity m = 15
Fractional Knapsack problem
• Profit of each item per kg is
• X1 = 5, x2=1.3, x3=3, x4=1, x5=6, x6=4.5, x7=3
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Items n = 7
Bag capacity m = 15
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Items n = 7
Bag capacity m = 15
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Fractional Knapsack problem
• Now we select the items on the basis of their profit
Objects 0 1 2 3 4 5 6 7
Profits p 10 5 15 7 6 18 3
Weights w 2 3 5 7 1 4 1
Max profit p/w 5 1.3 3 1 6 4.5 3
Items n = 7
Bag capacity m = 15
A* algorithm for searching
• Informed searching algorithm
• A* Search algorithm is one of the best and popular technique used in
path-finding and graph traversals.
• Informally speaking, A* Search algorithms, unlike other traversal
techniques, it has “brains”. What it means is that it is really a smart
algorithm which separates it from the other conventional algorithms.
• And it is also worth mentioning that many games and web-based
maps use this algorithm to find the shortest path very efficiently
(approximation).
A* algorithm for searching
• A* algorithms are similar to best-first search but use a somewhat
more complex heuristic to select a path through the tree. The best-
first algorithm always extends paths that involve moving to the node
that appears to be closest to the goal, but it does not take into
account the cost of the path to that node so far.
• The A* algorithm operates in the same manner as best-first search
but uses the following function to evaluate nodes:
• f(n) = g(n) + h(n)
A* algorithm for searching
• g(n)--- actual cost from start node to n.
• h(n)--- estimation cost from n to goal node.
A* algorithm for searching
• S is start node and G is goal node.
• A* is an admissible algorithm which mean that it will give an optimal
solution.
A* algorithm for searching
• We are taking a directed graph in this example. We also can take a
tree to solve this problem. From S to B, 4 is actual value and in red
color 12 is heuristic value.
A* algorithm for searching
• Explore S, SB, SC.
A* algorithm for searching
• We explore SCE, SCD, SBF, SBE
A* algorithm for searching
• We explore SCE, SCD, SBF, SBE
A* algorithm for searching
• We explore SCDEG
A* algorithm for searching
• Time complexity
• T(C) = O(v+E)
• In artificial intelligence point of view
• O(b^d)
• Where b is the branch factor, d is the depth.

More Related Content

What's hot

Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | EdurekaEdureka!
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structureSajid Marwat
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sJay Patel
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structureMAHALAKSHMI P
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structureVardhil Patel
 
Quick sort-170316064200
Quick sort-170316064200Quick sort-170316064200
Quick sort-170316064200ifeanyiokeke3
 
Knapsack problem dynamicprogramming
Knapsack problem dynamicprogrammingKnapsack problem dynamicprogramming
Knapsack problem dynamicprogrammingrowntu
 
Daa:Dynamic Programing
Daa:Dynamic ProgramingDaa:Dynamic Programing
Daa:Dynamic Programingrupali_2bonde
 
0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEMi i
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithmsSaga Valsalan
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Treezhaokatherine
 
Knapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmKnapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmHoneyChintal
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic ProgrammingFenil Shah
 

What's hot (20)

Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
Quick sort-170316064200
Quick sort-170316064200Quick sort-170316064200
Quick sort-170316064200
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
 
Knapsack problem dynamicprogramming
Knapsack problem dynamicprogrammingKnapsack problem dynamicprogramming
Knapsack problem dynamicprogramming
 
Daa:Dynamic Programing
Daa:Dynamic ProgramingDaa:Dynamic Programing
Daa:Dynamic Programing
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM0-1 KNAPSACK PROBLEM
0-1 KNAPSACK PROBLEM
 
Prims and kruskal algorithms
Prims and kruskal algorithmsPrims and kruskal algorithms
Prims and kruskal algorithms
 
Minimum Spanning Tree
Minimum Spanning TreeMinimum Spanning Tree
Minimum Spanning Tree
 
Merge sort
Merge sortMerge sort
Merge sort
 
Insertion Sort
Insertion SortInsertion Sort
Insertion Sort
 
Red black tree
Red black treeRed black tree
Red black tree
 
Knapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmKnapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithm
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming
 
Heap sort
Heap sort Heap sort
Heap sort
 
Binary search trees
Binary search treesBinary search trees
Binary search trees
 

Similar to AI Greedy Search and A* Algorithm Guide

Greedy method1
Greedy method1Greedy method1
Greedy method1Rajendran
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptRuchika Sinha
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptRuchika Sinha
 
Optimization problems
Optimization problemsOptimization problems
Optimization problemsRuchika Sinha
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfShiwani Gupta
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptdakccse
 
Solving 0-1 knapsack problems based on amoeboid organism algorithm
Solving 0-1 knapsack problems based on amoeboid organism algorithmSolving 0-1 knapsack problems based on amoeboid organism algorithm
Solving 0-1 knapsack problems based on amoeboid organism algorithmjuanjo_23
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptBinayakMukherjee4
 
Introduction to Optimization revised.ppt
Introduction to Optimization revised.pptIntroduction to Optimization revised.ppt
Introduction to Optimization revised.pptJahnaviGautam
 

Similar to AI Greedy Search and A* Algorithm Guide (20)

12 Greeddy Method
12 Greeddy Method12 Greeddy Method
12 Greeddy Method
 
Lec30
Lec30Lec30
Lec30
 
Greedy method1
Greedy method1Greedy method1
Greedy method1
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Fractional Knapsack Problem
Fractional Knapsack ProblemFractional Knapsack Problem
Fractional Knapsack Problem
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Greedy
GreedyGreedy
Greedy
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
 
module3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdfmodule3_Greedymethod_2022.pdf
module3_Greedymethod_2022.pdf
 
Knapsack algoritm
Knapsack algoritmKnapsack algoritm
Knapsack algoritm
 
Module 3_DAA (2).pptx
Module 3_DAA (2).pptxModule 3_DAA (2).pptx
Module 3_DAA (2).pptx
 
Mini project
Mini projectMini project
Mini project
 
Transportation technique
Transportation techniqueTransportation technique
Transportation technique
 
0/1Knapsack
0/1Knapsack0/1Knapsack
0/1Knapsack
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
 
Solving 0-1 knapsack problems based on amoeboid organism algorithm
Solving 0-1 knapsack problems based on amoeboid organism algorithmSolving 0-1 knapsack problems based on amoeboid organism algorithm
Solving 0-1 knapsack problems based on amoeboid organism algorithm
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
 
Introduction to Optimization revised.ppt
Introduction to Optimization revised.pptIntroduction to Optimization revised.ppt
Introduction to Optimization revised.ppt
 

More from Learning Courses Online

More from Learning Courses Online (6)

Convolutional neural networks
Convolutional neural  networksConvolutional neural  networks
Convolutional neural networks
 
Heap Sort || Heapify Method || Build Max Heap Algorithm
Heap Sort || Heapify Method || Build Max Heap AlgorithmHeap Sort || Heapify Method || Build Max Heap Algorithm
Heap Sort || Heapify Method || Build Max Heap Algorithm
 
Introduction to Hash Tables | What is a HashTable in Algorithm
Introduction to Hash Tables | What is a HashTable in AlgorithmIntroduction to Hash Tables | What is a HashTable in Algorithm
Introduction to Hash Tables | What is a HashTable in Algorithm
 
Binary tree data structure
Binary tree data structureBinary tree data structure
Binary tree data structure
 
8 queens problem using ga
8 queens problem using ga8 queens problem using ga
8 queens problem using ga
 
Simple auto encoder
Simple auto encoderSimple auto encoder
Simple auto encoder
 

Recently uploaded

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 

Recently uploaded (20)

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 

AI Greedy Search and A* Algorithm Guide

  • 2. Greedy search • Greedy search is a variation of the A* algorithm, where g(node) is set to zero, so that only h(node) is used to evaluate suitable paths. In this way, the algorithm always selects the path that has the lowest heuristic value or estimated distance (or cost) to the goal. • Greedy search is an example of a best-first strategy. • Greedy-search methods tend to be reasonably efficient, although in the worst case, like depth-first search, it may never find a solution at all.
  • 3. Knapsack problem • The knapsack problem is an interesting illustration of the use of greedy search algorithms and their pitfalls. The fractional knapsack problem can be expressed as follows: • A man is packing items into his knapsack. He wants to take the most valuable items he can, but there is a limit on how much weight he can fit in his knapsack. Each item has a weight wi and is profit pi. He can only fit a total weight of W in his knapsack.
  • 4. Knapsack problem • The items that he wants to take are things that can be broken up and still retain their value (like flour or milk), and he is The items that he wants to take are things that can be broken up and still retain their value (like flour or milk), and he is able to take fractions of items. Hence, the problem is called the fractional knapsack problem. • In solving this problem, a greedy-search algorithm provides the best solution. • The problem is solved by calculating the value per unit weight of each item: pi/wi, and then taking as much as he can carry of the item with the greatest value per unit weight. If he still has room, he moves on to the item with the next highest value per unit weight, and so on.
  • 5. Fractional Knapsack problem Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Items N = 7 Bag capacity M = 15
  • 6. Fractional Knapsack problem • Now we have a bag with capacity of 15. lets suppose 15 kg. • Now we want to transfer this bag from one location to another. • We are facing this problem in daily life. • Now problem is to filling of the objects in a container. • If you put all the objects in the bag with the capacity, there is no problem. • But the objects weight is more than the bag capacity, here the problem start.
  • 7. Fractional Knapsack problem • We should maximize the profit. • So this problem is optimization problem. • Can we apply the greedy method to solve this problem? • Yes, if it is suitable. • So what are the constraints here? • The bag capacity is 15, so all the objects which we want to transfer should be <= 15.
  • 8. Fractional Knapsack problem • For this problem we have many solutions. • The optimal result is to gain a maximum profit. • X = {x1, x2, x3, x4, x5, x6, x7} • We can say this problem is a fractional problem • 0 ≤ X ≤ 1
  • 9. Fractional Knapsack problem Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3 • Items n = 7 • Bag capacity m = 15
  • 10. Fractional Knapsack problem • Profit of each item per kg is • X1 = 5, x2=1.3, x3=3, x4=1, x5=6, x6=4.5, x7=3 Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3 Items n = 7 Bag capacity m = 15
  • 11. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3 Items n = 7 Bag capacity m = 15
  • 12. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 13. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 14. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 15. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 16. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 17. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 18. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 19. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 20. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 21. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 22. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 23. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3
  • 24. Fractional Knapsack problem • Now we select the items on the basis of their profit Objects 0 1 2 3 4 5 6 7 Profits p 10 5 15 7 6 18 3 Weights w 2 3 5 7 1 4 1 Max profit p/w 5 1.3 3 1 6 4.5 3 Items n = 7 Bag capacity m = 15
  • 25. A* algorithm for searching • Informed searching algorithm • A* Search algorithm is one of the best and popular technique used in path-finding and graph traversals. • Informally speaking, A* Search algorithms, unlike other traversal techniques, it has “brains”. What it means is that it is really a smart algorithm which separates it from the other conventional algorithms. • And it is also worth mentioning that many games and web-based maps use this algorithm to find the shortest path very efficiently (approximation).
  • 26. A* algorithm for searching • A* algorithms are similar to best-first search but use a somewhat more complex heuristic to select a path through the tree. The best- first algorithm always extends paths that involve moving to the node that appears to be closest to the goal, but it does not take into account the cost of the path to that node so far. • The A* algorithm operates in the same manner as best-first search but uses the following function to evaluate nodes: • f(n) = g(n) + h(n)
  • 27. A* algorithm for searching • g(n)--- actual cost from start node to n. • h(n)--- estimation cost from n to goal node.
  • 28. A* algorithm for searching • S is start node and G is goal node. • A* is an admissible algorithm which mean that it will give an optimal solution.
  • 29. A* algorithm for searching • We are taking a directed graph in this example. We also can take a tree to solve this problem. From S to B, 4 is actual value and in red color 12 is heuristic value.
  • 30. A* algorithm for searching • Explore S, SB, SC.
  • 31. A* algorithm for searching • We explore SCE, SCD, SBF, SBE
  • 32. A* algorithm for searching • We explore SCE, SCD, SBF, SBE
  • 33. A* algorithm for searching • We explore SCDEG
  • 34. A* algorithm for searching • Time complexity • T(C) = O(v+E) • In artificial intelligence point of view • O(b^d) • Where b is the branch factor, d is the depth.