Skip to content

Shivaansh-Agarwal/DS-Algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

307 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DS-Algorithms

TOPICS

  1. Mathematics
  2. Bitwise Algorithms
  3. Recursion
  4. Arrays
  5. Searching
  6. Sorting
  7. Matrix
  8. Hashing
  9. Strings
  10. Linked List
  11. Stack
  12. Queue
  13. Tree
  14. Binary Search Tree
  15. Heap
  16. Graph
  17. Greedy
  18. BackTracking
  19. Dynamic Programming
  20. Graph (Advanced)
  21. Trie

Mathematics

S.No. Problem Solution Date Reference

Bitwise Algorithms

S.No. Problem Solution Date References
1 Given a number N check if the k'th bit is set or not πŸ”‘ 20-05-19 -
2 Given a number N determine whether it is even or odd πŸ”‘ 20-05-19 -
3 Given a number N determine whether it is a power of 2 or not πŸ”‘ 20-05-19 -
4 Given a number N determine the number of set bits πŸ”‘ 20-05-19 -
5 Given an integer array that contains every number even number of times, except one number. Find that number. πŸ”‘ 20-05-19 A
6 Given an integer array that contains every number even number of times, except 2 numbers. Find the 2 numbers. πŸ”‘ 21-05-19 A
7 Given a number N determine the position of the first set bit πŸ”‘ 21-05-19 -
8 Given a String as input, generate it's PowerSet πŸ”‘ 21-05-19 -
9 Given a number N determine the position & value of the most significant digit πŸ”‘ 21-05-19 -
10 Given a number N determine the XOR of all numbers from 1 to N WITHOUT using Loops πŸ”‘ 21-05-19 A
11 Given a number N. Find the count of number of set bits from 1 to N πŸ”‘ 21-05-19 -
12 Given two numbers A and B. Count number of bits needed to be flipped to convert A to B πŸ”‘ 21-05-19 -

Recursion

S.No. Problem Solution Date References
1 Print numbers from 1 to N without using Loop πŸ”‘ 22-05-19 -
2 Print numbers from N to 1 without using Loop πŸ”‘ 22-05-19 -
3 Factorial πŸ”‘ 22-05-19 -
4 πŸ’‘ Factorial with Tail Recursion πŸ”‘ 22-05-19 -
5 πŸ’‘ Given a rope of length n and 3 values (a,b,c), we need to make maximum pieces such that every piece has length in set {a,b,c} πŸ”‘ 22-05-19 -
6 Josephus Problem πŸ”‘ 23-05-19 V1 V2 A1 A2
7 Print all subsets of a given set (string) πŸ”‘ 24-05-19 -
8 Given an integer set and a number, print all subsets whose sum is equal to given number -
9 Given an unsorted array of N elements and an element X. The task is to write a recursive function to check whether the element X is present in the given array or not. -
10 Given a string, the task is to write a recursive function to check if the given string is palindrome or not. -
11 Tower of Hanoi -

Arrays

S.No. Problem Solution Date References
1 Reversing an Array C++ 25-05-19 -
2

3 πŸ’‘
Rotating an Array (Naive Approach)

Rotating an Array (Efficient Approach)
C++

C++
25-05-19

25-05-19
-

-
4

5 πŸ’‘
Leaders in an Array (Naive Approach) O(n^2)

Leaders in an Array (Efficient Approach) O(n)
C++

C++
26-05-19

26-05-19
-

-
6

7 πŸ’‘
Trapping Rainwater (Naive Approach) O(n^2)

Trapping Rainwater (Efficient Approach) O(n)
C++

C++ JAVA
26-05-19

26-05-19
-

-
8 πŸ’‘ Stock Buy and Sell C++ 26-05-19 -
9

10
Reverse Arrays in Groups ((Naive Approach) O(n^2))

Reverse Arrays in Groups (Efficient Approach)
C++

C++
27-05-19

27-05-19
-

-
11 πŸ’‘ Maximum Occurred Integer in given Ranges C++ 28-05-19 -
12 πŸ’‘ Frequencies of Array elements in a Given Range C++ 28-05-19 -
13 πŸ’‘ Given an Array arr of n elements, Find the position of an element of which sum of elements on LHS is equal to sum of elements on RHS C++ 30-05-19 -
14 Smallest Positive Missing Number from 1 to N in an Array of Size N, which can store any number. C++ 30-05-19 -
15 Given an array, Find first continuous SubArray with Given Sum S C++ 04-05-19 GFG

Searching

S.No. Problem Solution Date References
1 Linear Search πŸ”‘ 01-06-19 -
2 Binary Search [Paytm] πŸ”‘ 02-06-19 -
3 Given a Sorted Array, find the number of occurrences of a given number πŸ”‘ 03-06-19 -
4 Given a Sorted Binary Array, find the number of 1's in it πŸ”‘ 04-06-19 -
5 Find Minimum Number in a sorted rotated array πŸ”‘ 05-06-19 -
6 Find two Repeated elements in an array of size N+2 which contains elements from 1 to N πŸ”‘ 05-06-19 -
7 Given a sorted array of N elements which contains consecutive elements, and one element is repeated number of times, Find the number and it's frequency. πŸ”‘ 05-06-19 -
8 Given an array of size N where all elements are distinct and a number K, Find the K'th smallest element [Microsoft, VMWare, Cisco] πŸ”‘ 05-06-19 -

Sorting

S.No. Problem Solution Date References
1 Bubble Sort πŸ”‘ 20/08/19 -
2 Selection Sort πŸ”‘ 21/08/19 -
3 Insertion Sort πŸ”‘ 21/08/19 -
4 Heap Sort - - -
5 Merge Sort πŸ”‘ 22/08/19 -
6 Quick Sort πŸ”‘ 28/01/2020 -
7 Counting Sort - - -
8 Cycle Sort - - -
9 Radix Sort - - -
10 Shell Sort - - -
11 Inversion Count πŸ”‘ 29/01/2020 -
12 Union of 2 Sorted Arrays πŸ”‘ 01/02/2020 -
13 Intersection of 2 Sorted Arrays πŸ”‘ 01/02/2020 -
14 Count No of Triangles Possible πŸ”‘ 03-02-2020 GFG
15 3 Way Partitioning πŸ”‘ 03-02-2020 -
16 Find Triplets with 0 Sum πŸ”‘ 03-02-2020 (LEARNT=> How to use 2 pointer technique)
17 Problem based on Counting Sort πŸ”‘ 03-02-2020 -
18 Closest 0's 1's 2's πŸ”‘ 03-02-2020 -
19 Sort by Absolute Difference πŸ”‘ 04-02-2020 (LEARNT=> Sort an array based on another array using Comparator Interface)
20 Triplet Sum in Array πŸ”‘ 04-02-2020 (LEARNT=> How to use 2 pointer technique)

Matrix

S.No. Problem Solution Date References
1 Print the matrix in the Sanke Pattern πŸ”‘ 12-08-19 -
2 Transpose of a Matrix πŸ”‘ 12-08-19 -
3 πŸ’‘ Rotate a Matrix πŸ”‘ 13-08-19 -
4 πŸ’‘ Search an element in a row wise and column-wise sorted Matrix πŸ”‘ 13-08-19 -
5 Given a matrix Print the Boundary elements πŸ”‘ 14-08-19 -
6 πŸ’‘ Given a matrix Print the elements in Spiral Order πŸ”‘ - -
7 πŸ’‘ Matrix Multiplication πŸ”‘ - -
8 πŸ’‘ Determinant of a Matrix πŸ”‘ - -
9 Implementation of a 2D Matrix (Using C++ Vectors) πŸ”‘ - -

Hashing

S.No. Problem Solution Date References
1 Given an array find the most frequent element. πŸ”‘ 02-08-19 -
2 Given an array find if there is a subarray with 0 sum.(Naive Solution O(n^2)) πŸ”‘ 05-08-19 -
3 Given an array find if there is a subarray with 0 sum.(Optimal Solution O(n^2)) πŸ”‘ 05-08-19 -
4 Given an array, print the frequency of every element. πŸ”‘ 02-08-19 -
5 Given an array and a sum x find if there is subarray where sum is aqual to x πŸ”‘ 06-08-19 -
6 Find the largest sub-array with given sum πŸ”‘ 06-08-19 -
7 Find the smallest sub-array with given sum πŸ”‘ 06-08-19 -
8 Find the largest sub-array with 0 sum πŸ”‘ 08-08-19 -
9 Find the smallest sub-array with 0 sum πŸ”‘ 08-08-19 -
10 πŸ’‘ Given a binary array find length of the largest subarray having equal number of 0's and 1's πŸ”‘ 11-08-19 -
11 Given an unsorted array and a number x, find if there is a pair with sum x πŸ”‘ 09-08-19 -

Strings

S.No. Problem Solution Date References
1 Check if 2 Strings are ANAGRAMS of each other πŸ”‘ 24-07-19 -
2 Given a String find the first repeating character πŸ”‘ 24-07-19 -
3 Given a String Find the First Non-Repeating Character πŸ”‘ 25-07-19 -
4 Given a String Find the Lexicographic Rank of it among all its Permutations πŸ”‘ 25-07-19 -
5 Anagram Search πŸ”‘ 29-07-19 -
6 Pattern Searching (Naive String Matching Algorithm) πŸ”‘ - -
7 Pattern Searching (Rabin Karp Algorithm) πŸ”‘ - -
8 Pattern Searching (KMP(Knuth Morris Pratt) Algorithm) πŸ”‘ - -
9 Pattern Searching (Suffix Tree Algorithm) πŸ”‘ - -
10 Check whether 2 strings are rotations of each other or not πŸ”‘ 29-07-19 -

Linked List

S.No. Problem Solution Date References
1 Singly Linked List Implementation πŸ”‘ 06-06-19 -
2 Middle Element of a Linked List πŸ”‘ 09-06-19 -
3 kth element from the end of a Linked List πŸ”‘ 15-06-19 -
4 Reverse a Linked List (Iterative Approach) πŸ”‘ 17-06-19 -
5 Reverse a Linked List (Recursive Approach) πŸ”‘ 24-06-19 -
6 Detect Loop in a Linked List πŸ”‘ 25-06-19 -

Stack

S.No. Problem Solution Date References
1 Stack Implementation using Linked List πŸ”‘ 10-07-19 -
2 Check for Balanced Parenthesis πŸ”‘ 10-07-19 -
3 Stack Implementation using Queues πŸ”‘ 11-07-19 -
4 Stack Implementation using C++ STL πŸ”‘ 14-07-19 -
5 Implement 2 Stacks in an Array πŸ”‘ 16-07-19 -
6 Implement n Stacks using 1 Array πŸ”‘ - -
7 Print Reverse of linked List using Stack πŸ”‘ 16-07-19 -
8 Next Greater Element πŸ”‘ 18-07-19 -
9 Stock Span Problem πŸ”‘ 17-07-19 -
10 Previous Greater Element πŸ”‘ 19-07-19 -
11 Next Smaller Element πŸ”‘ 19-07-19 -
12 Previous Smaller Element πŸ”‘ 19-07-19 -
13 Remove Consecutive Duplicates πŸ”‘ 20-07-19 -
14 Remove Paired Duplicates πŸ”‘ 21-07-19 -
15 Print Minimum of Stack at each Pop Operation πŸ”‘ 21-07-19 -

Queue

S.No. Problem Solution Date References
1 Queue Implementation using Linked List πŸ”‘ 11-07-19 -

Tree

S.No. Problem Solution Date References
1 DFS Traversal(Java) πŸ”‘ 03-10-19 -
2 BFS or Level Order Traversal (Java) πŸ”‘ 13-11-19 -
3 Given a Binary Tree, print it's level order traversal such that each level is in new line πŸ”‘ 14-11-19 -
4 Given a Binary Tree, find it's height πŸ”‘ 14-11-19 -
5 Given a Binary Tree, check if it follows Children-Sum Property πŸ”‘ 15-11-19 -
6 Check if a Binary Tree is Balanced or Not (O(n^2)) πŸ”‘ 15-11-19 -
7 Check if a Binary Tree is Balanced or Not (Optimal Solution O(n)) πŸ”‘ 19-11-19 1 2
8 Given a Binary Tree, Print all nodes at level K πŸ”‘ 16-11-19 -
9 Given a Binary Tree, Check whether it is Binary Search Tree (BST) or not (Inefficient Method) πŸ”‘ 20-11-19 1
10 Given a Binary Tree, Check whether it is Binary Search Tree (BST) or not (Efficient Method) πŸ”‘ 21-11-19 1
11 Given a Binary Tree, Check whether it is Binary Search Tree (BST) or not (Using Inorder Traversal) - - -
12 Given a Binary Tree, Convert it into a Double Linked List (In-Place) - - -
13 Lowest Common Ancestor in a Binary Tree - - -
14 Maximum Sum Root to Leaf Path - - -
15 Finding the Diameter of Binary Tree - 28-11-19 -
16 Check if given Preorder, Inorder and Postorder traversals are of same tree - - -
17 Left View of Binary Tree - Iterative Method using Queue πŸ”‘ 24-11-19 1

Tire

S.No. Problem Solution Date References
1 Insertion and Search in Trie JAVA 14-05-2020 -

About

The repository contains my C++ & Java solutions related to different Data Structure Problems.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors