Big O notation and magnitude analysis
Big O notation is a way in which we can analyze the amount of complexity there is within an operation (typically, time complexity) to help understand the magnitude or scale of the operation under consideration. O here stands for Order, and big O notation follows the convention of writing O and then the complexity (in terms of the number of operations) in brackets after, such as O(1), O(n), and O(n2). In this notation, n denotes the size or number of items input. Let’s see some examples to understand how we can use this notation.
The following code snippet, given a list of any size, simply outputs its length to the debug logs:
public static void printSize(List<Account> accounts) { System.debug('There are ' + accounts.size() + 'accounts in the list'); }
If we pass in a list of 1 account or a list of 100 accounts, the number of operations...