Skip to the content.

Graphs and Heuristics

04/22/25, Mirabelle's lesson

Heuristics

Popcorn Hack


def greedy_coin_change(amount, coins=[25, 10, 5, 1]):
    change = []
    for coin in coins:
        while amount >= coin:
            amount -= coin
            change.append(coin)
    return change

# Example usage:
amount = 63
result = greedy_coin_change(amount)
print(f"Change for {amount}¢: {result}")
print(f"Total coins used: {len(result)}")
Change for 63¢: [25, 25, 10, 1, 1, 1]
Total coins used: 6
  • Flipping the numbers makes it exponentially larger and less efficient than if it were 25 first.

Homework Hack

  • Reflection
    • Changing the order of coins affected the result because the greedy algorithm always picks the largest available coin first, which doesn’t always lead to the optimal solution. The algorithm that used fewer coins often depended on trying smaller coins earlier, showing that greedy algorithms work well when the coin system is “canonical” but can fail when it isn’t. One key change was adjusting the coin order, which revealed how a greedy strategy might miss the most efficient solution if it doesn’t consider all options.

Graphs

Popcorn Hack:

  • done on the board

Homework Hacks

Q1

  • Answer: C) Both configuration I and configuration II

Q2

  • Answer: C) Three

Undecideable Problems

Popcorn Hack: Practice from College Borad

  • 1.) False
  • 2.) False

Homework Hack

  • not committed, cant access

Kahoot

  • I got 21 lol