Last active
September 20, 2021 04:26
-
-
Save suragch/ae85c4cc737fee46b2abecd18394763a to your computer and use it in GitHub Desktop.
Homework from September 20, 2021
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Homework | |
/// | |
/// Give me an example of: | |
/// | |
/// 1. Constant time - O(1) | |
/// 2. Linear time - O(n) | |
/// 3. Quadratic time - O(n2) | |
void main(List<String> arguments) { | |
final startTime = DateTime.now(); | |
// constantTime(15); | |
// linearTime(23); | |
quadraticTime(5); | |
final endTime = DateTime.now(); | |
print(endTime.difference(startTime)); | |
} | |
// 1. Constant time | |
void constantTime(int input) { | |
print(3 * input); | |
} | |
// 2. Linear time | |
void linearTime(int number) { | |
var total = 0; | |
for (var i = 1; i <= number; i++) { | |
total = total + 1; | |
} | |
print(total); | |
} | |
// 3. Quadratic time | |
void quadraticTime(int number) { | |
var total = 0; | |
for (var i = 0; i <= number; i++) { | |
for (var j = 0; j < number; j++) { | |
total = total + 1; | |
} | |
} | |
print(total) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment