Overview of the lecture on Time Complexity and Asymptotic Notation.
Concepts covered so far:
Concepts of Computation and Algorithms
Comparing algorithms
Asymptotic Analysis
Mathematical foundations (available on Brightspace)
Topics to be discussed:
Selection Sort algorithm
Binary Search algorithm
Big-Oh notation
Classes of algorithms
Importance of sorting in data analysis:
Examples include sorting employees by salary and names alphabetically.
Overview of sorting algorithms:
Selection Sort: finds the smallest element in the unsorted portion and moves it to the front.
Part 1: Sorting an array of integers.
Original array: 11, 9, 17, 5, 12
Find the smallest and swap with the first element.
Part 2: Continue finding the next smallest.
Example progression: 5, 9, 17, 11, 12 → 5, 9, 11, 17, 12
Part 3: Repeat until the unsorted portion is of length 1.
Count of primitive operations for an array of size n:
Finding the smallest requires visiting n elements + 2 for the swap.
Total operations: O(n²) using Big-Oh notation.
Types of searching algorithms:
Sequential Search: checks each element, does not require sorted data.
Interval Search (Binary Search): requires sorted data and uses a divide and conquer approach.
Task: Search for a key in a sorted list.
Process:
Check the middle element.
If the key is less than the middle, search the first half; otherwise, search the second half.
Repeat until the key is found or confirmed absent.
Binary Search: O(log₂(n))
Linear Search: O(n)
Conclusion: Binary search is faster but only works on sorted data.
Example with a million unsorted elements:
Linear search: O(n)
Binary search + Selection sort: O(n²)
Conclusion: Linear search is faster in this scenario.
Need to define runtime without experimental studies due to varying factors (processor speed, etc.).
Algorithmic complexity indicates performance.
Determines running time in Big-Oh notation.
Focus on worst-case number of primitive operations as a function of input size.
Identify input and what n represents.
Calculate primitive operations in terms of n.
Drop lower-order terms.
Remove constant factors.
Example: ArrayMax algorithm with T(n) = 8n - 5.
Result: Runs in O(n) time.
Rankings based on time complexity:
O(log n)
O(n)
O(n log n)
O(n²)
O(n² log n)
O(n⁴)
O(2ⁿ)
Algorithms with O(2ⁿ) complexity are inefficient.
Questioning the existence of better polynomial time algorithms.
An algorithm is solvable in polynomial time if it requires O(n^k) steps for some non-negative integer k.
Computable: Problems solvable by a computer (e.g., f(x) = x + 1).
Non-Computable: Problems that cannot be solved (e.g., Halting Problem).
P Problems: Solvable in polynomial time (e.g., multiplication, sorting).
NP Problems: Difficult to solve but easy to verify (e.g., job scheduling).
NP-HARD: Very difficult problems, not solvable in polynomial time.
NP-COMPLETE: Hardest problems in NP, no known polynomial-time solutions.
Finding a polynomial-time algorithm for any NP-COMPLETE problem would imply all NP problems can be solved in polynomial time.
Travelling salesperson problem
Finding the shortest common superstring
Checking language acceptance of finite automata
Essence: If checking a solution is easy, is solving the problem also easy?
Consequences of proving P=NP could lead to security vulnerabilities.
Upcoming lecture on data structures and their applications.
Laboratory work on implementing and comparing algorithms, computing T(n) and O(n), and running experiments.