O(3^n) exponential time complexity [closed]

To be honest, if you feel like showing the guys teaching your course that their problem statement probably isn’t what they intended, I would just do it this way:

for(int i = 0; i < c; i++) { /*your code here*/}

This is in O(c), and since O(c) is a strict subset of O(ck) for k > 1, it’s also in O(ck). That’s probably not what the people teaching your course intended, they probably want you to write a loop that runs in Θ(ck).


On another note:

ck and 3n are not the same thing. Assuming the length of your input is n, ck is constant time while 3n is exponential time. Assuming the length of your input is c, ck is polynomial while 3n is constant. Assuming the length of your input is k, ck is exponential while 3n is constant.

Leave a Comment