I've been tackling complex maths on point clouds for a few weeks now, i will give you some ideas.
First of all, your points are either 16 bit 3D points or rounded to managable integers, for example every point is an integer ranging from size 0-5000, that givs high precision while giving access to fast X-Y-Z value sorting.
Normally they use KD trees for point cloud algebra, but if you have discreet points you can place them as true false values in a 3d boolean array, which can be very interesting to program with.
You have to specifically tailor your algorithm for the type of pattern that you wish to detect and fix, every time.
The result depends if you have reliable normals, precision level, error type, you have to get someone with good spacial visualization to figure out all the best logic to deal with your pattern recognition, it is very fun for me.
You have to sort your arrays by X/Y/Z and do iterative comparisons on them. Use square of distance to compare two points, not distance, square maths is slow.
sorting X Y Z individually, you will be able to fast compare close vertices on three axes in different iteration runs.
If you sort by x then y then z, you may have a nicely sorted data set that is fast to get data from.
It sounds like you just need a poximity test for Z compared to it's neighbors. description of data is vague. no images provided!
If so, sort array by z into strata of the precision of 1 unit or round them, make an array which holds data which tells you how many times a dot appears in any Z strata, for example the building roof at 20m contains 800 poins, 10m strata contains 200 points, and so forth for every strata, so you have an array of point number per strata.
You can use that strata number array to order all your data into an array you can read and write from very fast, comparing only 1% of the points to every z value instead of 100%, 100 times faster! that kind of data sorting takes 1 hour to write and can sort a 100 million poinds in a few seconds. you need to memorize number points on each axis level, write a staircase so you know that all points between 20 and 21 meters are in indexes 5mn and 5.23mn of your sorted point cloud for example.
Also check KD trees.
dont use distance maths use square of distance, it's faster.
hope that's helpful.