Why do you think a programmer should care about space and time complexity?

ANS

time and space complexity are important when developing programs, as you don't want your programs to consume too much memory, or take too long to complete. Basically, managing complexity and time of programs is essential when developing programs for user usage. You don't want your programs to consume too much of a users memory or take too long basically.

Do you think this is a time complexity or space complexity or both problem?

ANS

when comparing time of the algorithm when basewidth is 5000, the algorithm takes 1.4 seconds to complete.

With a basewidth of 40000, the Kernel crashes after 30 seconds or so of the algorithm running.

With a basewidth of 10000, the algorithm takes 5.6 seconds to complete.

basewidth of 625, time is only 0.3 seconds to complete.

This is time problem, as we can see the time of the algorithm becomes longer as the basewidth increases, so reducing steps in the problem to reduce time of the algorithm is something that could potentially be a problem to fix.

This could also be a space complexity, as we can see that the algorithm cannot finish when the basewidth is too large. Reducing complexity or reducing steps in the algorithm would need to be done to solve the problem, as it seems like the program does not have the capabilty to process higher base widths.

Linear time because the program must perform another step when the base width increases, thus linearily increasing timeoftfhefucntion.

Written Hacks

research on types of sorting algorithms and complexity

Constant:O(1). this is very good, as our time is guarunteed to stay low. Linear time: O(n). not as good as Constant, but better than other methods, as we are only increasing in steps by a set amount.

Logarithmic time: O( log n) not very good as O(1) and O(n), but can be useful. time grows logaritmicly.

Quadratic time: O(n^2). time is now increasing exponentially, which isn't good at all, but its not as bad as O(2^n)

Exponential time: O(2^n). very bad, steps become out of control at some values

Q: Why is time and space complexity important when choosing an algorithm?

Time and space complexity are important because programs should almost always be optimized to reduce time/space complexity. We don't want programs to be unusable because they take up too much time or use up too much of a user's cpu/memory.

Q: Should you always use a constant time algorithm / Should you never use an exponential time algorithm? Explain?

Constant time algorithms shouldn't always be used, as sometimes we need to use an exponential time algorithm for our programs. However, you should strive to have constant time algorithms or the shortest possible time algorithm, so that a user's experience isn't bogged down by long downtime as the program runs. The biggest problem with exponential is that the programs quickly fall apart when the inputs become too big. Otherwise, if the inputs are not that large or we have limits on our inputs, an exponential time algorithm would be fine. Sometimes, it might be too hard to optimize our programs, in which case springing for an exponential time algorithm would be neccessary, but reducing time should be something to keep in mind when developing programs.

Q: What are some general patterns that you noticed to determine each algorithm's time and space complexity?

NOTICE:When your calculation is not dependent on the input size, it is a constant time complexity

NOTICE:When you have a single loop within your algorithm, it is linear time complexity

NOTICE: When the input size is reduced by half, maybe when iterating, handling recursion, or whatsoever, it is a logarithmic time complexity

NOTICE: When you have nested loops within your algorithm, meaning a loop in a loop, it is quadratic time complexity

NOTICE: When the growth rate doubles with each addition to the input, it is exponential time complexity