DSAHashingBijection

Isomorphic Strings Visualizer

What are Isomorphic Strings

s and t are isomorphic when you can rename the letters of s to obtain t, and the renaming is one-to-one. Two hash maps enforce both directions: s→t and t→s. A second letter trying to reuse a partner breaks the bijection.

  • egg / add works: e→a, g→d.
  • foo / bar fails: o cannot map to both a and r.
  • Two maps catch both “same key, new value” and “new key, taken value”.

How this visualizer works

Compare egg and add, then switch the second string to bar to see a mapping conflict.

Interactive trace

hash_table.state

Input
Hash table
Current look-up
Match / window
Stored entry

current_action

Load an input, then press Play or Step.

live_trace.py

1def isIsomorphic(s, t):
2st, ts = {}, {}
3for a, b in zip(s, t):
4if a in st and st[a] != b: return False
5if b in ts and ts[b] != a: return False
6st[a], ts[b] = b, a
7return True

stdout — decision log

// each hash probe is recorded here
Speed Ready

Pseudocode & Complexity

idea.txt

1def isIsomorphic(s, t):
2st, ts = {}, {}
3for a, b in zip(s, t):
4if a in st and st[a] != b: return False
5if b in ts and ts[b] != a: return False
6st[a], ts[b] = b, a
7return True

complexity.md

OperationTime
Each pair of lettersO(1) expected
Full scanO(n)
SpaceO(Σ)

Python implementation

solution.py

1def isIsomorphic(s, t):
2 st, ts = {}, {}
3 for a, b in zip(s, t):
4 if a in st and st[a] != b:
5 return False
6 if b in ts and ts[b] != a:
7 return False
8 st[a], ts[b] = b, a
9 return True