david-kariuki / ace-the-java-coding-interview Goto Github PK
View Code? Open in Web Editor NEWJava project to learn advanced Data Structures and Algorithms
License: MIT License
Java project to learn advanced Data Structures and Algorithms
License: MIT License
Compute the big O complexity of the code snippet given below.
public static void main(String[] args) {
int n = 10;
int sum = 0;
int j = 1;
double pie = 3.14;
for (int var = 0; var < n; var++) {
System.out.println("Pie: " + pie);
while(j < var) {
sum += 1;
j *= 2;
}
}
System.out.println("Sum: " + sum);
}
Problem Set 1 - 6
Compute the Big O of an algorithm that involves nested loops, and increments the loop variables through multiplication.
public static void main(String[] args) {
int n = 10; // O(time complexity of the called function)
int sum = 0; //O(?)
double pie = 3.14; //O(?)
int var = 1; //O(?)
while(var < n) {
System.out.println("Pie: " + pie); //O(?)
for (int j = 0; j < var; j++) {
sum++; //O(?)
}
var *= 2; //O(?)
} //end of while loop
System.out.println("Sum: " + sum); //O(?)
}
A basic exercise based on the Big(O) of an algorithm that involves nested loops and the loop variables increment with multiplication.
public static void main(String[] args) {
int n = 10; // O(time complexity of the called function)
int sum = 0; //O(1)
double pie = 3.14; //O(1)
int var = 1; //O(?)
while(var < n) {
System.out.println("Pie: " + pie);
//O(?)
for (int j = 1; j < n; j = j + 2) {
sum++;
}
var *= 3;
} //end of while loop
System.out.println("Sum: " + sum); //O(1)
}
Compute the Big O complexity of the code snippet given below.
public static void main(String[] args) {
int n = 10;
int sum = 0;
double pie = 3.14;
for (int var = 0; var < n; var++) {
int j = 1;
System.out.println("Pie: " + pie);
while(j < var) {
sum += 1;
j *= 2;
}
} //end of for loop
System.out.println("Sum: " + sum);
}
Compute Big(O) of an algorithm that involves nested loops and the loop variables decrement.
public static void main(String[] args) {
int n = 10; // O(time complexity of the called function)
int sum = 0; //O(1)
double pie = 3.14; //O(1)
//O(?)
for (int var = n; var >= 1; var = var - 3) {
System.out.println("Pie: " + pie);
//O(?)
for (int j = n; j >= 0; j = j - 1) {
sum++;
}
} //end of outer for loop
System.out.println("Sum: " + sum);//O(1)
}
Compute the Big O complexity of an algorithm that involves nested loops where the loop variables increase with addition.
public static void main(String[] args) {
int n = 10;
int sum = 0;
double pie = 3.14;
for (int var = 0; var < n; var = var + 3) {
System.out.println("Pie: " + pie);
for (int j = 0; j < n; j = j + 2) {
sum++;
System.out.println("Sum = " + sum);
}
}
}
Compute the Big O complexity of the code snippet given below. It is better to solve it on a piece of paper, and then see if your answer matches the correct option!
public static void main(String[] args) {
int n = 10; //O(1)
int sum = 0; //O(1)
int j = 1; //O(1)
double pie = 3.14; //O(1)
//O(?)
for (int var = 1; var < n; var += 3) {
System.out.println("Pie: " + pie);
j = 1;
while (j < n) { //O(?)
sum += 1;
j *= 3;
}
}
System.out.println("Sum: " + sum); //O(1)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.