Data Structure and Algorithm Sample Questions
Data Structure and Algorithm Sample Questions
Problem 2
Problem 2
Find the time complexity of the following code snippets
Problem 3
Find the time complexity of the following code snippets
Problem 4
Find the time complexity of the following code snippets
int i = n;
while(i){
cout << i << " ";
i = i/2;
}
Problem 5
Find the time complexity of the following code snippets
if(i > j ){
j>23 ? cout<<j : cout<<i;
}
Problem 6
Find the time complexity of the following code snippets
Problem 7
What is the time & space complexity of the following code:
let a = 0, b = 0;for (let i = 0; i < n; ++i) {
a = a + i;
}
for (let j = 0; j < m; ++j) {
b = b + j;
}
Problem 8
What is the time & space complexity of the following code:
let a = 0, b = 0;
for (let i = 0; i < n; ++i) {
for (let j = 0; j < n; ++j) {
a = a + j;
}
}
for (let k = 0; k < n; ++k) {
b = b + k;
}
Problem 9
What is the time and space complexity of the following code:
let a = 0;
for (let i = 0; i < n; ++i) {
for (let j = n; j > i; --j) {
a = a + i + j;
}
}
Problem 10
What is the time complexity of the following code:
for (let i = n; i > 0; i = parseInt(i / 2)) {
console.log(i);
}
Problem 11
What is the time complexity of the following code:
for (let i = 1; i < n; i = i * 2) {
console.log(i);
}
Problem 12
What is the time complexity of the following code:
for (let i = 0; i < n; ++i) {
for (let j = 1; j < n; j = j * 2) {
console.log(j);
}
}
Problem 13
Explain any four approach to algorithm design