Avi*_*ash 5 c++ algorithm data-structures
我试图从http://linux.thai.net/~thep/datrie/datrie.html了解双阵列 Trie 实现 但我不明白以下部分。
check[base[s] + c] = s
base[s] + c = t
Run Code Online (Sandbox Code Playgroud)
添加c在这里是什么意思。
谁能用简单的语言解释算法。
想象一下您将 2D 数组折叠成 1D 数组:
int arr2D[2][3];
int arr1D[2 * 3]; // # of rows * # of columns
// access element [1][2] of 2D array, i.e., the last element
int elem2D = arr2D[1][2];
// access element [1][2] of 1D array, i.e., the last element
int elem1D = arr1D[1 * 3 + 2];
// =========================================================
lets visualize the array access:
arr2D => x/y 0 1 2
0 [N][N][N]
+1 on x > 1 [N][N][N]
+2 on y ---------- ^
y_len => ^-------^ 3 elements
so the access happens with x * y_len + y
1 * 3 + 2
now for the 1D array
we want the second row, so we go with 1 * 3
(0-based access, y_len = 3)
and then we want the 3rd element, so + 2
(again, 0-based access)
arr1D => x 0 1 2
[N][N][N]
3 4 5
1 * 3 = 3 > [N][N][N]
+ 2 = 5 ---- ^
Run Code Online (Sandbox Code Playgroud)
我希望我没有让这变得太复杂(尽管我认为我做到了......)。:)