Have you sent a text or used GPS navigation recently? Whether or not you were aware of it, you used a greedy algorithm, a topic studied in computer science. But greedy algorithms can do far more than just power technology. They and the ideas behind them can also be instructive spiritually.

Before diving in further, let’s define our terms. An algorithm is a step-by-step process to solve a problem, and a greedy algorithm is one that only takes steps that maximize value in the short term. For example, consider a cashier tasked with making 30 cents of change with as few coins as possible. She will first start by choosing the highest-valued coin, a quarter. Then, she is left to make 5 cents of change, so she will pick a nickel. With that, she has completed the task only using two coins. Notice that there are other but inferior solutions, like picking 2 dimes and 2 nickels.

By reflecting on such connections, Christians can learn to stay close to Christ “greedily” in all that he commands us to do.Though “greedy” generally has a negative connotation elsewhere, here in computer science, it just refers to having a short-term focus. This focus enables greedy algorithms to be straightforward and intuitive, compared to other algorithms that require more steps or use more resources. In short, greedy algorithms are popular because they are simple yet effective.

However, simplicity can quickly turn into naiveté, as honing in on the short term is not always best in the long term. For example, when making change with stamps, greedy algorithms can be incredibly inefficient. Consider the task of making 80 cents of postage with 60-, 40-, and 1-cent stamps. A greedy algorithm would pick the highest-valued stamp first, the 60-cent one. With 20 cents left, the algorithm can only pick 1-cent stamps, which it must do 20 times. Imagine receiving such a letter! The optimal solution instead would have been to pick two 40-cent stamps, even though they are not as high-valued individually.

Not only can greedy algorithms be inefficient, they can also fail altogether. This time, consider the task of making 10 cents of postage with 5- and 8- cent stamps. The greedy algorithm picks the highest-valued stamp first, the 8-cent one. After which, with 2 cents left, it gets stuck.

These examples illustrate the general computer science principle that a greedy algorithm only works optimally when its problem space is arranged in a particular way, like coin denominations are. Only then do they produce best solutions.

From one perspective, religions also concern themselves with problems and solutions: what is wrong with the world and what ought to be done in response. Framed this way, practicing Christianity is similar to following a greedy algorithm. Life is not primarily about working harder or converting more people (longer-term strivings). Instead, Christianity is first about being in relationship with the creator God. Christians are called to spend time with him, whether it be in his word or in prayer, whether it be individually or corporately. We are to know him personally not just intellectually, to seek his face not just his hands. Our first priority, our one thing, is simply to be with the Lord.

But can pursuing relationship in the short term actually be good in the long term too? After all, the sons of Aaron were presumably trying to relate to God in their own way in Leviticus 10, but God was displeased and killed them because of their “unauthorized fire.” In 2 Samuel 6, God fatally “struck [Uzzah] down” as he and other Israelites were in the middle of worship! As earnest as this group was in pursuing God, they disobeyed his commandments around appropriate transportation of the ark. In both of these cases, relationship seems secondary to holiness. Perhaps we must follow God’s commandments perfectly before we can expect to be with him.

This may be the essence of the Old Covenant, but everything changes when Jesus comes onto the scene. Christ died for all, fulfilling the righteous requirement of the law and reconciling believers to their holy Father. Now, despite our sin, we are adopted into God’s family, where direct relationship with God is possible. In fact, it is optimal, as we are commanded to “abide” in the Lord (John 15:4), “draw near” to him (James 4:8), “seek” him out (Psalm 27:8) and “look to him” (Psalm 34:4–5). This that ought to be most satisfying in the short term is ultimately what is best in the long term too.

But remember, this algorithm’s short-term focus only works because the problem space is arranged in a particular way: Christ shed his blood for sinners. This new privileged lifestyle that Christians lead is only possible because of his sacrifice. God could have abandoned us in our sin, but he did not and because of that, we can live as his children, simply. Similarly, coin denominations could have been counted randomly, but they are not and because of that, change can be made easily. Both of these simplicities cannot be taken for granted—they were “bought with a price” and intentionally designed. Only because of specific arrangements can Christians live “greedily.”

Of course, analogies have their limits. Sin still plagues us and we often do not desire the things of God in the short term. To this, it is worth clarifying that the greedy lifestyle is only Christian if it makes its short-term decisions based on God’s standards. Otherwise, it descends to mere hedonism or legalism.

Others may object that greed focused on immediacy seems immoral and at odds with biblical patience and forbearance. While believers are certainly called to wait on the Lord, this only comes after relationship with him has been established and cultivated. Relationship still comes first. Still, it does seem ironic that Christians ought not covet, yet ought to be greedy. However, it is not the desire by itself that matters, but what the object of the desire is. Desire for more wealth and worldly possessions, as “greed” is usually interpreted, is certainly reprehensible. But desire to know more of God, as “greed” is now reframed, is critical to our faith.

Furthermore, greedy algorithms characterize Christianity well, especially as it is compared with other religions or worldviews. In a conference on comparative religion, C. S. Lewis argued that although there are many distinctive aspects of Christianity—for example, incarnation or resurrection—they do appear in other religions too. What is truly unique about Christianity, Lewis observed, is grace. Philip Yancey elaborates this point further, writing,

The notion of God’s love coming to us free of charge, no strings attached, seems to go against every instinct of humanity. The Buddhist eightfold path, the Hindu doctrine of karma, the Jewish covenant, and the Muslim code of law—each of these offers a way to earn approval. Only Christianity dares to make God’s love unconditional.

Unconditional love is the foundation of our faith and enables us to boldly seek out relationship with our heavenly Father.

A biblical story that perhaps illustrates greedy faith well is the account of Mary and Martha. Luke juxtaposes these two sisters with Mary sitting and listening at Jesus’ feet while Martha “distracts” herself with serving. When Martha protests, Jesus actually praises Mary for choosing “the good portion” and the one thing “necessary.” Martha’s serving actions were respectable, but they were secondary compared to simply being with the servant king.

In addition to highlighting the Lord’s priorities for believers, this passage also exemplifies his inclusive grace. During New Testament times, women were often discouraged or even excluded from studying. Jesus, however, breaks with the culture and invites Mary to his teaching. This was not just a one-off exception for a friend; Jesus was known for associating with the lowly and the marginalized, to the point where the Pharisees thought of him as “a glutton and a drunkard, a friend of tax collectors and sinners” (Matthew 11:19). Jesus embodied grace consistently, in his life and in his death, when it was admirable and when it was taboo.

Grace and greed, covenants and computers. We may be tickled thinking about these connections, but what difference can they ultimately make?

By reflecting on such connections, Christians can learn to stay close to Christ “greedily” in all that he commands us to do. The primary point of Christianity still is relationship with God, but those who truly know him are compelled to go out to love and serve the world. As we serve our neighbor, let’s beware some of the various pitfalls awaiting us. First, one can serve but be “anxious and troubled about many things,” as Martha was. Second, one can serve but with bitterness or reluctance in their hearts (2 Corinthians 9:6–7). Finally, one can serve but have self-centered or malicious intent, like the Pharisees. God is not pleased with any of these attitudes. It is not just about the actions themselves; how they are done also matters. In fact, apart from him, one can do nothing. Therefore, relationship with God comes first, especially if one is to serve.

God reveals himself through this world (Psalm 8:3–4) and through domains as unexpected as computer science. While “greed,” traditionally understood, is certainly bad, “greedy algorithms,” scientifically understood, are not. In fact, greedy algorithms can actually help frame the gospel in a new and refreshing way. They have much to teach us about God, his extravagant grace, and what we ought to do in response. Let us have a heart of understanding and the will to put such lessons into practice.