is the exponent to which the base 2 must be raised to produce the number n. In other words, it answers the question: "2 raised to what power equals n?"
. Use bit-strings to solve this problem (1 = element included in the set, 0 = not).
.
This is the lower bound for comparison-based sorting algorithms, meaning that no comparison-based sorting algorithm can have a better average-case or worst-case time complexity than .
. Binary search if elements are sorted.
. Create a balanced BST by recursively choosing the middle element as the root.
The total number of squares in the region highlighted in black is what we're interested in counting. That is, .
Carl Friedrich Gauss
Solve the following recurrence: and for each that is a power of two.
Where is the number of times we have expanded the recurrence.
Remember, our goal is to express only in terms of (eliminating the recursive definition). Because the base case is , we can stop expanding when , or when . This means that .
We can say that is in .
Solve the following recurrence: and for each that is a power of two.
Again, we stop expanding when , or when . This means that .
Concluding that is in .
Let be a graph with vertices ad edges. Ca be a tree?
A tree is a connected graph with no cycles. A tree with vertices has exactly edges. Therefore, a graph with vertices and edges cannot be a tree, as it has one more edge than a tree would have.
Let be a graph with vertices. What is the maximum umber of edges that ca have?
In a simple graph with vertices, each pair of distinct vertices can be connected by at most one edge. This means the maximum number of edges occurs when every vertex is connected to every other vertex.
The total number of ways to choose 2 vertices from vertices (i.e., the number of pairs of vertices) is given by the binomial coefficient (combinatorics):
Thus, the maximum number of edges in a simple graph with vertices is .
Alternatively, we can use the summation formula:
You are given two sorted lists, each containing numbers. What is the best time complexity to merge these two lists into one sorted list?
Since both lists are already sorted, we can use a two-pointer technique to merge them efficiently. We maintain two pointers, one for each list, and compare the elements at these pointers. We append the smaller element to the merged list and move the corresponding pointer forward. This process continues until we have processed all elements from both lists.
The time complexity of this merging process is , where is the total number of elements in both lists (i.e., elements). Therefore, the best time complexity to merge the two sorted lists into one sorted list is .
What is a random variable? (Hint: A random variable is neither random nor a variable.)
A random variable is a mathematical function that maps outcomes of a random process to numerical values.
Suppose is the random variable representing the number of heads in 10 coin flips. If the outcome is H, T, H, H, T, T, H, T, H, T (where H = heads, T = tails), then maps this outcome to the value 5, since there are 5 heads.
In general, we can write:
where is the set of all possible outcomes (the sample space), and is the set of real numbers. For example,
or using arrow notation:
You roll a fair die repeatedly until the result is 3. Let be the number of rolls. What is the expected value of ?
To find the expected value of , we can use the concept of geometric distribution. The random variable follows a geometric distribution with success probability (the probability of rolling a 3 on a fair six-sided die).
The expected value (mean) of a geometric random variable is given by:
Substituting the value of : Therefore, the expected number of rolls until we get a 3 is 6.
© 2025 James Yap
Personal Website and Knowledge Base