Computer Science › Comparing Run Times
Consider the following code:
What is the expected runtime of the code (in Big-O notation?)
Consider the following code:
What is the run time of the code (in Big-O notation?)
Consider the following code:
What is the run time of the code (in Big-O notation)?
for( int i = 0; i < n; ++i){
for( int j = 1; j < n; j *= 2){
someFunction();
}
}
For the code above, what is the run time in Big O notation?
What is the BigO of the following function?
public void bigO(int[][] m)
{
if (m.length > 2)
{
for (int i = 0; i < m.length - 1; i++)
{
for (int j = 0; j < m[i].length; j++)
{
System.out.println(m[i][j]);
}
}
}
else
{
for (int j = 0; j < m[0].length; j++)
{
System.out.println(m[0][j]);
}
}
}
Consider the following code:
What is the run-time of the code (in Big-O notation?)
Which is more efficient?
a)
arr = [0, 1, 2, 3]
for (int i = 0; i < arr.length; i++) {
int j = 0;
if (j == arr[i]) {
j++;
}
}
b)
ArrayList<Integer> arL = new ArrayList<Integer>();
arL.add(0);
arL.add(1);
arL.add(2);
arL.add(3);
for (int i = 0; i < arL.size(); i++) {
int k = 0;
if (k == arL.get(i)) {
k++;
}
}
True or False.
The code snippet A has a more efficient running time than code snippet B.
(A)
for (int i = 0; i < 25; i++) {
for (int j = i; j < 25; j++) {
}
}
(B)
for (int i = 0; i < 25; i++ {
for (int j = 0; j < 25; j++) {
}
}
Which is more efficient (i.e. Lower Big O)?
arr = \[1, 2, 3, 4, 5, 6, 7, 8\]
arr2 = \[\[1,2\],\[3,4\],\[5,6\], \[7,8\], \[9,10\], \[10, 11\]\]
for (int i = 0; i < arr.length; i++) {
for (int j = i; j < arr2.length; j++) {
arr\[i\]\[j\] = 0;
}
}
arr = \[1, 2, 3, 4, 5, 6, 7, 8\]
arr2 = \[\[1,2\],\[3,4\],\[5,6\], \[7,8\], \[9,10\], \[10, 11\]\]
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr2.length; j++) {
arr\[j\] = 0;
}
}
Which has faster compile time, O(N), O(N2), O(N3), or O(NlogN)?