Algorithm Definition Reviews

本文详细介绍了算法中的分治策略,包括递归树和主定理的三个情况,以及如何根据这些理论计算问题的复杂度。此外,还探讨了图的搜索算法,如广度优先搜索和深度优先搜索,并阐述了它们在寻找最短路径中的应用。
摘要由CSDN通过智能技术生成

Divide and Conquer

They break the problem into several subproblems that are similar to the original problem but smaller in size, solve the subproblems recursively, and then combine these solutions to create a solution to the original problem.

Recursion Tree

In a recursion tree, each node represents the cost of a single subproblem somewhere in the set of recursive function invocations. We sum the costs within each level of the tree to obtain a set of per-level costs, and we sum all the per-level costs to determine the total cost of all levels of the recursion.

The master theorem

Let  be the constants, let  be a function, and let  be defined on the nonnegative integers by the recurrence


where we interpret n/b to mean either . Then  has the following asymptotic bounds:

  1. If  for some constant , then .
  2. If , then .
  3. If  for some constant , and if  for some constant  and all sufficiently large n, then .

In terms of the recursion tree, the three cases of the master theorem correspond to cases in which the total cost of the tree is (1) dominated by the costs in the leaves, (2) evenly distributed among the levels of the tree, or (3) dominated by the cost of the root.

Breadth-first search

Given a graph G=(V,E) and distinguished source vertex s, breadth-first search systematically explores the edges of G to "discover" every vertex that is reachable from s. It computes the distance (smallest number of edges) from s to each reachable vertex. It also produces a "breadth-first tree" with root s that contains all reachable vertices. For any vertex v reachable from s, the simple path in the breadth-first tree from s to v corresponds to a "shortest path" from s to v in G, that is, a path containing the smallest number of edges. The algorithm works on both directed and undirected graphs.

Depth-first search

Depth-first search explores edges out of the most recently discovered vertex v that still has unexplored edges leaving it. Once all of v's edges have been explored, the search "backtracks" to explore edges leaving the vertex from which v was discovered.

Shortest-path distance 

Define  from s to v as the minimum number of edges in any path from vertex s to vertex v; if there is no path from s to v, then . We call a path of length  from s to v ashortest path from s to v.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值