Assignment - Bubble Sort and Insertion Sort Implementation
Assignment - Bubble Sort and Insertion Sort Implementation
Assume
that the items to be sorted are stored in a 1D array with n elements.
def bubble(list_a):
indexing_length = len(list_a) - 1
sorted = False
sorted = True
sorted = False
return list_a
print(bubble([4,8,1,16,8,2,9,33,7,6,69]))
2. Dry-run the insertion sort algorithm using a trace table. Assume the list consists
of the following six items in the order given: 53, 21, 60, 18, 42, 19.
2 60 False [21,53,60,18,
42,19]
3 18 True [21,53,18,60,
42,19]
2 18 True [21,18,53,60,
42,19]
1 18 True [18,21,53,60,
42,19]
4 42 True [18,21,53,42,
60,19]
3 42 True [18,21,42,53,
60,19]
2 42 False [18,21,42,53,
60,19]
5 19 True [18,21,42,53,
19,60]
4 19 True [18,21,42,19,
53,60]
3 19 True [18,21,19,42,
53,60]
2 19 True [18,19,21,42,
53,60]
1 19 False [18,19,21,42,
53,60]
3. Write program code for the insertion sort algorithm. Assume that the items to be
sorted are stored in a 1D array with n elements.
def insertion_sort(list_a):
for i in indexing_length:
value_to_sort = list_a[i]
i = i -1
return list_a
print(insertion_sort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]))
4. Write a program to get character inputs from the user and output the sorted
character list.
array = [a, b, c, d, e, f]
aa = int(array.count(a))
bb = int(array.count(b))
cc = int(array.count(c))
dd = int(array.count(d))
ee = int(array.count(e))
ff = int(array.count(f))
for i in array:
else:
array.sort()
print(array)