Authors:
Release Date: January 9, 2022
License: MIT License
To execute this implementation, ensure you have Python 3.x installed and follow these steps:
python Isogram.pyAn Isogram (also known as a "non-pattern word") is a logological term for a word or phrase without a repeating letter. This implementation provides a robust verification mechanism to detect character collisions within a given string across any Unicode-compliant dataset.
The verification of an isogram is a problem of Set Cardinality.
Let
This equality implies that every element from the range of the sequence is unique, representing an Injective Mapping from the set of indices
In an isogram, each character provides a unique contribution to the string's information content, maximizing the local entropy per character for that specific set of symbols.
-
Hash-Set Optimization: This implementation utilizes a hash-set to check for uniqueness, reducing the search complexity from
$O(n^2)$ (nested loop comparison) to$O(n)$ . - Normalization: The algorithm ensures case-insensitivity and filters non-alphabetic characters (such as hyphens or spaces), ensuring the core logical test remains pure.
-
Complexity:
-
Time Complexity:
$O(n)$ , where$n$ is the length of the string. -
Space Complexity:
$O(u)$ , where$u$ is the number of unique characters (worst case $O(n)$).
-
Time Complexity:
- List Comprehension: Efficiently filters and normalizes the input string in a single linear pass.
-
Set Constructor: Leverages Python's highly optimized
$set()$ constructor, implemented in C, for high-performance cardinality calculation.
flowchart TD
A["Start: verify(text)"] --> B["Filter: alphabetic chars only"]
B --> C["Normalize: lowercase"]
C --> D["Calculate length of clean_text (L)"]
D --> E["Construct Hash-Set (unique_chars)"]
E --> F["Calculate cardinality of set (S)"]
F --> G{"Is S == L?"}
G -- "Yes" --> H["Return True (Isogram)"]
G -- "No" --> I["Return False (Not Isogram)"]
graph LR
subgraph DataStructures ["Execution State"]
direction LR
L1["List: [a, c, c, e, n, t, o, r]"]
S1["Set: {a, c, e, n, t, o, r}"]
L1 -- "Cardinality Check" --> S1
end
