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

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
Big O - Nested loops
Is the big o for the following O(n^2*log(n)) or O(n^3*log(n))
Confusion around Big-O with natural logs [closed]
Building a recurrence relation for this code?
Usage of Little-O notation
time complexity of the following algorithm
What is the Big O for the difference of two sorted lists [closed]
Big Oh Classification [closed]
Prove max(O(f(n)), O(g(n)))=O(max(f(n), g(n))

Categories

HOME
alexa-skills-kit
powerpoint
numbers
apache-spark-mllib
jsf-2.2
solver
r-googlesheets
interpolation
x264
mapbox
pattern-matching
openpyxl
angular-dart
radgridview
coin3d
atlassian-stash
fileserver
xmonad
cfml
spring-async
pchart
perlbrew
windows-server-2003
stackexchange
winexe
testbed
spring-security4
simplecv
openwhisk
nested-lists
installscript
apns-php
p4merge
c9.io
tcc
knime
clang++
uiimage
oim
xbmc
ntvs
tinymce-3
insight
posixct
remedy
payara-micro
mathcad
vibrate
reachability
xcode-server
synonym
vorpal.js
project-organization
thread-sleep
inf
ess
viola-jones
adehabitathr
mass-assignment
at-job
human-computer-interface
mobility
mutual-authentication
websphere-esb
gae-quotas
bin
visual-studio-express
ebay-lms
midlet
pstack
fragmenttransaction
boost-msm
fusefabric
josql
entity-attribute-value
denied
workflow-services
filemerge
qglwidget
cruisecontrol.rb
duplex
silverlight-oob
technical-debt
wcf-proxy

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