logo

Crowdly

What is the worst-case time complexity of getting the union of two sets (see...

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

What is the worst-case time complexity of getting the union of two sets (see example code below), if implemented with an array?

Explain your answer (no explanation, no marks) and define your input variables.

def union(self, other):

    res = ArraySet(len(self.array) + len(other.array))

    for i in range(len(self)):

        res.array[i] = self.array[i]

    res.length = self.length

    for j in range(len(other)):

        if other.array[j] not in self:

            res.array[res.length] = other.array[j]

            res.length += 1

    return res

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на learning.monash.edu?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!