Big-O Notation (Python) Lecture Notes PDF

Summary

These lecture notes cover Big-O notation for analyzing algorithm time complexity in Python. Examples of time complexities such as O(1), O(n), O(n^2), O(log n), and O(n log n) are shown, along with sorting algorithms like selection sort. The notes provide code examples and visualizations.

Full Transcript

Frequency count method Frequency count method Big-O Notation Big-O Notation O(1) - Constant Time: Accessing an element by index in a list. Big-O Notation O(n) - Linear Time: Summing all elements in a list. Big-O Notation O(n^2) - Quadratic Time: Bubble...

Frequency count method Frequency count method Big-O Notation Big-O Notation O(1) - Constant Time: Accessing an element by index in a list. Big-O Notation O(n) - Linear Time: Summing all elements in a list. Big-O Notation O(n^2) - Quadratic Time: Bubble Sort, where you compare every element with every other element. Big-O Notation O(log n) - Logarithmic Time: Big-O Notation O(n*log n) time complexity of O(n2) Selection Sort Selection Sort algorithm, which sorts an array by repeatedly finding the minimum element from the unsorted part and moving it to the beginning. The algorithm divides the array into two subarrays: 1.Sorted array 2.Unsorted array In each iteration, it selects the minimum element from the unsorted subarray and moves it to the sorted subarray. This process continues until the array is fully sorted. Selection Sort

Use Quizgecko on...
Browser
Browser