• [Algorithm] BFS vs DFS


    //If you know a solution is not far from the root of the tree:
    BFS, because it is faster to get closer node
    
    //If the tree is very deep and solutions are rare: 
    BFS, DFS will take a longer time because of the deepth of the tree
    
    //If the tree is very wide:
    DFS, for the worse cases, both BFS and DFS time complexity is O(N).
    But for the space complexity, DFS is O(H), where H is the height of the tree
    BFS space complexity is O(W), where W is the width of the tree
    As we know tree is very wide, W > H, so we choose DFS
    
    //If solutions are frequent but located deep in the tree:
    DFS, because we can find the node quickly
    
    //Determining whether a path exists between two nodes:
    DFS, it is good to check a path exists
    
    //Finding the shortest path:
    BFS, it is good to find shortest path
  • 相关阅读:
    PG-日常管理
    PG-高可用(pgpool-Ⅱ)
    PG-基准测试
    PG-备份恢复
    PG-并发问题
    Go-常量
    Go-变量
    Oracle-11g升级PSU补丁
    Oracle-`sqlplus`工具使用技巧
    [CF1051F] The Shortest Statement
  • 原文地址:https://www.cnblogs.com/Answer1215/p/11958668.html
Copyright © 2020-2023  润新知