Top 10 Algorithms and Data Structures for Competitive Programming
Last Updated :
10 Sep, 2024
In this post, we will discuss Important top 10 algorithms and data structures for competitive coding.
Topics :
- Graph algorithms
- Dynamic programming
- Searching and Sorting:
- Number theory and Other Mathematical
- Geometrical and Network Flow Algorithms
- Data Structures

The links below cover most important algorithms and data structure topics:
Graph Algorithms
- Breadth First Search (BFS)
- Depth First Search (DFS)
- Shortest Path from source to all vertices **Dijkstra**
- Shortest Path from every vertex to every other vertex **Floyd Warshall**
- Minimum Spanning tree **Prim**
- Minimum Spanning tree **Kruskal**
- Topological Sort
- Johnson's algorithm
- Articulation Points (or Cut Vertices) in a Graph
- Bridges in a graph
All Graph Algorithms
Dynamic Programming
- Longest Common Subsequence
- Longest Increasing Subsequence
- Edit Distance
- Minimum Partition
- Ways to Cover a Distance
- Longest Path In Matrix
- Subset Sum Problem
- Optimal Strategy for a Game
- 0-1 Knapsack Problem
- Assembly Line Scheduling
All DP Algorithms
Searching And Sorting
- Binary Search
- Quick Sort
- Merge Sort
- Order Statistics
- KMP algorithm
- Rabin karp
- Z's algorithm
- Aho Corasick String Matching
- Counting Sort
- Manacher's algorithm: Part 1, Part 2 and Part 3
All Articles on Searching, Sorting and Pattern Searching.
Number theory and Other Mathematical
Prime Numbers and Prime Factorization
- Primality Test | Set 1 (Introduction and School Method)
- Primality Test | Set 2 (Fermat Method)
- Primality Test | Set 3 (Miller–Rabin)
- Sieve of Eratosthenes
- Segmented Sieve
- Wilson’s Theorem
- Prime Factorization
- Pollard's rho algorithm
Modulo Arithmetic Algorithms
- Basic and Extended Euclidean algorithms
- Euler’s Totient Function
- Modular Exponentiation
- Modular Multiplicative Inverse
- Chinese remainder theorem Introduction
- Chinese remainder theorem and Modulo Inverse Implementation
- nCr%m and this.
Miscellaneous:
- Counting Inversions
- Counting Inversions using BIT
- logarithmic exponentiation
- Square root of an integer
- Heavy light Decomposition , this and this
- Matrix Rank
- Gaussian Elimination to Solve Linear Equations
- Hungarian algorithm
- Link cut
- Mo's algorithm and this
- Factorial of a large number in C++
- Factorial of a large number in Java+
- Russian Peasant Multiplication
- Catalan Number
All Articles on Mathematical Algorithms
Geometrical and Network Flow Algorithms
- Convex Hull
- Graham Scan
- Line Intersection
- Interval Tree
- Matrix Exponentiation and this
- Maxflow Ford Furkerson Algo and Edmond Karp Implementation
- Min cut
- Stable Marriage Problem
- Hopcroft–Karp Algorithm for Maximum Matching
- Dinic's algo and e-maxx
All Articles on Geometric Algorithms
Data Structures
- Binary Indexed Tree or Fenwick tree
- Segment Tree (RMQ, Range Sum and Lazy Propagation)
- K-D tree (See insert, minimum and delete)
- Union Find Disjoint Set (Cycle Detection and By Rank and Path Compression)
- Tries
- Suffix array (this, this and this)
- Sparse table
- Suffix automata
- Suffix automata II
- LCA and RMQ
All Articles on Advanced Data Structures.
How to Begin?
Please see How to begin with Competitive Programming?
How to Practice?
Please see https://practice.geeksforgeeks.org/
What are top algorithms in Interview Questions?
Top 10 algorithms in Interview Questions
How to prepare for ACM – ICPC?
How to prepare for ACM – ICPC?
This is an initial draft. We will soon be adding more links and algorithms to this post.
The biggest mistake programmers make is probably getting discouraged and not practicing enough. Or practicing only on problems they feel they're good at. - Derek Kisman, aka SnapDragon
Related Courses
Taking the first step is always hard, isn’t it? But we say no, why? Because we’ve brought a course that will help you to top the charts of leading coding competitions and interviews. Great right? You can start your journey of being a Competitive Programmer now, but before you start know the basics of Data structures and algorithms and programming foundations. Enroll Today, we'll see you inside the course.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
min 4 words, max Words Limit:1000
Thank You!
Your suggestions are valuable to us.
');
// $('.spinner-loading-overlay').show();
let script = document.createElement('script');
script.src = 'https://assets.geeksforgeeks.org/v2/editor-prod/static/js/bundle.min.js';
script.defer = true
document.head.appendChild(script);
script.onload = function() {
suggestionModalEditor() //to add editor in suggestion modal
if(loginData && loginData.premiumConsent){
personalNoteEditor() //to load editor in personal note
}
}
script.onerror = function() {
if($('.editorError').length){
$('.editorError').remove();
}
var messageDiv = $('
').text('Editor not loaded due to some issues');
$('#suggestion-section-textarea').append(messageDiv);
$('.suggest-bottom-btn').hide();
$('.suggestion-section').hide();
editorLoaded = false;
}
});
//suggestion modal editor
function suggestionModalEditor(){
// editor params
const params = {
data: undefined,
plugins: ["BOLD", "ITALIC", "UNDERLINE", "PREBLOCK"],
}
// loading editor
try {
suggestEditorInstance = new GFGEditorWrapper("suggestion-section-textarea", params, { appNode: true })
suggestEditorInstance._createEditor("")
$('.spinner-loading-overlay:eq(0)').remove();
editorLoaded = true;
}
catch (error) {
$('.spinner-loading-overlay:eq(0)').remove();
editorLoaded = false;
}
}
//personal note editor
function personalNoteEditor(){
// editor params
const params = {
data: undefined,
plugins: ["UNDO", "REDO", "BOLD", "ITALIC", "NUMBERED_LIST", "BULLET_LIST", "TEXTALIGNMENTDROPDOWN"],
placeholderText: "Description to be......",
}
// loading editor
try {
let notesEditorInstance = new GFGEditorWrapper("pn-editor", params, { appNode: true })
notesEditorInstance._createEditor(loginData&&loginData.user_personal_note?loginData.user_personal_note:"")
$('.spinner-loading-overlay:eq(0)').remove();
editorLoaded = true;
}
catch (error) {
$('.spinner-loading-overlay:eq(0)').remove();
editorLoaded = false;
}
}
var lockedCasesHtml = `
You can suggest the changes for now and it will be under 'My Suggestions' Tab on Write.You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!`;
var badgesRequiredHtml = `
It seems that you do not meet the eligibility criteria to create improvements for this article, as only users who have earned specific badges are permitted to do so.However, you can still create improvements through the Pick for Improvement section.`;
jQuery('.improve-header-sec-child').on('click', function(){
jQuery('.improve-modal--overlay').hide();
$('.improve-modal--suggestion').hide();
jQuery('#suggestion-modal-alert').hide();
});
$('.suggest-change_wrapper, .locked-status--impove-modal .improve-bottom-btn').on('click',function(){ // when suggest changes option is clicked
$('.ContentEditable__root').text("");
$('.suggest-bottom-btn').html("Suggest changes");
$('.thank-you-message').css("display","none");
$('.improve-modal--improvement').hide();
$('.improve-modal--suggestion').show();
$('#suggestion-section-textarea').show();
jQuery('#suggestion-modal-alert').hide();
if(suggestEditorInstance !== null){
suggestEditorInstance.setEditorValue("");
}
$('.suggestion-section').css('display', 'block');
jQuery('.suggest-bottom-btn').css("display","block");
});
$('.create-improvement_wrapper').on('click',function(){ // when create improvement option clicked then improvement reason will be shown
if(loginData && loginData.isLoggedIn) {
$('body').append('
');
$('.spinner-loading-overlay').show();
jQuery.ajax({
url: writeApiUrl + 'create-improvement-post/?v=1',
type: "POST",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
xhrFields: {
withCredentials: true
},
data: JSON.stringify({
gfg_id: post_id
}),
success:function(result) {
$('.spinner-loading-overlay:eq(0)').remove();
$('.improve-modal--overlay').hide();
$('.unlocked-status--improve-modal-content').css("display","none");
$('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank');
$('.create-improvement-redirection-to-write')[0].click();
},
error:function(e) {
showErrorMessage(e.responseJSON,e.status)
},
});
}
else {
if(loginData && !loginData.isLoggedIn) {
$('.improve-modal--overlay').hide();
if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) {
$('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click();
}
return;
}
}
});
$('.left-arrow-icon_wrapper').on('click',function(){
if($('.improve-modal--suggestion').is(":visible"))
$('.improve-modal--suggestion').hide();
else{
}
$('.improve-modal--improvement').show();
});
const showErrorMessage = (result,statusCode) => {
if(!result)
return;
$('.spinner-loading-overlay:eq(0)').remove();
if(statusCode == 403) {
$('.improve-modal--improve-content.error-message').html(result.message);
jQuery('.improve-modal--overlay').show();
jQuery('.improve-modal--improvement').show();
$('.locked-status--impove-modal').css("display","block");
$('.unlocked-status--improve-modal-content').css("display","none");
$('.improve-modal--improvement').attr("status","locked");
return;
}
}
function suggestionCall() {
var editorValue = suggestEditorInstance.getValue();
var suggest_val = $(".ContentEditable__root").find("[data-lexical-text='true']").map(function() {
return $(this).text().trim();
}).get().join(' ');
suggest_val = suggest_val.replace(/\s+/g, ' ').trim();
var array_String= suggest_val.split(" ") //array of words
var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val();
var error_msg = false;
if(suggest_val != "" && array_String.length >=4){
if(editorValue.length <= 2000){
var payload = {
"gfg_post_id" : `${post_id}`,
"suggestion" : `${editorValue}`,
}
if(!loginData || !loginData.isLoggedIn) // User is not logged in
payload["g-recaptcha-token"] = gCaptchaToken
jQuery.ajax({
type:'post',
url: "https://apiwrite.geeksforgeeks.org/suggestions/auth/create/",
xhrFields: {
withCredentials: true
},
crossDomain: true,
contentType:'application/json',
data: JSON.stringify(payload),
success:function(data) {
if(!loginData || !loginData.isLoggedIn) {
grecaptcha.reset();
}
jQuery('.spinner-loading-overlay:eq(0)').remove();
jQuery('.suggest-bottom-btn').css("display","none");
$('#suggestion-section-textarea').hide()
$('.thank-you-message').css('display', 'flex');
$('.suggestion-section').css('display', 'none');
jQuery('#suggestion-modal-alert').hide();
},
error:function(data) {
if(!loginData || !loginData.isLoggedIn) {
grecaptcha.reset();
}
jQuery('.spinner-loading-overlay:eq(0)').remove();
jQuery('#suggestion-modal-alert').html("Something went wrong.");
jQuery('#suggestion-modal-alert').show();
error_msg = true;
}
});
}
else{
jQuery('.spinner-loading-overlay:eq(0)').remove();
jQuery('#suggestion-modal-alert').html("Minimum 4 Words and Maximum Words limit is 1000.");
jQuery('#suggestion-modal-alert').show();
jQuery('.ContentEditable__root').focus();
error_msg = true;
}
}
else{
jQuery('.spinner-loading-overlay:eq(0)').remove();
jQuery('#suggestion-modal-alert').html("Enter atleast four words !");
jQuery('#suggestion-modal-alert').show();
jQuery('.ContentEditable__root').focus();
error_msg = true;
}
if(error_msg){
setTimeout(() => {
jQuery('.ContentEditable__root').focus();
jQuery('#suggestion-modal-alert').hide();
}, 3000);
}
}
document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){
jQuery('body').append('
');
jQuery('.spinner-loading-overlay').show();
if(loginData && loginData.isLoggedIn) {
suggestionCall();
return;
}
// script for grecaptcha loaded in loginmodal.html and call function to set the token
setGoogleRecaptcha();
});
$('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked
$('body').append('
');
$('.spinner-loading-overlay').show();
// send this option via create-improvement-post api
jQuery.ajax({
url: writeApiUrl + 'create-improvement-post/?v=1',
type: "POST",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
xhrFields: {
withCredentials: true
},
data: JSON.stringify({
gfg_id: post_id
}),
success:function(result) {
$('.spinner-loading-overlay:eq(0)').remove();
$('.improve-modal--overlay').hide();
$('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank');
$('.create-improvement-redirection-to-write')[0].click();
},
error:function(e) {
showErrorMessage(e.responseJSON,e.status);
},
});
});
"For an ad-free experience and exclusive features, subscribe to our Premium Plan!"