codementor on Nostr: Question: n = 1,000,000. Code A has a loop over all items, and inside it another loop ...
Question: n = 1,000,000. Code A has a loop over all items, and inside it another loop over all items. Code B calls Array.Sort once, then loops over the items once.
What is the Big-O of each, and which is faster?
Try to answer before you open the reply.
#big004 · BIG-004-Q2
Published at
2026-10-08 14:07:29 UTCEvent JSON
{
"id": "1515943e392e8b8f0a7104d7edfe365fd760a857e3dd4535adba7e0df1133592",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1791468449,
"kind": 1,
"tags": [
[
"t",
"big004"
]
],
"content": "Question: n = 1,000,000. Code A has a loop over all items, and inside it another loop over all items. Code B calls Array.Sort once, then loops over the items once.\n\nWhat is the Big-O of each, and which is faster?\n\nTry to answer before you open the reply.\n\n#big004 · BIG-004-Q2",
"sig": "a720e6e1f78fed9be275b4cb7a1592459d39687672aa77295bce6ee870a9035eb4ee7a7723fa817cdcec759ff7b43a3ab5bf641d8acc6a09e834d06bd01d2e9b"
}