Skip to content

sandeepjindal/algos

Repository files navigation

alt tag
-Here we will learn all the data-structure and algorithms, we generally need.

Topics:

  • Array
  • Linked list
  • Stack
  • Queue
  • Trees
  • Priority Queues
  • Graphs
  • Sorting
  • Divide and conquer(backtrack/Recurssion)
  • Traversals
  • Dynamic Programming

Patterns

If input array is sorted then

  • Binary search
  • Two pointers

If asked for all permutations/subsets then

  • Backtracking

If given a tree then

  • DFS
  • BFS

If given a graph then

  • DFS
  • BFS

If given a linked list then

  • Two pointers

If recursion is banned then

  • Stack

If must solve in-place then

  • Swap corresponding values
  • Store one or more different values in the same pointer

If asked for maximum/minimum subarray/subset/options then

  • Dynamic programming

If asked for top/least K items then

  • Heap
  • QuickSelect

If asked for common strings then

  • Map
  • Trie

Else

  • Map/Set for O(1) time & O(n) space
  • Sort input for O(nlogn) time and O(1) space

STL resources:

http://www.cplusplus.com/reference/algorithm/

https://github.com/srcmake/cpp-stl-algorithms

https://www.topcoder.com/community/competitive-programming/tutorials/power-up-c-with-the-standard-template-library-part-1/

https://www.hackerearth.com/practice/notes/standard-template-library/

Will update if something new will add.
Contributors: Sandeep Jindal