for those who did not get how the time complexity of nested loop is O(n) we calculate the time complexity of nested loop :- by finding how many time the inner loops are running for nth value of outermost loop here the outer loop will almost run for n-1 time maximum as the pivot is fixed so array length -1 now we will count the number of iterations of inner loop since first while loop checks the condition if arr[i]
1:17:10 static int partition2(int[] arr, int start, int end) { Random random = new Random(); int randomIndex = random.nextInt(end - start + 1) + start;
// Swap the random pivot element with the first element to improve worst case swapElements(arr, start, randomIndex); int pivot = arr[start];
// now the pivot is on start index so check the elements after pivot are they smaller or larger or equal to pivot int i = start + 1; int j = end;
Mam, mein leetcode per question try kar raha hu ,basically Maine array se chalu kiya,lekin logic or code dono nahi bana pa raha hu , consistent hu lekin jab logic nahi banta to motivation down ho jata hai mam
@@nucle0981 308 Everything in Java is passed by value. In case of an array which is nothing but an Object, the array reference is passed by value just like an object reference is passed by value.
reference pass hota hai jo orignal array ko point karta h or jab recursion call hoti h to new array banta hai par vo bi same hi object ko point kar rha hota isliye jab method call hoti h to array update ho jata h
static void printArray(int arr[]){ for(int val : arr){ System.out.print(val+" "); } System.out.println(); } static void swap(int arr[],int x,int y){ int temp= arr[x]; arr[x]=arr[y]; arr[y]=temp; } static int partition(int arr[],int start,int end){ int pivot =arr[start]; int cnt = 0; for(int i= start+1;i=end){ return; } int pi = partition(arr, start, end); quickSort(arr, start, pi-1); quickSort(arr, pi+1, end); } public static void main(String[] args) {
int arr[] = {2,4,33,8,6,43,5}; System.out.println("array before sorting"); printArray(arr); int n=arr.length; quickSort(arr,0,n-1); System.out.println("array after sorting"); printArray(arr); } }
PW Skills is announcing the launch of the following programs,
Binary Batch:- Java-with-DSA-&-System-Design (Java with DSA & System Design)
pwskills.com/course/Java-with-DSA-and-system-design (Hindi)
pwskills.com/course/Java-with-DSA-and-System-Design (English)
Sigma Batch:- Full-Stack-Web-Development (MERN Stack)
pwskills.com/course/Full-Stack-web-development (Hindi)
pwskills.com/course/Full-Stack-Web-Development (English)
Impact Batch:- Data-Science-Masters (Full Stack Data Science)
pwskills.com/course/Data-Science-masters (Hindi)
pwskills.com/course/Data-Science-Masters (English)
Data analytics course kab start hoga
One video in the Java playlist is hidden. Kindly public the video so that we can learn more and can take advantage of it.
for those who did not get how the time complexity of nested loop is O(n)
we calculate the time complexity of nested loop :- by finding how many time the inner loops are running for nth value of outermost loop
here the outer loop will almost run for n-1 time maximum as the pivot is fixed so array length -1
now we will count the number of iterations of inner loop
since first while loop checks the condition if arr[i]
1:17:10
static int partition2(int[] arr, int start, int end) {
Random random = new Random();
int randomIndex = random.nextInt(end - start + 1) + start;
// Swap the random pivot element with the first element to improve worst case
swapElements(arr, start, randomIndex);
int pivot = arr[start];
// now the pivot is on start index so check the elements after pivot are they smaller or larger or equal to pivot
int i = start + 1;
int j = end;
while (i
time compexity dimaag ke upr se ja rha he 🤕🤕
😂😂
Thank for this beautiful lecture maanvi maam
Thank You Mam ❤❤❤
Thank you Mam,
You are amazing ❤❤
great explanation mam
Mam, mein leetcode per question try kar raha hu ,basically Maine array se chalu kiya,lekin logic or code dono nahi bana pa raha hu , consistent hu lekin jab logic nahi banta to motivation down ho jata hai mam
abi bi h kya consistent
@@Luffy_2804 hey listen I have seen you consistent would you like to clear my doubts ?
@@uchako7219please tell your doubt
mam very outstanding explanation
When will be the lectures, lesson plans, assignment and solutions be uploaded?
Thanks ma'am
Thank you mam
For Sorting in Descending Order, what to do????
Notes are not available please provide through a link and the provided link is invalid. Fix it
Mam but java to pass by value leta hain to alag stack frame main elements ko manipulate karke ap sorted array kaise la rahe ho ?
bro aap first year ho?
Bhai tu chod de DSA ,jaake pehle basics clear kr fir idhar aana,
But array is pass by reference
@@nucle0981 308
Everything in Java is passed by value. In case of an array which is nothing but an Object, the array reference is passed by value just like an object reference is passed by value.
reference pass hota hai jo orignal array ko point karta h or jab recursion call hoti h to new array banta hai par vo bi same hi object ko point kar rha hota isliye jab method call hoti h to array update ho jata h
Data analytics course kab tak start hoga
public class Quicksort {
static void printArray(int arr[]){
for(int val : arr){
System.out.print(val+" ");
}
System.out.println();
}
static void swap(int arr[],int x,int y){
int temp= arr[x];
arr[x]=arr[y];
arr[y]=temp;
}
static int partition(int arr[],int start,int end){
int pivot =arr[start];
int cnt = 0;
for(int i= start+1;i=end){
return;
}
int pi = partition(arr, start, end);
quickSort(arr, start, pi-1);
quickSort(arr, pi+1, end);
}
public static void main(String[] args) {
int arr[] = {2,4,33,8,6,43,5};
System.out.println("array before sorting");
printArray(arr);
int n=arr.length;
quickSort(arr,0,n-1);
System.out.println("array after sorting");
printArray(arr);
}
}
Mam, crystal clear explanation
Mam react sikhna h
Can anyone find an error I am not getting expected result
static int partition(int[] arr,int start,int end) {
int pivot = arr[start];
int cnt = 0;
for(int i = start + 1;i pivotIdx) {
swap(arr,i,j);
i++;
j--;
}
}
return pivotIdx;
}
static void quickSort(int[] arr,int start,int end) {
if(start >= end) return;
int pi = partition(arr,start,end);
quickSort(arr,start,pi - 1);
quickSort(arr,pi + 1,end);
}
which error you are getting
if we take 5 4 3 2 1 it is giving 1 4 3 2 5
Really
Time and space complexity smjh hi nahi aarha 😢
day 9 of being consitent :(
👍
👍👍👍
lectures are too long😵😵😵😵
kuch samaz nahi aaya
Thank you Mam