I am designing my own algorithm to check if 2 codes are similar or identical?

How do pre-exsting softwares do this?
What logic do they use?
Are there different levels of testing for this?
please give detailed answers

Dani AI

Generated

Short answer: there is no single trick — real systems layer several techniques. Start with fast, language‑agnostic filters to cut the search space, then apply language‑aware structural checks, and finally (only when needed) deeper semantic or runtime analysis. As pointed out, ideas from sequence comparison are a useful starting point, but code needs preprocessing and parsing to be reliable.

A practical pipeline to design and evaluate:

  • Normalization: remove/ignore comments and formatting, optionally expand/preprocess macros, and canonicalize literal and identifier names.
  • Fast filtering: tokenize and build n‑gram shingles or hashed fingerprints (winnowing/minhash style) to find candidate pairs quickly.
  • Structural comparison: for candidates, parse to an AST (use a real C++ front end), compare tree shape or compute tree‑edit distance, and compare control‑flow or program‑dependence subgraphs for reordered code.
  • Semantic checks: run test suites, differential execution, or lightweight symbolic checks when you need functional equivalence.

Tradeoffs and cautions: fingerprints and token matching are fast but fragile to obfuscation (renaming, refactoring). AST and PDG comparisons are more robust but much heavier and harder for C++ because of templates and preprocessor complexity — use a compiler front end (for example Clang) rather than regex parsing. Full semantic equivalence is undecidable in the general case, so aim for heuristics + human review rather than a binary oracle.

Practical tips: exclude common libraries and boilerplate to cut noise, tune thresholds with labeled examples, keep an indexed fingerprint store for scale, and escalate matches through your pipeline rather than doing expensive analyses on every file.

There are techniques from bioinformatics to perform this kind of task. Try looking at this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.