Howdy, I'm Mike. I'm a software engineer from the United States. I make concise computer science tutorials to help you learn, review for exams, and prep for interviews.
My background: I have a bachelor's and master's degree in computer science from Georgia Tech. I'm a principal software engineer for Workday, and I previously worked for AWS, Intuit, and IBM.
Thanks for the explination. I wanted to point out that you can right much more effecient code: for i = 0 to n-1 for j = 0 to n-i-2 if array[j] > array[j+1] swap(array[j], array[j+1])
in case 3, you violate the rules for every path from a node to an abitary leave, number of nodes remains the same, which is 2 if we start from A to C (C and his null), and 1 from A to Z (his null only)
hmmmm so you say to iterate through the arrays you want to get and compare to the previous index by doing i - 1 you want to know that the index exists so you compare that its greater than 0 then you want to check if the previous is greater than the current and if so then you have to swap afterwards you would want to shift the elements to the right and finally insert the current element into the correct position? So something like this idk and i = 2 as we are comparing the previous and there is no previous of the first index (or 1 if your language supports 0 as an index) local arr = {7,9,4,0,2}; function sort(arr) for i = 2, #arr do local current = arr[i]; local j = i - 1; while(j > 0 and arr[j] > current)do arr[j + 1] = arr[j]; j = j - 1; end arr[j + 1] = current; end end I think its cool that the more I learn, the easier the visualization of imagery and words can be translated into syntax
If we drop the constants, like 3 * O(1) and interpret it as O(1), why is N * O(1) is O(N)? Doesnt it mean that it is not for 3, even if it is a 1000, it is still a constant and if it is 1000 * O(N) we can still drop the 1000? Can someone please explain?
I've got a dumb question which is why is the running time of build_max_heap O(n), n = len(a)? (refer to 5:29). In my opinion, the for loop is O(n) and inside each for loop is O(logn) to call max_heapify so in total, the time complexity would be O(nlogn), right?
I think you made a mistake because we have to choose any one of the nodes which have the minimum value after the visited node and we cannot see the visited node again until we visited all the nodes