Skip to content

I have started Data structures and Algorithms on April 1, 2021, and this repository will be containing my resources, tutorial, codes, and my approach to Qs, for future reference. As I'm in the learning process, this repository will be refreshed daily with my new bits of knowledge.

License

Notifications You must be signed in to change notification settings

hiimvikash/DSA-EndGame

Repository files navigation

DSA-EndGame 🔥

Data Structures :-

Data Structures is a way of storing/organising data in the memory, in such a way that access, management and modification become efficient.

Algorithms :-

Algorithms is any approach you use to perform operations on data (like searching, sorting, traversing, ..Etc.).

Let's Walk through this repository :-

    1. Bit Manipulations(10+ Questions)

    2. Heap(20 Questions)

    3. Trie(6 Questions)

    4. Graphs(40+ Questions)

Some Common FAQs :

1. How to make maximum Output from DSA-EndGame🔥?

Follow the Walk strictly and fill up the holes with "Prerequisites" below, then you will feel the smooth knowledge geeting into and expanding your 🧠.

2. Why Have you not Started Data Structures with Arrays?

Array is a topic which has unlimited questions and I believe as a beginner if you start with array then geeting out of it is tough so I don't want you all to get stuck in array only till end and leave other data structures.

I also believe that many of you are very well familiar with concept of array traversing, modifying and etc..so here we will solve only questions of arrays after completing full data structures.

If you have no idea of Arrays then just understand few concept like :- Traversing in array, modifying array, reversing array and some basic questions of array from Hackerrank.

3. How to be consistent while completing DSA-EndGame?

Make a group of not more than 3 friends who are equally passionate like you to master DSA and start peer programming by making a single google sheet shared between your friends and update your daily work in sheet due to which you all will be able to see each others progress daily.

4. Why to prefer this repository over some paid courses which claim to be complete DSA course?

Except pepcoding resources I haven't found any course which would satisfy my heart, In every courses either there will be some topic missing or topic done with few questions only.

So I tell you the best platform is Youtube.

Now the problem arises with Youtube is best videos in each topics are scattered in all over different channels like DP is best explained by AdityaVerma, Stack & Queues are best explained by SimpleSnipets, Question solutions are best explained by Striver Bhaiya simillarly many topic have their own best channels.

So all you need is Guided path and Youtube videos link attached with each Questions and topics.

and your above need is fulfilled, has been tried to be fulfilled with DSA-EndGame🔥.

Thankyou.

Prerequisites :-

  1. PROGRAMMING LANGUAGE.
trueAF.mp4
  1. CLASS AND OBJECTS.
  2. CONSTRUCTOR.
  3. this KEYWORD.
  4. ACCESS MODIFIERS IN JAVA.
  • Public- The access level of public modifier is everywhere. Methods, variables declared public can be accesed from anywhere after importing that class.

  • Default- The access level of default modifier is within package. Methods, variables declared default can be accesed from other classes of same package.

  • Private- The access level of private modifier is within the class. Methods, variables declared private cannot be accesed from outside the class.

  1. ENCAPSULATION.
  2. STATIC KEYWORD IN JAVA.
    • You can call static methods from non static method but reverse is not true.
  3. INNER CLASS IN JAVA.
  4. Pass by value.
  5. Pass by refrence.
import java.util.*;

public class Hi {

	// here value is copied in localVariable 'a'.
	public static void incrementPrimitiveDT(int a) {
		a++;
	}

	// here reference is copied, means 'input' is also pointing to 'arr'.
	public static void incrementReferenceDT(int input[]) {
		for(int i=0;i<input.length;i++) {
			input[i]++;
		}
	}


	public static void main(String[] args) {
		int i=10;
		incrementPrimitiveDT(i); // passByValue
		System.out.println(i); // 10


		int arr[]= {1,2,3,4,5};
		incrementReferenceDT(arr); // passByReference
		System.out.println(Arrays.toString(arr)); // [2, 3, 4, 5, 6]
	}
}
  1. Strings are immutable.
  2. String Builder
  3. == & .equals in String.
  4. Wrapper class in java.
    • Object creation and memory allocation in Integer class.

    public static void main(String[] args) {
		// case 1:
				Integer i= new Integer(1);
				Integer j=new Integer(1);
				System.out.println(i==j); // false,  coz == check reference address of i and j, and here 'i' is pointing to 1 (i---> 1) and 'j' is pointing to different 1 (j---> 1)
				System.out.println(i.equals(j)); // true

		// case 2:
				Integer a=new Integer(2);
				Integer b=2;

				System.out.println(a==b); // false
				System.out.println(a.equals(b)); // true

		// case 3:
				Integer x=new Integer(3);
				Integer y=x;

				System.out.println(x==y); // true
				System.out.println(x.equals(y)); // true


		// case 4
				Integer p=128;
				Integer q=128;
				System.out.println(p==q); // false
				System.out.println(p.equals(q)); // true

		// case 5 -128 to 127 is in cached memory so they point to same object without creating it instances.
				Integer s=50;
				Integer t=50;
				System.out.println(s==t); // true
				System.out.println(s.equals(t)); // true
    }
  1. Generics in Java.

  2. isequals and hashcode in java by codingSimplified.

  3. % operator in JAVA : dividend % divisor - Here two statement is needed to be taken care :-

    • When Divedend < Divisor then answer is dividend.

    • When Divedend > Divisor then answer lie in between [0 to divisor-1].

  4. Store 2 numbers in a number. (true only in +ve scenerio)

    • To Inject B in A we ADD(+) B*INF in A and store it in A, where INF is any number greater than A and B.
    • to extract old number i.e., A from modified A we do (A % INF).
    • to extract new number(Injected number) i.e., B from modified A we do (A / INF).
    	int a=5;
    	int b=4;// number to be injected
    	int INF=9999;
    	a=a+(b*INF);
    	System.out.println(a%INF); // 5
    	System.out.println(a/INF); //4
  5. Comparator : - Collections.sort(al,(a,b)-> scores[b]-scores[a]);

// this is a PQ of ARRAY of size 2
Comparator<int[]> ShortDisFromOrigin = (int p1[], int p2[]) -> ((p1[0]*p1[0]) + (p1[1]*p1[1])) - ((p2[0]*p2[0]) + (p2[1]*p2[1]));
PriorityQueue<int[]> pq=new PriorityQueue<>(ShortDisFromOrigin);

// OR


PriorityQueue<int[]> pq=new PriorityQueue<>((int p1[], int p2[]) -> ((p1[0]*p1[0]) + (p1[1]*p1[1])) - ((p2[0]*p2[0]) + (p2[1]*p2[1])));
Arrays.sort(arr,(x,y)-> (x.c < y.c) ? 1 : -1); // 1 signifies swap -1 says no swap so this DEScending order

whenever u want to swap then pass 1 else -1 according to ur logic.

See this Q

Arrays.sort(arr, new Comparator<Iteminfo>() {
            
    public int compare(Iteminfo o1, Iteminfo o2)
    {
            if(o2.c > o1.c) return 1; // that's why we write o2.c - o1.c if descending order
            return -1;
    }
});
  1. HashMap Itterations
// freq of words
    HashMap<String, Integer> hm=new HashMap<>();
    for(String word : words) hm.put(word, hm.getOrDefault(word,0)+1);
// adding entries in list for sorting
    List<Map.Entry<String, Integer>> l=new ArrayList<>();
    for(Map.Entry<String, Integer> e : hm.entrySet()) l.add(e); // if u want key then write e.getKey() || e.getValue();
    Collections.sort(l, (e1,e2)-> (e2.getValue()!=e1.getValue())?e2.getValue()-e1.getValue(): e1.getKey().compareTo(e2.getKey())); // conditional sorting
//

// itterating over keys
for(String s : hm.keySet())
	hm.get(s);
    • Character to Integer
    char ch = '2';
    int a = ch - '0'; // 2
    • Integer to Character
    int a=65;  
    char ch=(char)a; // A
    • String to Integer
    int i=Integer.parseInt("0100"); // 100
    
    String s="200";  
    int i=Integer.valueOf(s);
    • Integer to String
    String.valueOf(20);
    • If you want to acces array for each character then how to get Index ?
    for(char c = 'a'; c<='z'; c++){
    arr[c-'a'];
    }
    • StringBuilder to String
    return sb.toString();
    return sb.substring(0, sb.length() - 1); // except last
    • Char[] to String
    return new String(ch);
    return String.valueOf(ch);


1. Memory Allocation when you initialize a variable.

kunalKushwaha1 1

  • Note : When there is no reference variable pointing to actual object then it is deleted automatically when garbage collection hits.

2. Objects & Reference Variable.

kunalKushwaha1 0

public class Demo{ 
	public static void main(String[] args) {
			Human obj=new Human();
			Human son=obj; // this is his mom who call obj as hisSon.
			Human bro=obj; // this is his sis who call obj as hisBro.
			son.hairCut="done"; // here his mom made him do haircut.
			// here his sister is also able to see his haircut.
			System.out.println(bro.hairCut); // done
		
	}
}
class Human{
	String name="Vikash";
	String hairCut="notDone";
}

About

I have started Data structures and Algorithms on April 1, 2021, and this repository will be containing my resources, tutorial, codes, and my approach to Qs, for future reference. As I'm in the learning process, this repository will be refreshed daily with my new bits of knowledge.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages