Skip to content
Advertisement

Tag: time-complexity

time complexity of concatenating strings in python

What is is the time complexity for the following function in Python? The function takes two inputs, string1 and string2, concatenates them together using “+” and returns the concatenated string. is it O(n + m) where n is the length of string1 and m is the length of string2? thanks! Answer Yes, it is. Strings in Python are immutable, once-allocated

Power Plant – solve the problem in O(nlogn)

I had the following problem on the exam: A certain power plant needs coal to operate, so it has ordered n deliveries, and information about each delivery (number of tons) is stored in a list A. The delivered coal is stored in warehouses with consecutive numbers 0, 1, …. (Their exact number is not given). Each warehouse has the same

Algorithm for ordering data so that neighbor elements are as identical as possible

I have a (potentially large) list data of 3-tuples of small non-negative integers, like I want to order the tuples within data so that neighboring tuples (data[i] and data[i+1]) are “as similar as possible”. Define the dissimilarity of two 3-tuples as the number of elements which are unequal between them. E.g. (0, 1, 2) vs. (0, 1, 2): Dissimilarity 0.

Advertisement