Shivam-Saini-SS / DSA-EndGame

I have started DS & ALgo 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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DataStructures-And-Algorithms.

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.).


Prerequisites :-

  1. PROGRAMMING LANGUAGE.
  2. CLASS AND OBJECTS.
  3. CONSTRUCTOR.
  4. this KEYWORD.
  5. 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. == & .equals in String.
  3. 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.

    • 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


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 DS & ALgo 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.


Languages

Language:Java 100.0%