Skip to content

nguyetdoan10/Awesome-Competitive-Programming

 
 

Repository files navigation

Awesome Competitive Programming Problems

This repository contains my implementation of useful / well-known data structures, algorithms and solutions for awesome competitive programming problems in Hackerrank, Project Euler and Leetcode

I create this for faster implementation and better preparation in interviews as well as programming contests :trollface: :trollface:

📆 Last updated on 06.04.2021 in Python 3 by Le Duc Khai

⚠️ This repo is day-by-day updated. Please make sure you have the latest version!

❓ How to use

  • : Useful / well-known data structures or algorithms

  • : Solutions for some awesome competitive programming problems

Mathematics : Type of the Algorithm

Permutation Problems : Category of the Problem

Lexicographic Permutations : Name of the problem

Awesome-Competitive-Programming 
│   README.md 
│
└───Folder 1        : Type of Algorithm 
│   │   File1.ipynb : Python codes for the problem
│   │   ...   
│   
└───Folder 2
│   │   File2.ipynb
│   │   ...
│     
└───Folder Data Bank: Descriptions and Solution Guides for the Problem 
│   │   File1.pdf
│   │   ...
│
└───...    

🍉 Algorithms

A) Data Structures Applications

🌴 Binary Search Tree Algorithm

B) String Algorithm

🌾 Suffix Tree - Suffix Array

    • Longest Palindromic Substring - (O(n)) (Đang cập nhật)
    • Pattern Search - O(log(n)) (Đang cập nhật)

C) Searching and Graph Algorithms

❄️ Graph Theory

    • Graph Representation using Adjacency List: Weighted, Un-/Directed (Đang cập nhật)
    • Find All Nodes: Find All Nodes in the Unweighted Graph - O(V+E) for Adjacency List , V, E is the number of vertices and edges
    • Find All Edges (Đang cập nhật)

♻️ Detect Cycle

    • Detect Cycle: Disjoint Set: Detect Cycle in an Undirected Graph based on Disjoint Set (Union-Find) using "Union by Rank and Path Compression" - O(V)

✈️ Graph Traversal

    • Breadth-First Search: Find BFS Path from a Starting Node in Un-/Directed Graph - O(V+E) for Adjacency List; O(V2) for Adjacency Matrix , V, E is the number of vertices and edges
    • Depth-First Search: Find DFS Path from a Starting Node in Un-/Directed Graph - O(V+E) for Adjacency List; O(V2) for Adjacency Matrix , V, E is the number of vertices and edges

☘️ Minimum Spanning Tree (MST)

    • MST: Kruskal Algorithm[PDF]: Find Minimum Spanning Tree (MST) of an Undirected Graph using Kruskal Algorithm - O(E.log(E)) or O(E.log(V))

🛴 Shortest Path

Type of Algorithm Subjects of Application Time Complexity
Breadth-First Search Unweighted, Un-/Directed Graph O(V+E) for Adjacency List
Dijkstra Non-Negative Un-/Weighted Un-/Directed Graph O(E.log(V)) for Min-priority Queue
Bellman-Ford
Floyd-Warshall
    • Shortest Path: Breadth-First Search: Find the Shortest Path in a Unweighted Un-/Directed Graph based on BFS - O(V+E) for Adjacency List , V, E is the number of vertices and edges
    • Shortest Path: Bellman-Ford (Đang cập nhật)
    • Shortest Path: Floyd-Warshall (Đang cập nhật)

D) Greedy Algorithm

  1. Sherlock and The Beast
  • Find the "Decent Number" having n Digits ("Decent Number" has its digits to be only 3's and/or 5's; the number of 3's it contains is divisible by 5; the number of 5's it contains is divisible by 3; and it is the largest such number for its length)
  1. Largest Permutation
  • Swap 2 digits of a number k times to get largest number - O(n)

E) Dynamic Programming

Coin Change Algorithms: Given an array of choices, every choice is picked unlimited times

Knapsack Problems: Given an array of choices, every choice is picked only once

💰 Coin Change Algorithms

    • Coin Change[PDF]: How many ways to pay V money using C coins [C1,C2,...Cn] - O(C.V)

👜 Knapsack Problems

    • Knapsack 0/1[Wiki]: Given a List of Weights associated with their Values, find the Founding Weights and Maximum Total Value attained with its Total Weight <= Given Total Weight, each Weight is only picked once (0/1 Rule) - O(N.W) , N, W is length of weights array and given total weight
    • Partition Problem: Subset Sum[Wiki]: Given an Array containing only Positive Integers, find if it can be Partitioned into 2 Subsets having Sum of elements in both subsets is Equal. - O(N.T) , N, T is the length of numbers array and the target sum (=sum/2)
    • Partition Problem: Multiway Number Partitioning[Wiki]: Đang cập nhật

📈 Path Sum Problems

Subsequence = Any subset of an array/string

Subarray = Contiguous subsequence of an array

Substring = Contiguous subsequence of a string

📅 Subarray Problems

🍡 Subsequence Problems

📃 Substring Problems

F) Mathematics

📘 Binomial Coefficient Problems

    • Pascal Triangle: Create Pascal Triangle (to Calculate Multiple Large-Number Combinations) - O(n2)
    • PE #15: Lattice Paths[PDF] : Find the number of routes from the top left corner to the bottom right corner in a rectangular grid

📕 Factors Problems

📗 Multiples Problems

📓 Permutation Problems

    • Permutation Check: Check if 2 Numbers/Strings are Permutations - O(n) , n = max(|a|,|b|)

📙 Primes Problems

📔 Primes-Factors Problems

    • Euler Totient Function (Number List): Find ALL Numbers of Coprimes < n based on Euler Totient Function - O((l) + m.loglogm + l.(logm + k)) , k is the number of prime factors of n; m and l is max value and length of the input number list

📒 Pythagorean Theorem

📖 Non-categorized

Recursion Algorithm

Backtracking

Divide and Conquer

About

Some awesome competitive programming problems with solutions

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Jupyter Notebook 100.0%