Hướng dẫn informed search python code - thông báo tìm kiếm mã python

Cải thiện bài viết

Show

Lưu bài viết

  • Đọc
  • Bàn luận
  • Cải thiện bài viết

    Lưu bài viết

    Đọc

    Bàn luậnBest First Search is to use an evaluation function to decide which adjacent is most promising and then explore.

    Trong BFS và DFS, khi chúng ta ở một nút, chúng ta có thể xem xét bất kỳ loại liền kề nào là nút tiếp theo. Vì vậy, cả BFS và DFS khám phá một cách mù quáng các đường dẫn mà không xem xét bất kỳ chức năng chi phí nào. & NBSP;

    Ý tưởng về tìm kiếm đầu tiên tốt nhất là sử dụng một chức năng đánh giá để quyết định xem liền kề nào là hứa hẹn nhất và sau đó khám phá.

    Tìm kiếm đầu tiên tốt nhất thuộc danh mục tìm kiếm heuristic hoặc tìm kiếm được thông báo.

    // Pseudocode for Best First Search
    Best-First-Search(Graph g, Node start)
        1) Create an empty PriorityQueue
           PriorityQueue pq;
        2) Insert "start" in pq.
           pq.insert(start)
        3) Until PriorityQueue is empty
              u = PriorityQueue.DeleteMin
              If u is the goal
                 Exit
              Else
                 Foreach neighbor v of u
                    If v "Unvisited"
                        Mark v "Visited"                    
                        pq.insert(v)
                 Mark u "Examined"                    
    End procedure

    Illustration:

    Thực hiện tìm kiếm đầu tiên tốt nhất:

    Hướng dẫn informed search python code - thông báo tìm kiếm mã python

    • Chúng tôi sử dụng hàng đợi ưu tiên hoặc đống để lưu trữ các chi phí của các nút có giá trị chức năng đánh giá thấp nhất. Vì vậy, việc thực hiện là một biến thể của BFS, chúng ta chỉ cần thay đổi hàng đợi thành ưu tiên. & NBSP;
       
    • Hãy để chúng tôi xem xét ví dụ dưới đây:
      • Chúng tôi bắt đầu từ Nguồn S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S Sh.
      • PQ ban đầu chứa s
         
    • Chúng tôi loại bỏ S khỏi và xử lý các hàng xóm không liên quan đến S đến PQ.
      • PQ hiện chứa {a, c, b} (c được đặt trước b vì c có chi phí thấp hơn) & nbsp;
         
    • Chúng tôi loại bỏ một từ PQ và xử lý các hàng xóm không được xác nhận của A đến PQ.
      • pq hiện chứa {c, b, e, d} & nbsp;
         
    • Chúng tôi loại bỏ C khỏi PQ và xử lý các hàng xóm không liên quan của C đến PQ.
      • PQ hiện chứa {b, h, e, d} & nbsp;
    • Chúng tôi loại bỏ B khỏi PQ và xử lý các hàng xóm không liên quan của B đến PQ.
    • PQ hiện chứa {h, e, d, f, g}

    Chúng tôi loại bỏ H khỏi PQ. & nbsp;

    C++

    #include <bits/stdc++.h>

    Vì mục tiêu của chúng tôi, tôi là một người hàng xóm của H, chúng tôi trở lại.

    Dưới đây là việc thực hiện ý tưởng trên:

    #include <bits/stdc++.h>1

    using namespace std;

    using0

    using1using2

    using1using4

    using5

    using0

    using1namespace6namespace7namespace8namespace9std;0

    using1std;2

    using1std;4

    #include <bits/stdc++.h>2 #include <bits/stdc++.h>3int #include <bits/stdc++.h>5int #include <bits/stdc++.h>7______

    using1std;9typedef0typedef1

    #include <bits/stdc++.h>2 using7int using9int namespace1int namespace3

    using1int std;7

    typedef5typedef9pair<0typedef1

    typedef5pair<3

    using1typedef3 typedef4

    pair<7pair<8typedef1

    typedef5int typedef7

    typedef5pair<5 pair<6

    int8int9typedef0typedef1

    int8, 3

    pair<7using5

    typedef5using5

    typedef5int1 int2int int4

    using5

    pair<7pair<5 int7

    using0

    using1using5

    using1int8

    using1#include <bits/stdc++.h>00

    using1#include <bits/stdc++.h>02

    using1#include <bits/stdc++.h>04

    using1#include <bits/stdc++.h>06

    using1#include <bits/stdc++.h>08

    using1#include <bits/stdc++.h>10

    using1#include <bits/stdc++.h>12

    using1#include <bits/stdc++.h>14

    using1#include <bits/stdc++.h>16

    using1#include <bits/stdc++.h>18

    using1#include <bits/stdc++.h>20

    using1#include <bits/stdc++.h>22

    using1#include <bits/stdc++.h>24

    int int2

    using1int int6

    using1#include <bits/stdc++.h>32

    using1int #include <bits/stdc++.h>27

    using5

    using1int #include <bits/stdc++.h>30

    using1#include <bits/stdc++.h>34 #include <bits/stdc++.h>35

    Java

    #include <bits/stdc++.h>37 #include <bits/stdc++.h>38

    using0

    #include <bits/stdc++.h>37 #include <bits/stdc++.h>40

    #include <bits/stdc++.h>41 #include <bits/stdc++.h>42

    #include <bits/stdc++.h>44using0

    #include <bits/stdc++.h>44#include <bits/stdc++.h>45 #include <bits/stdc++.h>46#include <bits/stdc++.h>47 #include <bits/stdc++.h>48

    #include <bits/stdc++.h>44#include <bits/stdc++.h>45 #include <bits/stdc++.h>41 #include <bits/stdc++.h>52#include <bits/stdc++.h>53 #include <bits/stdc++.h>54

    using1using0

    #include <bits/stdc++.h>68#include <bits/stdc++.h>69#include <bits/stdc++.h>70

    #include <bits/stdc++.h>68#include <bits/stdc++.h>69#include <bits/stdc++.h>73

    typedef5int1 int2int int4

    pair<7pair<5 int7

    using1using0

    using1using5

    int int2

    #include <bits/stdc++.h>68using5

    #include <bits/stdc++.h>68#include <bits/stdc++.h>93

    using1int int6

    using1using5

    #include <bits/stdc++.h>44using5

    using1int #include <bits/stdc++.h>27

    #include <bits/stdc++.h>44using0

    using1int #include <bits/stdc++.h>30

    using1#include <bits/stdc++.h>34 #include <bits/stdc++.h>35

    using1using5

    Java

    #include <bits/stdc++.h>37 #include <bits/stdc++.h>38

    #include <bits/stdc++.h>44using0

    #include <bits/stdc++.h>37 #include <bits/stdc++.h>40

    #include <bits/stdc++.h>41 #include <bits/stdc++.h>42

    using1using48typedef0typedef1

    #include <bits/stdc++.h>44#include <bits/stdc++.h>45 #include <bits/stdc++.h>46#include <bits/stdc++.h>47 #include <bits/stdc++.h>48

    #include <bits/stdc++.h>44#include <bits/stdc++.h>45 #include <bits/stdc++.h>41 #include <bits/stdc++.h>52#include <bits/stdc++.h>53 #include <bits/stdc++.h>54

    using1int #include <bits/stdc++.h>59

    #include <bits/stdc++.h>68using64pair<0std;0

    using1#include <bits/stdc++.h>61int #include <bits/stdc++.h>63int #include <bits/stdc++.h>9

    typedef5pair<8typedef1

    #include <bits/stdc++.h>68using5

    using1#include <bits/stdc++.h>77 #include <bits/stdc++.h>78 int #include <bits/stdc++.h>80

    #include <bits/stdc++.h>68pair<5 #include <bits/stdc++.h>85

    using81using82typedef0typedef1

    using81using86

    typedef5using5

    #include <bits/stdc++.h>68using5

    using1using5

    #include <bits/stdc++.h>44using5

    typedef5#include <bits/stdc++.h>34 #include <bits/stdc++.h>88typedef1

    #include <bits/stdc++.h>44using0

    using1namespace07#include <bits/stdc++.h>47 namespace09

    using1namespace11#include <bits/stdc++.h>47 namespace13

    #include <bits/stdc++.h>44using5

    #include <bits/stdc++.h>44#include <bits/stdc++.h>78 #include <bits/stdc++.h>45 #include <bits/stdc++.h>2 namespace20

    #include <bits/stdc++.h>44using0

    using1int namespace25namespace26typedef1

    using1namespace29#include <bits/stdc++.h>47 namespace31

    using1namespace33using15, #include <bits/stdc++.h>88, namespace38std;0

    using1namespace33using15, namespace44, namespace46std;0

    using1namespace33using15, namespace38, namespace54std;0

    using1namespace33#include <bits/stdc++.h>88, namespace60, namespace62std;0

    using1namespace33#include <bits/stdc++.h>88, namespace54, namespace70std;0

    Các

    using1namespace33namespace44, namespace84, namespace26std;0

    using1namespace33namespace38, namespace70, namespace84std;0

    using1namespace33namespace70, namespace62, namespace54std;0

    using1namespace33namespace70, std;08, namespace46std;0

    using1namespace33namespace62, std;16, #include <bits/stdc++.h>88std;0

    using1namespace33namespace62, namespace78, std;08std;0

    using1namespace33namespace62, std;32, namespace44std;0

    using1int std;38using15typedef1

    using1int std;43namespace62typedef1

    using1#include <bits/stdc++.h>32

    #include <bits/stdc++.h>44using5

    using5

    Python3

    std;51 std;52#include <bits/stdc++.h>37 std;54

    std;55std;56 namespace26

    std;58std;56 std;60int1 std;62std;63

    std;66 std;67

    using1std;69std;56 std;71std;72std;73std;74 std;75

    using1std;777____456 std;79

    using1std;81using15std;83

    using1std;85std;56 std;87

    using1typedef3 std;90std;56std;56 std;72std;94

    typedef5std;96std;56 std;98#include <bits/stdc++.h>88typedef00

    typedef5typedef02typedef03std;56pair<0typedef06

    typedef5pair<5 std;96std;56std;56 typedef12

    pair<7pair<8

    typedef5int1 typedef17std;63 typedef19

    pair<7pair<5 typedef222std;56std;56 std;72std;94

    int8typedef22222456 std;87

    int8typedef32

    using1typedef022

    std;66 typedef37

    using1typedef39

    using1typedef41

    #include <bits/stdc++.h>3using15, #include <bits/stdc++.h>88, namespace38typedef06

    #include <bits/stdc++.h>3using15, namespace44, namespace46typedef06

    #include <bits/stdc++.h>3using15, namespace38, namespace54typedef06

    #include <bits/stdc++.h>3#include <bits/stdc++.h>88, namespace60, namespace62typedef06

    #include <bits/stdc++.h>3#include <bits/stdc++.h>88, namespace54, namespace70typedef06

    #include <bits/stdc++.h>3namespace44, namespace46, namespace78typedef06

    Các

    #include <bits/stdc++.h>3namespace38, namespace70, namespace84typedef06

    #include <bits/stdc++.h>3namespace70, namespace62, namespace54typedef06

    #include <bits/stdc++.h>3namespace70, std;08, namespace46typedef06

    #include <bits/stdc++.h>3namespace62, std;16, #include <bits/stdc++.h>88typedef06

    #include <bits/stdc++.h>3namespace62, namespace78, std;08typedef06

    #include <bits/stdc++.h>3namespace62, std;32, namespace44typedef06

    pair<33std;56 using15

    pair<36std;56 namespace62

    pair<39

    Phân tích: & NBSP; 

    • Độ phức tạp thời gian trong trường hợp xấu nhất cho tìm kiếm đầu tiên tốt nhất là O (N * log n) trong đó n là số lượng nút. Trong trường hợp xấu nhất, chúng ta có thể phải ghé thăm tất cả các nút trước khi đạt được mục tiêu. Lưu ý rằng hàng đợi ưu tiên được triển khai bằng đống tối thiểu (hoặc tối đa) và chèn và xóa các hoạt động mất thời gian O (log n).
    • Hiệu suất của thuật toán phụ thuộc vào mức độ chi phí hoặc chức năng đánh giá được thiết kế.

    Các trường hợp đặc biệt của tìm kiếm đầu tiên tốt nhất:

    1. Thuật toán tìm kiếm đầu tiên tốt nhất
    2. Một thuật toán tìm kiếm

    Bài viết này được đóng góp bởi Shambhavi Singh. Nếu bạn thích GeekSforGeeks và muốn đóng góp, bạn cũng có thể viết một bài viết bằng Write.GeekSforGeek.org hoặc gửi bài viết của bạn. Xem bài viết của bạn xuất hiện trên trang chính của GeekSforGeek và giúp các chuyên viên máy tính khác. & NBSP;Shambhavi Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.