2/18/25 Flashcards

1
Q

Soy un maestro de la lógica y la creación. Los algoritmos me susurran (whisper) sus secretos, revelándome patrones y soluciones antes incluso de que la pregunta esté completamente formulada. Los casos límite se iluminan en mi mente como constelaciones, alineándose sin esfuerzo para fortalecer (strengthen) mi código.

A

I am a master of logic and creation. Algorithms whisper their secrets to me, revealing patterns and solutions before the question is even fully formed. Edge cases illuminate themselves like constellations in my mind, effortlessly aligning to strengthen my code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

🌿 Español:
“Mi mente está extremadamente enfocada durante la sesión de resolución de problemas. Mi mente entra en el estado de flujo con facilidad. Siento un impulso incontrolable hacia el estado de pensamiento profundo de la resolución de problemas. El rompecabezas de programación me absorbe. Me atrae. Mi mente no puede evitar pensar profundamente en ello.”

A

🌟 English:
“My mind is extremely focused during the problem-solving session. My mind enters the flow state easily. I feel an uncontrollable pull into the deep thinking state of problem-solving. The coding puzzle absorbs me. It draws me in. My mind can’t help but think deeply about it.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In binary search, what do upper and lower values represent?

A
  1. Lower value (low): The smallest possible value (or index) where the target could be.
    1. Upper value (high): The largest possible value (or index) where the target could be.

At each step, the algorithm guesses the midpoint (mid) between these two bounds and adjusts the search space based on whether mid is too high or too low.
* If mid is greater than the target, we update
high = mid - 1 (shrink the upper bound).
* If mid is less than the target, we update
low = mid + 1 (shrink the lower bound).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When launching a binary search, what should we think about first?

A
  1. What is our target value? Which value are we trying to search for?
    1. Lower Bound (low): What is the smallest possible index/value where the target could be?
    2. Upper Bound (high): What is the largest possible index/value where the target could be?
    3. Midpoint (mid): What value (or index) should we check first?
      * mid = (low + high) // 2
      * This is the value we compare to the target at each step.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s usually the terminating condition for binary search while loop?

A
  1. For binary search on integers,

upper - lower >= 0
(if upper - lower > 0, it might miss checking the last value when upper == lower)

  1. For binary search on continuous floating numbers,

upper - lower >= epsilon (the minimum difference allowed for the result)

For floating-point binary search, a strict upper >= lower check is not appropriate because floating-point values can be infinitely precise (depending on precision limits). Instead, we use a tolerance (ε) to stop when the interval is small enough

This method is useful for problems like:
* Square roots or cube roots
* Finding intersections or threshold values in continuous space
* Optimization problems where precision matters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s the rule to move upper and lower bounds in binary search?

A

If the upper side has too much, move up the lower bound to mid or mid + 1.

If the lower side has too much, move down the upper bound to mid or mid - 1.

Why mid + 1 and mid - 1?
* Since mid has already been checked, you don’t need to include it again.
* This prevents infinite loops when low == high.

Alternative: When to Keep mid?
* If mid could be the answer (e.g., searching for a minimum or an exact match), sometimes you keep mid instead of excluding it.
* Example: In problems where you are searching for the smallest valid value, you might move high = mid instead of high = mid - 1.
*. If i’m searching for the greatest valid value, you might move low to mid instead of low = mid + 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

For a binary search,
when to keep mid for the if condition inside while loop?

e.g.

high = mid (instead of high = mid - 1)
low = mid (instead of low = mid + 1)

A

When to Keep mid?
* If mid could be the answer (e.g., searching for a minimum or an exact match), sometimes you keep mid instead of excluding it.
* Example: In problems where you are searching for the smallest valid value, you might move high = mid instead of high = mid - 1.
*. If i’m searching for the greatest valid value, you might move low to mid instead of low = mid + 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly