+ 3

How can we reduce time complexity of programmes

Just to reduce O(n^2) to O(n)

24th Aug 2019, 3:19 AM
Hamza Rarani
Hamza Rarani - avatar
4 Answers
+ 6
We will need to look at the code for that purpose. The complexity of some algorithms simply cannot be reduced, possibly because it's already optimal for that particular task.
24th Aug 2019, 4:38 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
One example for moving from O(n) to O(log n) is to use a binary rather than a linear search on a sorted array.
24th Aug 2019, 5:23 AM
Sonic
Sonic - avatar
+ 3
That depends on your code. Sometimes it is enough to choose the right data structure (eg. set instead of list). At other times you need to implement a completely different algorithm to get big O down.
24th Aug 2019, 4:38 AM
Thoq!
Thoq! - avatar
+ 3
In simple way use minimum variable as far as possible and loops too.
24th Aug 2019, 5:53 AM
Abhishek Kushwaha
Abhishek Kushwaha - avatar