编程语言
首页 > 编程语言> > 【算法图解】学习笔记

【算法图解】学习笔记

作者:互联网

一 、算法简介

1.1 二分查找

1.2 大O表示法


二、选择排序

2.1 数组与链表

2.2 选择排序


三、递归


四、快速排序

4.1 分而治之(D&C)

4.2 快速排序

4.3 再谈大O表示法


五、散列表

5.1 散列函数

5.2 散列表

5.3 装填因子


六、广度优先搜索

6.1 最短路径问题

6.2 广度优先搜索


七、狄克斯特拉算法

7.1 使用狄克斯特拉算法

7.2 术语

7.3 实现

graph = {}
graph["you"] = ["alice", "bob", "claire"]

graph["start"] = {}
graph["start"]["a"] = 6
graph["start"]["b"] = 2

graph["a"] = {}
graph["a"]["fin"] = 1
graph["b"] = {}
graph["b"]["a"] = 3
graph["b"]["fin"] = 5

graph["fin"] = {}

infinity = float("inf")

infinity = float("inf")
costs = {}
costs["a"] = 6
costs["b"] = 2
costs["fin"] = infinity

parents = {}
parents["a"] = "start"
parents["b"] = "start"
parents["fin"] = None

processed = []

def find_lowest_cost_node(costs):
    lowest_cost = float("inf")
    lowest_cost_node = None
    for node in costs:
        cost = costs[node]
        if cost < lowest_cost and node not in processed:
            lowest_cost = cost
            lowest_cost_node = node
    return lowest_cost_node

node = find_lowest_cost_node(costs)
while node is not None:
    cost = costs[node]
    neighbors = graph[node]
    for n in neighbors.keys():
        new_cost = cost + neighbors[n]
        if costs[n] > new_cost:
            costs[n] = new_cost
            parents[n] = node
    processed.append(node)
    node = find_lowest_cost_node(costs)

八、贪婪算法

8.1 教室调度问题

8.2 背包问题

8.3 集合覆盖问题

8.4 旅行商问题


九、K最近邻算法

9.1 创建推荐系统

9.2 机器学习

标签:node,graph,costs,笔记,列表,算法,cost,图解
来源: https://blog.csdn.net/qq_51283283/article/details/113865970