Data Structures is a way of storing/organising data in the memory, in such a way that access, management and modification become efficient.
Algorithms is any approach you use to perform operations on data (like searching, sorting, traversing, ..Etc.).
Follow the Walk strictly and fill up the holes with "Prerequisites" below, then you will feel the smooth knowledge geeting into and expanding your 🧠.
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.
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.
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.
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.
- PROGRAMMING LANGUAGE.
trueAF.mp4
- CLASS AND OBJECTS.
- CONSTRUCTOR.
- this KEYWORD.
- ACCESS MODIFIERS IN JAVA.
- ENCAPSULATION.
- STATIC KEYWORD IN JAVA.
-
- You can call static methods from non static method but reverse is not true.
- INNER CLASS IN JAVA.
- Pass by value.
- 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]
}
}
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
}
-
% operator in JAVA : dividend % divisor - Here two statement is needed to be taken care :-
-
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
-
Comparator : -
Collections.sort(al,(a,b)-> scores[b]-scores[a]);
Arrays.sort(arr,(a,b)-> a.length()-b.length());
- Priority Queue
// 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
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;
}
});
- 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);
- Note : When there is no reference variable pointing to actual object then it is deleted automatically when garbage collection hits.
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";
}