big-o


Why this code gives big-O = O(1)


public static LinkedList third(int[] array){
LinkedList retval = null;
for (int i = 0; i < 999 && i < array.length; i = i + 1) {
retval = new LinkedList(array[i], retval);
}
return retval;
}
Why this code gives big-O = O(1) ?
Because the loop will be executed maximally 999 times which is a constant value therefore You can think of it as it's O(999) = O(1) = O(c), where c is a constant value.
If the value of i wouldn't be limited by 999, the loop would be executed array.length times and the complexity would be O(n), where n is the size of input array.

Related Links

Time complexity of nested for loop?
Is O(log(n*log n) can be considered as O(log n)
Time complexity of recursive algorithms with branches of different complexity
What is the difference between O(1) and Θ(1)?
Time complexity (in big-O notation) of the following code?
LSM Tree lookup time
The time complexity of O(nⁿ) and O(n!)
O notation using pseudocode
Why is multiplication n^2 time?
What is growth function and order where inner loop variable is multiplied by 2
Big O time complexity for nested j = i + 1 loop
How to calculate the running time of this algorithm?
Big-O Notation and coding
Either f(n) = O(g(n)) or g(n) = O(f(n))
Is an algorithm with asymptotic runtime complexity of θ(n) always faster runtime than a similar algorithm with runtime complexity of θ(n^2 )?
Best case of quick sort variation

Categories

HOME
sonarqube
phantom-dsl
xml
pda
rsa
fftw
error-handling
appcelerator
simulink
polling
retrofit2
webix
accessibility
mql5
g++
reactive-programming
android-securityexception
activecollab
filechannel
plink
parameter-passing
html5-appcache
connector
breadth-first-search
googlebot
react-toolbox
perlbrew
xcode-ui-testing
nstimer
genexus-sd
failover
magento-1.8
corenlp-server
apiary.io
git-rewrite-history
loading
tasm
trigonometry
watchface
odoo-website
linqpad
ssrs-2014
placeholder
android-exoplayer
apache-directory
vaadin-charts
facebook-social-plugins
optimizely
ntvs
cnc
reindex
truezip
colorbar
cup
mouseleave
flyout
rxtx
gets
grails-plugin
omxplayer
seek
dup
http-status-code-401
omniauth-facebook
lua-telegram-bot
php-socket
sklearn-pandas
ikiwiki
fuzzywuzzy
nupic
jaunt-api
relativelayout
spring-retry
lazybones
binomial-theorem
vacuum
baasbox
snackbar
kubuntu
xmltype
openbabel
procedural-programming
packet-sniffers
mruby
android-vibration
linkedin-jsapi
live555
functional-java
dct
menubar
square-bracket
clickbank
spring-3
scriptaculous
visual-studio-express
breakout
code-duplication
route-provider
pclzip
actiondispatch
pagedown
server-administration
robotlegs
wcf-configuration
flex-mobile
jquery-tools
timertask
load-time
nstokenfield

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App