Professional Documents
Culture Documents
BigOnotationquestionsandanswers|JavaSuccess.com
Java-Success.com
Register
Login
Logout
Contact
uTube
600+ Java Interview Questions Answered with lots of dagrams & code
Go
searchhere
Home
QuickPrep
Can u Debug?
600+ Q&A
Judging Experience
Java Career
Spring Tutorials
Tutorials
Membership
Java 8 Tutorials
Web
Other
CVs
Top X
Tools
Free content
Home Written Tests Java Data Structures & Algorithms Big O notation Big
O notation questions and answers
Big O notation
questions and answers
Posted on May 6, 2015 by akumaras
600+ Java/JEE
Q&A
open all | close all
Q1. What do you know about the big-O notation and can
you give some examples with respect to dierent data
structures?
A1. The Big-O notation simply describes how well an
algorithm scales or performs in the worst case scenario as
the number of elements in a data structure increases. The
Big-O notation can also be used to describe other behavior
such as memory consumption. At times you may need to
choose a slower algorithm because it also consumes less
memory. Big-o notation can give a good indication about
performance for large amounts of data, but the only real
way to know for sure is to have a performance benchmark
with large data sets to take into account things that are not
considered in Big-O notation like paging as virtual memory
usage grows, etc. Although benchmarks are better, they
arent feasible during the design process, so Big-O
complexity analysis is the choice.
The algorithms used by various data structures for dierent
http://www.javasuccess.com/bigoquestionsandanswers/
5/27/2015
BigOnotationquestionsandanswers|JavaSuccess.com
http://www.javasuccess.com/bigoquestionsandanswers/
2/7
5/27/2015
BigOnotationquestionsandanswers|JavaSuccess.com
Java Career
open all | close all
Beginner or Intermediate?
Did you get the Job oer?
Earning More
Feeling stagnated?
Freelancing & job security
3/7
5/27/2015
BigOnotationquestionsandanswers|JavaSuccess.com
packagebigo;
importjava.util.Arrays;
publicclassInsertingElementsToArray{
publicstaticvoidinsertUnsortedArray(String
String[]unsortedArray={"A","D","C"
Java Tutorials
open all | close all
Setting up Tutorial
Tutorial - Diagnosis
JEE Web & Web Services Tutorial
JSF Tutorial
SQL Tutorial
JDBC Tutorial
Hibernate Tutorial
Spring Tutorial
Spring batch tutorial
Drools Tutorial
JMeter Tutorial
Core Java Tutorial
Debugging Tutorial
DOS Tutorial
ESB Tutorials
FIX and Java Tutorial
JasperReport Tutorial
Java 8 Tutorial
JSON and Java Tutorial
JAXB Tutorial
JMX Tutorial
JPA-Hibernate-Spring Tutorial
JPA Tutorial
Logging and auditing Tutorial
Maven Tutorials
Metrics Tutorial
Productivity Tools Tutorial
Spring ORM Tutorial
Spring other tutorial
Spring OXM Tutorial
Unix Tutorial
XML and Java Tutorial
CSV and Java Tutorials
String[]newUnsortedArray=newString[
System.arraycopy(unsortedArray,0,newUnsortedArray
newUnsortedArray[newUnsortedArray.length
System.out.println(Arrays.toString(newUnsortedArray
}
http://www.javasuccess.com/bigoquestionsandanswers/
4/7
5/27/2015
BigOnotationquestionsandanswers|JavaSuccess.com
publicstaticvoidmain(String[]args){
insertUnsortedArray("B");
}
}
packagebigo;
importjava.util.Arrays;
publicclassInsertingElementsToArray{
publicstaticvoidinsertSortedArray(StringtoInsert
String[]sortedArray={"A","C","D"
/*
*Binarysearchreturnstheindexofthesearchitem
*iffound,otherwisereturnstheminusinsertionpoint.Thisexample
*returnsindex=2,whichmeanstheelemntisnotfoundandneedsto
*beinsertedasasecondelement.
*/
intindex=Arrays.binarySearch(sortedArray
if(index<0){
//arrayindicesarezerobased.2indexmeansinsertionpointof
//(2)1=1,soinsertIndex=1
intinsertIndex=index1;
String[]newSortedArray=newString
System.arraycopy(sortedArray,0,newSortedArray
System.arraycopy(sortedArray,insertIndex
newSortedArray,insertIndex
newSortedArray[insertIndex]=toInsert
System.out.println(Arrays.toString(newSortedArray
}
}
http://www.javasuccess.com/bigoquestionsandanswers/
5/7
5/27/2015
BigOnotationquestionsandanswers|JavaSuccess.com
publicstaticvoidmain(String[]args){
insertSortedArray("B");
}
}
Unless you have lots of inserts in the front and middle and
the performance bench marks clearly shows that LinkedList
is the way to go, it is better to use an ArrayList.
http://www.javasuccess.com/bigoquestionsandanswers/
6/7
5/27/2015
BigOnotationquestionsandanswers|JavaSuccess.com
Categories (mobile)
SelectCategory
Reviews
"I have read several technical books over the last few years, but this one was entirely dierent...." - By Meera Subbarao IT Book Zone
Team Leader
I used this to get 6 jobs in 2 weeks -- Vinodh Eth
Broad and insightful. Will raise your exp a few levels even if only half is read . -- by Grant Dawson
2015 Java-Success.com
http://www.javasuccess.com/bigoquestionsandanswers/
7/7