Posts

Cycle Sort || Java + DSA course || Blog 14

Image
W e learnt about Sorting algorithms like bubble sort, insertion sort, selection sort in Blog 9 Sorting in Java . So why are we learning cycle sort in a new blog?  Cycle sort questions are asked in various tech interviews , in huge companies like Facebook , Amazon , Google ... For a quick overview, we will be learning:- W hat is C yclic sort ?   How to solve Code Working of the code. What is cyclic sort? Cyclic sort is used on an array from 1 to n or from 0 to n. In 1 to n case, we know that our first value will be 1 followed by 2 3 4...n. if we try to place it at index 0(in java, index of an array starts from 0) we know value is 1 which can be also said as index+1 = 0+1 = 1. At index 1, 2 should be placed = index+1 = 1+1 = 2. This should keep on happening till nth value becomes n+1. If we want a formula for index, it is index = value - 1 since every value has index+1 index. How to solve Lets take array = {3,5,1,2,4} Correct index value should be arr[i]-1 We will check if our ...

Space and Time Complexity in Detail || Java + DSA Course || Blog 13

Image
E very computer has a different processor, so algorithm can take different time to execute . So, Time complexity doesn't talk about the time taken by the algorithm. Instead, it considers how many times each statement executes. For a quick overview, we will be looking at: What is Time complexity? Solving Time complexity Big O Notation Big Omega Notation Theta Notation Little O Notation Little Omega Notation Space Complexity What is Time Complexity? Time Complexity tells us how the time is going to grow depending on its input so we can estimate value at any point. This is the Graph of Different Time complexities: Here, O(1) is constant time complexity. It means your time will remain constant at every input length. O(log n) is the time complexity used by Binary search(algorithm used to search a value in a sorted array). It starts to curve at a certain point. The more the input, the less time Taken. O(n) is the time complexity used by Linear search (algorithm used to search a value i...