You are a legend. Even almost ten years later, your explanation is the best.
@AruneshSrivastava5 жыл бұрын
Before watching this , i watched 2 other videos on similar issue , dint understand a damm thing , then i just see this video's link on suggestions and i smiled . The complexity of the problem doesn't bother you if you have a good teacher. Thanks man
@findoc92823 жыл бұрын
as I keep learing and comparing I realize how energy saving it can be with a good teacher/tutotial
@excitingmonkey39703 жыл бұрын
Man you are awesome! I was Leetcoding, got stuck in understanding the solution and searched for explanation. And here i am , mindblown by how simple you made me understand.
@RaoVenu9 жыл бұрын
Thanks for the great tutorial. My implementation (assuming we already have implementations for findRotations and binary search in place) CircularArraySearch(A, n, x) { lowIndex = findRotations(A, n) // Index of lowest value in circular sorted array O(lgN) //Now we have two cases. The array to left of lowIndex is sorted. And the array to the right(including lowIndex is sorted) if (x == A[lowIndex]) return lowIndex // O(c) else if (x > A[lowIndex]) return BST(A, lowIndex + 1, n, x) // O(lgN) else return BST(A, 0, lowIndex - 1, x) //O(lgN) }
@S__Arslaan2 жыл бұрын
Amazing!!!No other youtube channel matches your level of explaination!!!!Thanks mycodeschool
@Aggarwal_Anshul5 жыл бұрын
Such an Efficient & Simple Solution to a tricky problem! Fantastic explanation BIG THANKS!
@mycodeschool12 жыл бұрын
Thanks !
@Guillermorosales9 жыл бұрын
Thank you very much!!! for this series of videos, you explained it very well.
@Joyddep5 жыл бұрын
Exactly what I was looking for. Thank you for your excellent content!
@StartDeutsch9 жыл бұрын
Hi! What do you use for writing? A tablet or what? Looks very good! Thank you
@yunususmani32947 жыл бұрын
Can't thanks enough...... You just saved my night :) Thanks a lot :)
@SaumyaSharma0073 жыл бұрын
Thank you so much....The evergreen lectures 🌟👌
@codingandmathvideos10 жыл бұрын
great tutorial! you simply rock!!! God bless you. You probably should adjust the way you calculate the middle index. If you add 2 big positive numbers or 2 big negative numbers for that matter, you can get overflow. Use mid = low + (high - low)/2 instead to get the index of the middle element.
@AbhijithVMohan10 жыл бұрын
In typical system, overflow will only happen if the array has about 2**30 integers. In that case, the array itself will take ~4 GB space.
@saiadityagedda6 жыл бұрын
He already mentioned about that in his initial lecture
@S__Arslaan2 жыл бұрын
not if u use python
@saileshverma19423 жыл бұрын
Thank you for your excellent teaching
@siddharthasharma93163 жыл бұрын
as you mention that a circular sorted array with Distinct elements in description part of this problem , we can also skip equal sign- Array[mid] < Array[high] and same for Array[mid] > Array[low].
@siddharthasharma93163 жыл бұрын
and thanks for such nice explanation.
@adityagupta63389 жыл бұрын
Hey, thanks for this. It really helps. I want to just verify my approach is correct. How about we find the pivot using the previous tutorial, figure out which sorted array it belongs to (left of pivot or right of pivot) and apply binary search to whichever direction of pivot x belongs to? The time complexity is still 0 (log n), right?
@allanbee575210 жыл бұрын
Hi, Firstly, you are doing amazing job. Your teaching skills are superb!! Can you please share your algorithm approach to print all the permutations of a string? String length could be any length. e.g. abc, acb, bac,bca, cab,cba.
Thanks for your great effort You are an excellent teacher
@bharathrajakumar18239 жыл бұрын
Simple and easy to understand. Thank you !!!
@jalajkhajotiaiitr11 жыл бұрын
Thanks for your work sir, it is really helpful
@bhoopendrasharma94744 жыл бұрын
Excellent tutorial, Thanks a ton. I believe this will work for duplicates as well, especially for the example shown in the tutorial { 2, 2, 2, 2, 2, 0, 2, 2 }. I tried it and found working.
@stym066 жыл бұрын
best explanation ever.
@yuvarajravi78496 жыл бұрын
Great tutorial. Other approach is just keep comparing first and last elements. Say if i=1, j=n-1, perform if a[i]
@harshbaliyan58674 жыл бұрын
O(n) complexity still
@piyushjindal49559 жыл бұрын
simple and nice explanation :)
@vramali18 жыл бұрын
I am finding it hard to understand the code. I think i need a lot of example use cases for each of the conditions applied in the code.
@salemouail6274 жыл бұрын
Write it write it write it
@nobody29372 жыл бұрын
Thank you very much... Thank you ...
@sawyerford21913 жыл бұрын
How you were able to return the index value without returning it
@saisudheermittapalli5748 жыл бұрын
Looks like you are not returning any value from CircularArraySearch() function in success case (when x is part of array)
@unknownman14 жыл бұрын
mid is returned
@401varun10 жыл бұрын
Very nice.. this code is for ascending array rotations.. but doesn't work for descending array rotations... kindly generalize for both.. working for : {4,5,1,2,3} ---> initial array {1,2,3,4,5} rotated twice right . not working for : {5,4,8,7,6} --> initial array {8,7,6,5,4} rotated twice right. Thanks :)
@kiranmahesh936 жыл бұрын
same here
@dangidelta5 жыл бұрын
Just change every '' and vice-versa. It should work just fine.
@prs3148 жыл бұрын
have you considered the possibility of (low + high) overflowing in "int mid = (low + high) / 2"? Since int is signed the (low + high) will give an undefined behavior in C++ or a negative number in Java. I think the better way would be to cast them to unsigned int and shift. int mid = ((unsigned int) low + (unsigned int) high) >> 1;
@adarshverma33722 жыл бұрын
One of the variation can be achieved using below code: private static int searchNumberInCircularSortedArray(int []inputs, int numberToSearch, int startIndex, int endIndex) { if (startIndex > endIndex) return -1; int mid = (startIndex + endIndex) / 2; if (inputs[mid] == numberToSearch) return mid; if (inputs[mid] = numberToSearch) return searchNumberInCircularSortedArray(inputs, numberToSearch, mid + 1, endIndex); return searchNumberInCircularSortedArray(inputs, numberToSearch, startIndex, mid - 1); } else { if ((inputs[mid] > numberToSearch && numberToSearch
@krushnnabaviskar21702 жыл бұрын
Completed playlist
@sdhupar9 жыл бұрын
If array has duplicate elements then we can still apply Binary Search
@WhisperingWalnuts9 жыл бұрын
saurabh Dhupar yes, i tried the code by giving array with duplicate elements as input, and it works!!! Simple and great algo!!
@artyzach8 жыл бұрын
but wouldn't it only show the index of the first occurrence of duplication?
@dangidelta5 жыл бұрын
A recursive approach : int CircularlySorted(int Array[ ], int first, int last, int value){ if(first > last) return -1; int m = first + (last - first)/2; if(Array[m] == value) return m; else if(Array[m] = Array[first]){ if(Array[m] < value) return CircularlySorted(Array, m+1, last, value); return CircularlySorted(Array, first, m-1, value); } else if(Array[m] = Array[first]) return CircularlySorted(Array, first, m-1, value); return CircularlySorted(Array, m+1, last, value); } }
@Sohanbadaya9 жыл бұрын
public int searchItem(int arr[], int item){ int low = 0; int high = arr.length-1; while(low arr[mid] && item
@srkrohit9 жыл бұрын
+Sohan badaya The authenticity of this code is only valid if the segment is sorted otherwise not. "if(item > arr[mid] && item
@Sohanbadaya9 жыл бұрын
+Rohit Kumar You are right Rohit. Thanks :)
@omkarkulkarni32075 жыл бұрын
// Search an element in rotated/circular array. public static int findElementInCircularArray(int[]a, int n, int x) { int pivot=findRotationCount(a,n); if(x==a[pivot]) { return pivot; } if(x> a[0]) { //Search in sub-array left of the pivot return binarySearchRecursive(a,0,pivot-1,x); } else { //Search in sub-array right of the pivot return binarySearchRecursive(a,pivot+1,n,x); } }
@yashtailor15434 жыл бұрын
love you @mycodeschool
@mayuraggarwal58405 жыл бұрын
This solution will not work if the element to be searched is present in unsorted part of the array.