Skip to content

070_lesson#7

Open
ikrugloff wants to merge 1 commit intomasterfrom
070_lesson
Open

070_lesson#7
ikrugloff wants to merge 1 commit intomasterfrom
070_lesson

Conversation

@ikrugloff
Copy link
Owner

No description provided.

Copy link

@Dzhoker1 Dzhoker1 left a comment

Choose a reason for hiding this comment

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

Оставил комментарии по коду

@@ -0,0 +1,21 @@
import random

Choose a reason for hiding this comment

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

Похоже вы прослушали то, что было в конце урока.
В функцию не превратили, "ускоритель" не добавили. И сортирует по возрастанию, а не по убыванию.
Да, разворот внизу есть. Но с таким же успехом можно все задачи решить через sorted.

@@ -0,0 +1,28 @@
import random

Choose a reason for hiding this comment

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

Это сортировка слиянием? )))
Куда потерялось условие задачи?

a_result = []
for i in range(N):
a_result.append(sum_(a[i]))
print(f'{a_result}')

Choose a reason for hiding this comment

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

Прочитал до конца код. Абсолютно уверен, что это не сортировка. Результаты вывода на экран подтверждают моё мнение. Что же это? )))

M = 10
N = 2 * M + 1

l = [0] * N

Choose a reason for hiding this comment

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

l - без комментариев.

:return: k-тый элемент l
"""
if len(l) == 1:
assert k == 0

Choose a reason for hiding this comment

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

В половине запусков выпадаю тут с ошибкой

x = sorted(l[:])
print(f'sorted_list = {x}')

# With love to https://habr.com/post/346930/

Choose a reason for hiding this comment

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

)))


# With love to https://habr.com/post/346930/

def nlogn_median(l):

Choose a reason for hiding this comment

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

Простое решение со встроенной сортировкой.
Хорошо, но расцениваю это как читерство высшего уровня.

quickselect(l, len(l) / 2, pivot_fn))


def quickselect(l, k, pivot_fn):

Choose a reason for hiding this comment

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

Примерно это будет на разборе ДЗ


print(f'n*logn median = {nlogn_median(l)}')
print(f'quickselect_median = {quickselect_median(l, pivot_fn=random.choice)}')
print(f'determine O(n) = {pick_pivot(l)}') # что-то здесь пошло не так с медианой???

Choose a reason for hiding this comment

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

Привязка к 5.

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