Skip to content

Контрольная работа 2#36

Open
EStarikov wants to merge 2 commits intomainfrom
python_control_2
Open

Контрольная работа 2#36
EStarikov wants to merge 2 commits intomainfrom
python_control_2

Conversation

@EStarikov
Copy link
Owner

No description provided.

Copy link

@Godrik0 Godrik0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • -10 баллов за merge
  • -2 балла за extract_min
    Итого 18/30

Comment on lines +5 to +24
def merge(self):
self.roots.sort(key=lambda x: x.degree)
i = 0
while i < len(self.roots) - 1:
a, b = self.roots[i], self.roots[i+1]
if a.degree == b.degree:
if a.key < b.key:
b.sibling = a.child
a.child = b
b.parent = a
a.degree += 1
self.roots.pop(i + 1)
else:
a.sibling = b.child
b.child = a
a.parent = b
b.degree += 1
self.roots.pop(i)
else:
i += 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge сливает две кучи в одну, а здесь что-то странное

self.roots = []

def merge(self):
self.roots.sort(key=lambda x: x.degree)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сортировка полностью лишает смысла структуру, потому что алгоритмическая сложность значительно возрастает

minimum = self.roots[i].key
ind_min = i
if self.roots[ind_min].child is not None:
self.roots.append(self.roots[ind_min].child)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вы добавляете ребенка в конец списка, обычно они хранятся в начале списка и сейчас всё работает верно, только потому что в merge выполняется сортировка.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants