Chapter 3.1-3.2 Simple Algorithms
Chapter 3.1-3.2 Simple Algorithms
procedure for solving a problem or accomplishing a task. We will discuss the following:
1. Definition of an algorithm
One of the simplest algorithms is finding the maximum value in a list of numbers. Here is a
5. After the loop ends, 'max_value' will hold the maximum value in the list.
Python implementation:
def find_max(numbers):
max_value = numbers[0]
max_value = number
return max_value
# Example usage
Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent
elements, and swaps them if they are in the wrong order. The pass through the list is repeated until
Python implementation:
def bubble_sort(numbers):
n = len(numbers)
for i in range(n):
# Example usage
The following graph represents the number of operations (swaps) performed by the Bubble Sort
algorithm as the list size increases. It demonstrates the algorithm's O(n^2) time complexity, meaning
the time it takes to sort the list grows quadratically as the list size increases.