-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson7 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: Lesson6
Are you sure you want to change the base?
Conversation
Dzhoker1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Оставил комментарии по коду
| @@ -0,0 +1,71 @@ | |||
| # Это просто материал урока, не дз | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не буду его проверять )))
| import random | ||
|
|
||
| # Генерация массива размера SIZE с числами в диапазоне от MIN до MAX | ||
| def ar_gen(SIZE, MIN, MAX): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
аргументы функции пишите строчными буквами. Они не могут быть константами по определению.
| if array[i] > array[i + 1]: | ||
| array[i], array[i + 1] = array[i + 1], array[i] | ||
| subcount += 1 | ||
| else: # Добавляем обратный проход для ускорения "всплытия" :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это называется шейкерная сортировка.
Уже не пузырёк.
| while len(left) != 0 and len(right) != 0: | ||
| if left[0] < right[0]: | ||
| result.append(left[0]) | ||
| left.remove(left[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Алгоритм верный.
Но одна эта строчка добавляет O(n) к сложности.
А у вас их две.
| return array | ||
|
|
||
| def find_med(array): | ||
| source = array.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кроме сложности по времени решили добавить сложность по памяти.
Не завидую я компьютеру, когда на вход придёт массив в 10 Гб.
No description provided.