代码随想录算法训练营第56天 | 图论理论基础 、深搜理论基础、98. 所有可达路径、广搜理论基础

图论理论基础 今天主要是理论

大家可以在看图论理论基础的时候,很多内容 看不懂,例如也不知道 看完之后 还是不知道 邻接矩阵,邻接表怎么用, 别着急。

理论基础大家先对各个概念有个印象就好,后面在刷题的过程中,每个知识点都会得到巩固。
https://www.programmercarl.com/kamacoder/图论理论基础.html

深搜理论基础
了解一下深搜的原理和过程
https://www.programmercarl.com/kamacoder/图论深搜理论基础.html

  1. 所有可达路径
    https://www.programmercarl.com/kamacoder/0098.所有可达路径.html
/**
 * @param {number[][]} graph
 * @return {number[][]}
 */
var allPathsSourceTarget = function(graph) {
    const len = graph.length;
    const res = [];
    const path = [0];
    const dfs = (graph, j) => {
        if (j === len - 1) {
            res.push([...path]);
            return;
        }
        const item = graph[j];
        for (let i=0;i<item.length;i++) {
            path.push(item[i]);
            dfs(graph, item[i]);
            path.pop();
        }
    }
    dfs(graph, 0);
    return res;
};

广搜理论基础
https://www.programmercarl.com/kamacoder/图论广搜理论基础.html

posted @ 2024-07-09 23:38  YuanYF6  阅读(1)  评论(0编辑  收藏  举报