A brief conversation about big O
To be honest with you, when I first got into programming I procrastinated learning Big O for quite a wh...
For further actions, you may consider blocking this person and/or reporting abuse
Great post! Not sure if I'm getting something wrong, but in your object example, should't it be like this
Also, in your code what happens if
targetNum < list[i]
(this would happen in your given example array above[1,2,3,4,9,6]
and target number 8) on line 28:I'm not sure if I am getting your question but will return to it later, I'm not sure if I am seeing the behavior you mention running that example though? Screenshot below...will try to remember to revisit this and get back to you later on
I think it's correct in your code, but wrong in the example you have given. And with my comment regarding line 28 I was referring to the second (optimized) version of the code. So, not the screenshot you posted as a reply, but the next one.
Great article, thanks!
Regarding the code challenge example, keep in mind that the solution with hash map requires
M(n)
additional memory, while theO(n^2)
solution requiresM(1)
memory. So this is a trade-off; there might be cases where it would not be possible to fit all the data in memory, and you would have to use the algorithm that is less effective in terms of CPU.Writing this for new people, I chose to skip memory entirely in introducing the concepts since in my (long) career I have so relatively rarely hit space vs time constraints. Appreciate this point, but definitely was deliberate to skip some finer points in this which was written for pure newbies :) (actually originally wrote it for some mentees who are a few months into learning to code)
@citizen428 I thought of this immediately when I saw the post, you beat me to the punch ;) It's so good.
Oh my god I love this haha!
Thanks
Great job! Thanks a lot for this!
Really well explained, thanks you
Am I missing something? The quadratic example given seems linear to me. If there are 5 tasks in each house, 5 is a constant, so the complexity is O(5N) which is considered equal to O(N). That N happens to be 5 in the example is irrelevant.
It would be O(N^2) if the number of tasks grew with the number of houses (e.g. 1 task per house if there is only one house, but 5 tasks per house if there are 5 houses, i.e. f(1)=1 and f(5)=25).
What are the rule of using Big O notation? كيفية جلب حبيب