Urgent.News

What's breaking now, across hundreds of outlets.

Tech

My O(n ) Algorithm Ran in O(n) — and Why That Meant My Stress Test Was Wrong

For my algorithms course, I solved three variants of the text segmentation problem with dynamic programming, proved them correct, and stress-tested them. The most useful part wasn't the algorithms. It was looking at my stress test results and realising one of them made no sense. The problem You get a string of letters with no spaces, and a function IsWord(s) that tells you whether s is a valid…

The student completed three variants of the text segmentation problem using dynamic programming. The first variant counted the ways to split a string into words. The second variant checked whether two strings could be split at the same positions. The third variant counted the ways to split two strings at the same positions, but aimed to minimize the number of dictionary lookups.

The student simulated the worst-case scenario by making the IsWord function always return True. This resulted in O(n²) calls to IsWord. The stress test showed that variant (b) was significantly faster than the others, with a linear growth rate, contrary to the O(n²) expectation.

The student discovered that the inner loop only required a single check for the first word in each iteration. By moving this cheap check first in the boolean condition, the number of IsWord calls was reduced. In the case where no substring was a word, the number of IsWord calls dropped from 2,001,000 to 2,000.

Additionally, the number of splits for an n-letter string with every substring being a word is 2ⁿ⁻¹. At n = 2,000, this results in a 2,000-bit integer. The algorithm also copies characters during slicing, making the "O(n²)" analysis misleading as it assumes O(1) operations for additions and slicing.

The student learned the importance of verifying that the worst-case test is indeed the worst case, analyzing which input makes each loop run longest, measuring the operation of interest rather than relying solely on wall-clock time, and considering the order of boolean conditions.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Twelve questions before any code

We're building a product for small organizations, and its newest piece is a tracked list of work with approval steps. When someone asks for something, it's held until a person says yes, then handed to…

  • Twelve questions addressed before coding began for small organization software
  • Final decision rested with intended users, not developers
  • Privacy ensured by limiting access to relevant roles only

Building ComfyUI custom nodes for a remote generation API: polling, tensors, VIDEO outputs and keeping keys out of workflows

ComfyUI is usually about running models on your own GPU, but a growing number of node packs call remote APIs instead: the graph stays local, the heavy lifting happens on someone else's hardware.

  • ComfyUI discovers custom nodes in customnodes/ directory
  • Node class includes INPUTTYPES, RETURNTYPES, and FUNCTION
  • Vellria API uses POST for image/video generation, returning 202 status

Why 1.26 cubic metres of concrete comes out as 70 bags, or 71, depending on where you round

A 4 by 3 metre slab at 100 mm deep is 1.2 cubic metres. Add the usual 5 percent margin and you have 1.26. Divide by the yield on the bag and the order should be 70 bags.

  • Concrete volume, margin, bag yield, and rounding precision determine bag count
  • 4 m by 3 m slab with 0.1 m depth requires 1.26 cubic meters of concrete
  • Rounding 70.00000000000001 up yields 71 bags, but rounding ratio first yields 70 bags

Copy Dropbox to Google Drive With rclone (Without Deleting Anything by Accident)

If you need to move a Dropbox account, or one big folder, into Google Drive, rclone is the most capable free tool for the job. It talks to both APIs directly, so you are not downloading everything through a desktop sync client and uploading it again. It is also a tool where one wrong verb deletes files.

  • Use rclone to copy Dropbox to Google Drive without deleting.
  • Create separate remotes for Dropbox and Google Drive in rclone config.
  • Use the copy command with dry run and progress flags for safe transfer.

Case-saathi

* title: "Introducing CaseSaathi: Simplifying Digital Fraud Complaints in India" published: false tags: fintech, webdev, ai, india * Introducing CaseSaathi: Simplifying Digital Fraud Complaints in India Digital payment fraud has become an increasingly serious concern in India.

More from Saturday, 28 November 2026 →