+ 2
[SOLVED]what does this mean in/to programming logics O(N^2)
i always see this expression around but i don't kind of understand, even after reading about it on Google it seem am now confused the more. please guru's help me understand this with your explicit explanation and the best which is better than google. thanks in advance for your kind gesture...😎😎😎
6 Antworten
+ 5
thanks everyone;
+ 3
O(N^2) represents an algorithm whose performance is directly proportional to the square of the size of the input data set. This is common with algorithms that involve nested iterations over the data set (src: Internet)
The above definition comes from the Big O notation - a tool aiming at assessing the complexity of algorithms thus their efficiency and effectiveness.
Nobody is going to waste time explaining stuff which is very well explained in the Internet.
However if you're new to programming - forget it until reaching at least a good solid intermediary programming skills
+ 2
I did a write-up on it that probably goes into more detail than necessary.
https://code.sololearn.com/WS8SBRFRVxcn/?ref=app
+ 1
It is one of big O notation that talks about time complexity(speed) and space complexity (memory).
When it comes to speed it is graph between number of operation (y-axis) and number of element (x-axis) on which that operation is performed.
In O(N^2), N depends on number of elements on which operation is performed.
If we don't know on how many elements we are going to perform the operation we simply represent it with N.
And square on that N just tells us that it is nested for loop. since for each element that we have we are looping through every element.
For example if we have 3 elements in array [a, b, c]. and if we want to add each element to every element in that array like
[a+a, a+b, a+c, b+a, b+b, b+c, c+a, c+b, c+c]
Then we will have O(N^2) Big O.
Since in order to do these we are looping through each element, total number of element in that array number of times. That is 3X3.
3 total number of elements
Another 3 no of loops for each element.
+ 1
O(N^2) is worst you should avoid it. See following link for reference.
http://bigocheatsheet.com