What are the 10 algorithms one must know in order to solve most algorithm challenges/puzzles?

QUESTION :

ANSWER:

Dynamic Programming (DP) appears to account for a plurality (some estimate up to a third) of contest problems. Of course, DP is also not a single algorithm that you can just learn once and retain, so maybe this doesn‘t answer your question.

I suppose it also depends on whether you consider data structures in the same category as algorithms. There are certainly some data structures that you should be familiar with if you want to do well in programming competitions. The most important ones are range trees (variously known as interval trees or segment trees) and binary indexed trees (BITs), also known as Fenwick trees. Additionally, many DP algorithms make use of a prefix sum array.

The most essential of the single algorithms I can think of are the following, in no particular order. However, you may be disappointed by how rarely some of these actually appear in contests. Most non-DP problems appear to be of the "ad hoc with data structures" variety, and you simply have to practice in order to get good at them.

(To be clear, again, I list below only algorithms that take a single input set, compute some function of it, and carry no state between inputs. This distinguishes them from data structures, which by definition hold state, and categories of algorithms and algorithmic techniques like DP, which don‘t have some specific function they compute.)

    • Sieve of Eratosthenes, or another prime number sieve
    • Depth-first search
    • Breadth-first search
    • Dijkstra‘s algorithm
    • Floyd--Warshall algorithm
    • Either Kruskal‘s or Prim‘s algorithm
    • Some implementation of topological sorting, such as by using DFS
    • Convex hull (I recommend the Monotone Chains algorithm)
    • Coordinate compression
    • Edmonds--Karp, or another implementation of the Ford--Fulkerson method; or a preflow-push algorithm; or, if you are preparing an ACM codebook, Dinic‘s algorithm. (Note: Max flow is not allowed to appear on the IOI, but may nevertheless appear on national team-selection contests)

-- By Brian Bi

Excerpt from :https://www.quora.com/What-are-the-10-algorithms-one-must-know-in-order-to-solve-most-algorithm-challenges-puzzles

时间: 2024-12-30 02:21:05

What are the 10 algorithms one must know in order to solve most algorithm challenges/puzzles?的相关文章

Top 10 Algorithms of 20th and 21st Century

Top 10 Algorithms of 20th and 21st Century MATH 595 (Section TTA) Fall 2014 TR 2:00 pm - 3:20 pm, Room 341 Altgeld HallUniversity of Illinois at Urbana-Champaign, Department of Mathematics Instructors : Yuliy Baryshnikov and Anil N. Hirani Schedule:I

机器学习算法之旅A Tour of Machine Learning Algorithms

In this post we take a tour of the most popular machine learning algorithms. It is useful to tour the main algorithms in the field to get a feeling of what methods are available. There are so many algorithms available and it can feel overwhelming whe

二十世纪最伟大的10大算法

The Best of the 20th Century: Editors Name Top 10 Algorithms [http://www.uta.edu/faculty/rcli/TopTen/topten.pdf] 译文见:细数二十世纪最伟大的10大算法

Basic Sort Algorithms

1. Bubble Sort public void bubbleSort(int[] arr) { boolean swapped = true; int j = 0; int tmp; while (swapped) { swapped = false; j++; for (int i = 0; i < arr.length - j; i++) { if (arr[i] > arr[i + 1]) { tmp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1

IEEEXtreme 10.0 - Goldbach&#39;s Second Conjecture

这是 meelo 原创的 IEEEXtreme极限编程大赛题解 Xtreme 10.0 - Goldbach's Second Conjecture 题目来源 第10届IEEE极限编程大赛 https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/goldbachs-second-conjecture An integer p > 1 is called a prime if its only divisors ar

&quot;Insufficient RAM for Flash Algorithms&quot;出错原因及解决方案

"Insufficient RAM for Flash Algorithms"错误一般会有一个"cannot load flash programming algorithm !"的提示窗口,如下图: "Insufficient RAM for Flash Algorithms"从字面上解释是:"装载FLASH算法的RAM空间不足". 这个错误一般出现在添加了新的FLASH烧写算法以后. 原因:FLASH的烧写算法本身也相当于

关于CSS需要知道的10件事

原文: http://dsheiko.com/weblog/10-things-to-need-to-know-about-css CSS may look as a simple language. In fact it can be simple only to use, but definitely not simple to maintain. CSS看起来是个简单的语言,实际上只是使用较为简单,但是很显然维护它并不简单. Observing that the maximum numbe

R语言-找出向量或矩阵中的最大10个数

一.向量 最大10的数的索引(位置),可先按降序排序,得到索引号,然后将前10个取出即可. 建议方法: order(x,decreasing=TRUE)[1:10] 过程详解: 1.测试数据x > x [1] 0.00 0.00 0.00 0.00 0.00 0.00 0.06 0.09 0.20 0.09 0.08 0.14 0.14 0.23 [15] 0.08 0.06 0.12 0.20 0.14 0.11 0.20 0.14 0.17 0.15 0.18 0.15 0.20 0.12

10.31 morning

NP(np)Time Limit:1000ms Memory Limit:64MB题目描述LYK 喜欢研究一些比较困难的问题,比如 np 问题.这次它又遇到一个棘手的 np 问题.问题是这个样子的:有两个数 n 和 p,求 n 的阶乘对 p 取模后的结果.LYK 觉得所有 np 问题都是没有多项式复杂度的算法的,所以它打算求助即将要参加 noip的你,帮帮 LYK 吧!输入格式(np.in)输入一行两个整数 n,p.输出格式(np.out)输出一行一个整数表示答案.输入样例3 4输出样例2数据范