Answer: It is n-1 swaps! 🙂 Feedback: Would be good to define what n actually is Alternate Answer:n-1 swaps, where n is the number of elements in the list Yeap this is correct
1. The main idea of Bubble Sort: Answer: Start by comparing the first pair of elements and swap them if the first element is greater than the second (assuming ascending order). Repeat for all pairs in the list. Repeat this whole iteration n-1 times (or until the whole list is sorted by checking if no swaps were done in the current iteration (optimisation 1)). There is no need to check the elements that were already sorted in subsequent iterations so reduce the range by 1 in each iteration (optimisation 2). Feedback: Alt answer #1: Add the statement Bubble sort is a sorting algorithm whose main idea is to place the largest unsorted element into its final position after each traversal. 2. What is the largest number of swaps performed by Bubble Sort per item in the list? Answer: It is n-1 swaps! 🙂 Feedback: Would be good to define what n actually is Alternate Answer: n-1 swaps, where n is the number of elements in the list Yeap this is correct 3. What is the…
FIT 1008/2085 A1 quiz (please don't try the quiz yet) /4 FIT 1008/2085 Quiz FIT 1008/2085 Quiz 1 / 4 Consider the following implementation of a class for a Monash student:class Student: def __init__(self, name, stud_id): self.name = name self.stud_id = stud_id def __gt__(self, other): # TODO: Finish implementation return self.stud_id > other.stud_id self.stud_id > other.stud_id stud_id > other.stud_id return stud_id > other.stud_id 2 / 4 What will be the returned value from the following function:def mystery(lst): bingo = 0 for item in lst: if bool(item): bingo += 1 return bingowhen the value of list is [0, 1, 2, 3, None, 5, -0, 6, 7, None] Check 3 / 4 What is the purpose of this function?def scramble(my_container): mid = len(my_container)//2 a = my_container[mid] b = my_container[0] c = [] for item in my_container: if item > a: c.append(item) elif item < b: b = item return c, b The function counts the number of elements in the array that are bigger than the middle element and then returns the last element and the count.…
Note: If you want to leave comment as Anonymous, don't type name and email when you leave comments