# Review of Code Similarity and Plagiarism Detection Research Studies
## 2 Code Clones: Definition and Types
### Type I Code Clone  
Type I code clones, popularly known as \"exact clones\", consider only substantially identical pieces of code to be code clones. Note that whitespace characters or comments that are not involved in actual code execution are ignored in this comparison. Thus, type I code clones may still exhibit differences in the code, when examined using a general version control system (VCS), or in the text, when examined using the diff command in Unix systems. Table 2 demonstrates the similarities and differences that can exist between an original code and its type I code clone.  
In the second code snippet, most of the spaces between the keywords and variables have been removed, and the positions of comments comment 1 and comment 2 are completely different, even in their order relative to the actual code. Moreover, \")\", which marks the end of the if statement, has been moved to the end of the line above it, before else. This is the result of moving the newline character \"\(\backslash\)n\" in the line above to the end of \")\". In the case of these two code snippets, the two codes will likely be assessed to be completely different by a simple text difference detection technique. However, in the context of code similarity detection, the second code snippet is considered a type I code clone, i.e., the strictest type, because there is no actual difference between it and the original, except for spaces and comments.  
\begin{table}
\begin{tabular}{l l l} \hline \hline
**Classification** & **Types** & **Explanation** \\ \hline \multirow{4}{*}{Text Similarity} & Type I & Code snippets that are identical except for whitespace, comments, etc. \\ \cline{2-3}  & Type II & In addition to type I, code snippets that are structurally or syntactically identical except for identifiers, literals, types, etc. \\ \cline{2-3}  & Type III & In addition to type II, code snippets that include some structural/grammatical variations of additional statements or expressions but are nonetheless thought to be copied \\ \hline \multirow{2}{*}{Functional Similarity} & Type IV & Code snippets that perform the same computation but differ in the actual structural/grammatical implementation \\ \cline{2-3}  & & \\ \end{tabular}
\end{table}
Table 1: Types of code clones.  
\begin{table}
\begin{tabular}{l l l} \hline \hline  & & if(i>=j){ \\ if (i >= j) [ & s=t+i; \\ s = t + i; //_comment 1_ & //_comment 1_ \\ t = i - j; & t=i-j; \\ ] else & //_comment 2_ \\ s = t + j; //_comment 2_ & s=t+j; \\ \hline \hline \end{tabular}
\end{table}
Table 2: Example of an original code snippet (left) and its type I code clone (right).  
Ignoring code style differences, the type I code clone has exactly the same code. Notably, the identifiers or literals have been preserved. Thus, code similarity detection targeting type I code clones can be considered (1) when it is meaningful to compare variable names or function names, or (2) when the same code is detected among codes using the same literal. However, in such cases, even a slight change in variable names can cause similar codes to fail to be recognized as code clones.