Home

Awesome

datastructures-algorithms

List of Programs related to data structures and algorithms

Data Structures

Stack

No.NameSourceLiveDocumentationLevelPattern
1Stack using arraySourceJavaScript-<!--[Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/datastructures/stack/1.stack_with_array//stack_with_array.md) -->EasyUsing Array operations
2Stack using linkedlistSourceJavaScript-<!--[Documentation](https://github.com/sudheerj/datastructures-algorithms/blob/master/src/javascript/datastructures/stack/2.stack_with_linkedlist/stack_with_linkedlist.md) -->EasyUsing LinkedList operations

Queue

  1. Queue using array: JavaScript
  2. Queue using linkedlist: JavaScript

SinglyLinkedlist

  1. SinglyLinkedlist implementation: Source Playground Documentation

DoublyLinkedlist

  1. DoublyLinkedlist implementation: Source Playground Documentation

Tree

  1. Binary Search Tree: Source JavaScript Documentation

Graphs

  1. Unweighted undirected graph: Source Playground Documentation

HashTable

  1. HashTable: JavaScript

Algorithms

Array

No.NameSourceLiveDocumentationLevelPattern
1Contains duplicatesSourcePlaygroundDocumentationEasySet/Object
2Two sum2- Input array sortedSourcePlaygroundDocumentationMediumTwo pointers
33 sumSourcePlaygroundDocumentationMediumTwo pointers
4Product of array except selfSourcePlaygroundDocumentationMediumPrefix and postfix pattern
5Max sum subarraySourcePlaygroundDocumentationMediumKadane's algorithm
6Minimum size subarray sumSourcePlaygroundDocumentationMediumSliding window
7Sort ColorsSourcePlaygroundDocumentationMediumTwo pointers
8Maximum product subarraySourcePlaygroundDocumentationMediumKadane's algorithm
9Find minimum in rotated sorted arraySourcePlaygroundDocumentationMediumBinary search technique
10Maximum Circular subarraySourcePlaygroundDocumentationMediumKadane's algorithm
11Rotate arraySourcePlaygroundDocumentationMediumTwo pointers
12Search in rotated sorted arraySourcePlaygroundDocumentationMediumBinary search
13Container with most waterSourcePlaygroundDocumentationMediumTwo pointers
14First missing positive numberSourceJavaScriptDocumentationHardIn-place hashing
15Best time to buy stock and sell stockSourceJavaScriptDocumentationEasyGreedy algorithm
16Two missing numbersSourceJavaScriptDocumentationMediumSum and average calculations
17Pascal's TriangleSourceJavaScriptDocumentationEasyArray traversal and sequential sum
18Remove ElementSourceJavaScriptDocumentationEasyArray traversal
19Can place flowersSourceJavaScriptDocumentationEasyArray traversal and comparison
20Majority ElementSourceJavaScriptDocumentationEasyBoyer Moore Voting algorithm

String

No.NameSourceLiveDocumentationLevelPattern
1Longest substring without repeating charactersSourceJavaScriptDocumentationMediumSliding Window
2Longest repeating character replacementSourceJavaScriptDocumentationMediumSliding Window
3Minimum window substringSourceJavaScriptDocumentationHardSliding Window
4Valid anagramSourceJavaScriptDocumentationEasyFrequency counting
5Group anagramsSourceJavaScriptDocumentationMediumFrequency counting
6Valid palindromeSourceJavaScriptDocumentationEasyTwo pointer
7Longest palindromic substringSourceJavaScriptDocumentationMediumExpanding around center
8Palindromic substringsSourceJavaScriptDocumentationMediumExpanding around center
9Encode and decode stringsSourceJavaScriptDocumentationMediumBasic string and array operations
10Greatest common devisor of stringsSourceJavaScriptDocumentationEasyEuclidean and String operations
11Reverse words in stringSourceJavaScriptDocumentationMediumBasic string and array operations
12Length of last wordSourceJavaScriptDocumentationEasyString traversal

Dynamic programming

No.NameSourceLiveDocumentationLevelPattern
1Climbing stairsSourceJavaScriptDocumentationMediumDynamic programming
2Coin changeSourceJavaScriptDocumentationMediumDynamic programming
3Longest increasing subsequenceSourceJavaScriptDocumentationMediumDynamic programming(Bottom up)
4Longest common subsequenceSourceJavaScriptDocumentationMediumTwo-dimentional bottom up Dynamic programming
5Word breakSourceJavaScriptSourceMediumBottom up dynamic programming
6Combination Sum 4SourceJavaScriptDocumentationMediumBottom up Dynamic programming
7House robberSourceJavaScriptDocumentationMediumFibonacci pattern bottom-up dynamic programming
8House robber 2SourceJavaScriptDocumentationMediumBottom-up dynamic programming
9Decode waysSourceJavaScriptDocumentationMediumDynamic programming
10Unique pathsSourceJavaScriptDocumentationMediumDynamic programming
11Jump gameSourceJavaScriptDocumentationMediumDynamic programming or Greedy

Binary

No.NameSourcePlaygroundDocumentationLevelPattern
1Sum of two integersSourceJavaScriptDocumentationMediumBitwise operations
2Number of 1 BitsSourceJavaScriptDocumentationEasyBrian Kernighans
3Counting BitsSourceJavaScriptDocumentationEasyDynamic programming
4Missing numberSourceJavaScriptDocumentationEasyBitwise XOR
5Reverse BitsSourceJavaScriptDocumentationEasyBitwise operations

Stack

No.NameSourcePlaygroundDocumentationLevelPattern
1Sort StackSourceJavaScriptDocumentationEasyStack push & pop
2Balanced BracketsSourceJavaScriptDocumentationMediumStack push and pop
3Reverse Polish NotationSourceJavaScriptDocumentationMediumStack push & pop
4Daily TemperaturesSourceJavaScriptDocumentationMediumMonotonic decreasing stack
5Number of People See In QueueSourceJavaScriptDocumentationMediumMonotonic decreasing stack

LinkedList

No.NameSourcePlaygroundDocumentationLevelPattern
1Reverse sublistSourceJavaScriptDocumentationEasyList traversal
2Detect cycle in a linkedlistSourcePlaygroundDocumentationEasyFloyd's cycle-finding or Tortoise and Hare algorithm
3Merge two sorted listsSourceJavaScriptDocumentationEasyArithmetic comparison
4Merge K sorted listsSourceJavaScriptDocumentationHardDivide and conquer
5Remove Kth node from end of listSourceJavaScriptDocumentationMediumTwo pointers
6Reorder listSourceJavascriptDocumentationMediumTwo pointers
7Find middle nodeSourceJavaScriptDocumentationEasyTwo pointers
8Find Kth node from end of listSourceJavaScriptDocumentationEasyTwo pointers
9Partition listSourceJavaScriptDocumentationMediumTwo pointers
10Remove duplicatesSourceJavaScriptDocumentationEasyTwo pointers
11Binary to decimalSourceJavaScriptDocumentationEasyList traversal and math operations

Doubly linkedlist

No.NameSourcePlaygroundDocumentationLevelPattern
1Swap first and lastSourceJavaScriptDocumentationEasySwap nodes
2Palindrome checkSourcePlaygroundDocumentationEasyTwo pointers
3Swap node pairsSourceJavaScriptDocumentationMediumList traversal and update pointers

Tree

No.NameSourcePlaygroundDocumentationLevelPattern
1Maximum depth of binary treeSourceJavaScriptDocumentationEasyDepth First Search(DFS) with recursion
2Same treeSourceJavaScriptDocumentationEasyDepth First Search(DFS) with recursion
3Invert or Flip binary treeSourceJavaScriptDocumentationEasySwapping nodes and Depth First Search(DFS) with recursion
4Binary tree maximum path sumSourceJavaScriptDocumentationHardDFS using recursion
5Binary tree level order traversalSourceJavaScriptDocumentationEasyDepth First Search(DFS) with recursion
6Serialize and deserialize binary treeSourceJavaScriptDocumentationHardDFS preorder traversal
7Subtree of another treeSourceJavaScriptDocumentationEasyDepth First Search(DFS) with recursion
8Construct binary tree from preorder and inorder traversalSourceJavaScriptDocumentationMediumDFS with recursion
9Validate BSTSourceJavaScriptDocumentationMediumDepth-First-Search(DFS) using recursion
10Kth smallest element in BSTSourceJavaScriptDocumentationMediumIterative inorder traversal using stack
11Lowest Common Ancestor of BSTSourceJavaScriptDocumentationMediumIterative tree traversal
12TrieSourceJavaScriptDocumentationMediumIteration over string characters
13Design and Search words DatastructureSourceJavaScriptDocumentationMediumTrie and DFS recursion
14Word search 2SourceJavaScriptDocumentationHardBacktracking with Trie

Graph

No.NameSourceLiveDocumentationLevelPattern
1Clone graphSourceJavaScriptDocumentationMediumDepth-First-Search(DFS) using recursion
2Course scheduleSourceJavaScriptDocumentationMediumDFS using recursion
3Pacific Atlantic waterflowSourcePlaygroundDocumentationMediumDFS using recursion
4Number of IslandsSourceJavaScriptDocumentationMediumDFS using recursion
5Alien dictionarySourceJavaScriptDocumentationHardKahn's algorithm for topological sorting
6Graph valid treeSourceJavaScriptDocumentationMediumUnion Find algorithm(+ union by rank & path compression)
7Number of connected components in an undirected graphSourceJavaScriptDocumentationMediumUnion Find algorithm(+ union by rank & path compression)
8Walls and gatesSourceJavaScriptDocumentationMediumBFS traversal

Matrix

No.NameSourceLiveDocumentationLevelPattern
1Set matrix zerosSourceJavaScriptDocumentationMediumIn-place updates through traversal
2.Spiral matrixSourceJavaScriptDocumentationMediumBoundary matrix traversal/spiral pattern
3Rotate imageSourceJavaScriptDocumentationMediumInplace square rotation
4Word searchSourceJavaScriptDocumentationMediumDepth-First Search (DFS) using recursion

Interval

No.NameSourceLiveDocumentationLevelPattern
1Insert intervalSourceJavaScriptDocumentationMediumBasic math operations
2Merge intervalSourceJavaScriptDocumentationMediumSorting and basic math operations
3Non-overlapping intervalsSourceJavaScriptDocumentationMediumGreedy and basic math operations
4Meeting roomsSourceJavaScriptDocumentationMediumGreedy and basic math operations
5Meeting rooms 2SourceJavaScriptDocumentationMediumTwo pointers

Hashtable

No.NameSourceLiveDocumentationLevelPattern
1DuplicatesSourceJavaScriptJavaScriptEasyUsing Map
2Two sumSourceJavaScriptDocumentationEasyUsing Map
3First non repeating characterSourceJavaScriptDocumentationEasyUsing Map
4Group anagramsSourceJavaScriptDocumentationMediumUsing Map & its methods
5Verify Common ElementsSourceJavaScriptDocumentationEasyUsing Map methods
6Longest consequtive sequenceSourceJavaScriptDocumentationMediumFind sequence using set or hash table
7Valid SudokuSourceJavaScriptDocumentationMediumUsing Map and Set methods
8Letter combinationsSourceJavaScriptDocumentationMediumBacktracking with hash table mapping
9LRU CacheSourceJavaScriptDocumentationMediumCombination of Hash Table and doubly linked list
10Maximum number of balloonsSourceJavaScriptDocumentationEasyHash map on characters

Sorting

No.NameSourcePlaygroundDocumentationLevelComplexity
1Bubble sortSourceJavaScriptDocumentationEasyTC: O(n<sup>2</sup>), SC: O(1)
2Selection sortSourceJavaScriptDocumentationEasyTC: O(n<sup>2</sup>), SC: O(1)
3Insertion sortSourceJavaScriptDocumentationEasyTC: O(n<sup>2</sup>), SC: O(1)
4Merge sortSourceJavaScriptDocumentationMediumTC: O(n log(n)), SC: O(n)
5Quick sortSourceJavaScriptDocumentationMediumTC: O(n<sup>2</sup>), SC: O(log n)
6Heap sortSourceJavaScriptDocumentationHardTC: O(n log(n)), SC: O(1)