What is pseudopolynomial time? How does it differ from polynomial time?

To understand the difference between polynomial time and pseudopolynomial time, we need to start off by formalizing what “polynomial time” means. The common intuition for polynomial time is “time O(nk) for some k.” For example, selection sort runs in time O(n2), which is polynomial time, while brute-force solving TSP takes time O(n · n!), which … Read more

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line

BTW complexity is indeed O(n^3) to lower that you need to: sort the points somehow by x and or y in ascending or descending order. Also use of polar coordinates can help sometimes use divide at impera (divide and conquer) algorithms usually for planar geometry algorithms is good idea to divide area to quadrants and … Read more

Time complexity of string slice

Short answer: str slices, in general, copy. That means that your function that does a slice for each of your string’s n suffixes is doing O(n2) work. That said, you can avoid copies if you can work with bytes-like objects using memoryviews to get zero-copy views of the original bytes data. See How you can … Read more