a DV algorithm in objective-c