Tải bản đầy đủ (.pdf) (73 trang)

Mastering Algorithms with Perl phần 10 pot

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (178.1 KB, 73 trang )

crack program, 529
cracking (guessing) passwords, 529-532
cross edges, 317
cross product, 435
cryptography, 526-565
authorizing data, 533-537
authorizing passwords, 528-533
encrypted source code, 562-564
encryption, 538-555
legal issues 527
security issues in general, 564
steganography, 555-558
winnowing and chaffing, 558-562
crypt( ) function, 529
cubic( ), 268, 637
cubic equations, finding roots, 636
cubic splines, 644-647
customizing
algorithms, 5
data structures, 26
cycles, 301
Euler and Hamiltonian cycles, 311
in graphs, 277
negative cycles, 334, 337
D
DAGs (directed acyclic graphs), 304, 312
single-source shortest paths, 338
data
access methods, 526
authentication and integrity, 533-537
discarding invalid (winnowing), 558


hiding (steganography), 555-558
passwords, authorizing, 528-533
smoothing, 648
data encryption (see encryption)
Data Encryption Standard (see DES)
data link escape (DLE) character, 414
data structures, 22, 24-101
arrays/lists (see arrays)
binary trees, 314
preorder, postorder, inorder, 314
searching, 167-171
constructed, 34
garbage collection (see garbage collection)
hashes (see hashes)
heaps, 91-101
binary heaps, 92-99
Heap modules, 99
Janus heaps, 99
linked lists, 47-59
circular, 60-62
doubly-linked lists, 65-71
tracking both ends, 52-55
lookup searching and, 159, 173
matrices (see matrices)
sets (see sets)
traversal performance, 72
union-tree forests, 326
within arrays, 37-45
dataflow analysis, 396
Date: :Calc module, 489

Date: :Convert module, 490
Date: :GetDate module, 490
Date: :Manip module, 489
dates and times, 489
datetab( ), 168
daVinci package, 301
DB_File module, 170
DBL_EPSILON constant, 473
dealing cards, 589break
Page 663
debugging
heaps, 101
silencing warnings, 135
decile( ), 142
decimal numbers, 481
decimal point, rounding to, 474
declaring scalars, 4
decryption (see encryption)
decrypt.xs file, 562-563
definite integrals, computing, 631-634
degree( ), 297
degree of graph vertices, 279-281, 296
delete_edge( ), 297
delete_edges( ), 297
delete operator, 205
delete_vertex( ), 297
deleting
binary tree elements, 77, 80-81, 84
graph edges and vertices, 297-299
linked list elements, 55, 60

set members (subtracting), 205, 218
delimiters, balancing, 410
dense sets, 229
density, graph, 285, 296
density_limits( ), 296
dependency graphs, 304
dependent events, 569
dependent variables, 620
depth-first search, 193, 301-304
graph traversal, 309, 314
deques, 40-42
circular linked lists vs., 60
dereferencing, 5
deriv( ), 628, 638
derivatives, computing, 628-629
Jacobian matrix, 629-631
derived graphs, 281-285
complement graph, 284
complete graph, 282
graph transpose, 282
DES (Data Encryption Standard), 528, 543
Perl implementation (SSLeay), 543
DES-EDE and DES-EDE3 encryption algorithms, 543
descendant vertices, 315
destroy( ) (double package), 66, 68
DESTROY( ), 65, 68, 70
det_LR( ), 262
determinant, matrix, 262
deterministic finite automata (DFA), 354, 396
DFA: :Kleene module, 231

DFS (depth-first search), 301-304
graph traversal, 309, 314
dictionary order, 107
die_roll( ), 577
difference( ), 220
difference levels (Wu-Manber), 382
differences and fuzzy matching, 379
differences, sets, 217-222
differential analysis, 543
Diffie, Whitfield, 548
digital images, secret messages in, 555
digital signatures, 537
El Gamal public key encryption, 552
Dijkstra's single-source shortest paths, 334-337
dimensions (see size)
directed acyclic graphs (DAGs), 304, 312
single-source shortest paths, 338
directed graphs and edges, 277-279, 291-293
directed( ), 292
direction, specifying, 433-435
directional alternative hypotheses, 612
directories, searching with B-trees, 169
discrete probability distributions, 575
algorithms for (list), 592-598
expected value, 575
disjointed sets, 223
disk space, 9-11
caching, 16
lookup tables, 9
display( ) (position), 177

display_poker( ), 587
display_poker_many( ), 587
distance( ), 427
distance, calculating, 426-429
distributions (see probability distributions)
divergent series, 494
divide-and-conquer strategy, 21, 134
closest pair of points, 457
division
modular, 513
numeric precision and, 574
divisors, 499
greatest common (see GCD)
DLE character, 414break
Page 664
Dominus, Mark-Jason, 71, 113, 171, 386, 416, 505
double package (example), 65
double-ended queues (deques), 40-42
circular linked lists vs., 60
double_head package, 68
doubly-linked lists, 65-71
downloading files, risks, 534
dynamic programming, 22, 202
matrix chain products, 269
dynamic variables, 36
E
eavesdropping, 529
ECB (Electronic Code Book), 543
edge_classify( ), 318
edges, graph, 276-281

adding and testing for, 291-293
attributes, 299
classes, 279-281, 316-320
deleting, 297-299
direction, 277-279
graph density, 285, 296
walking (see traversing graphs)
weight/cost, 286, 334
(see also graphs)
editing algorithms, 5
Edmonds-Karp algorithm, 348
Edmonds-Karp flow network, 307
efficiency of algorithms, 8-20
arrays and hashes, 27-29, 33, 43
Benchmark module, 11
caching, 16
dynamic allocation, 37
floating-point numbers, 14
heaps, 92
linked lists, 47
tail pointers, 54
list traversal performance, 72
O (N) notation, 17-20
recursion, 21
regular expressions, 355
searching, 157
lookup searches, 172-175
sets, 243
membership sets, 216
power set generation, 239

sorting, 108-116, 145-150
bubble sort, 126
external sorting, 150
insertion sort, 129
sensitivity and stability, 119
shellsort, 132
summary and comparison, 151-156
string matching
naïve searching, 361
Rabin-Karp algorithm, 369
tips for regular expressions, 355
temporary variables, 14
eigen_c( ), 266
eigenvalue( ), 268
eigenvalues and eigenvectors, 266-269
direct eigenvalue calculation, 268
El Gamal public key encryption, 552-554
Electronic Code Book (ECB), 543
elements of matrices, 246
elements of sets (see members of sets)
emit( ), 402-403
empty set, 213
encryption, 526, 538-554
algorithms (licensing), 527
authentication vs., 559
block unit size, 547
lost/stolen keys, 564
meet-in-the-middle attacks, 543
one-time pads, 538-540, 543
password storage, 528

of Perl source code, 562-564
product development (government restrictions), 527
public key, 533, 543, 548-554
El Gamal, 552-554
private key vs., 554
RSA, 549-552
random numbers, 568
shared-secret, 540-548
Caesar cipher, 540
differential analysis algorithm, 543
idea-ecb algorithm, 543
Solitaire algorithm, 542
SSLeay module for, 543-548
steganography vs., 555
winnowing and chaffing, 558-562
(see also cryptography)
encryption object, creating, 546
English stemming (see stemming)
epsilon, 472
eq statement, 359break
Page 665
equations, solving, 634-642
approximating roots, 638-640
multiple nonlinear equations, 640-642
quadratics and cubics, 635-638
Eratosthenes, sieve of, 504
erlang( ), 595
Erlang distribution, 595
erlang_expected( ), 595
erlang_variance( ), 595

error( ), 400, 404
estimate_variance( ), 614, 618
Euclidean distance, 426
euclid( ), 501
Euler cycles, 311
Euler path, 311
Euler tours, 311
Euler's formula, 485
evaluate( ) (position), 177
events, probability of, 566, 569-571
birthday conundrum, 570
distributions (see probability distributions)
multiple events, 569-571, 581
exact matching, 354
shift-OR exact matching, 377-379
exclusive binary or (XOR) operator, 220-221
exclusive logical or (xor) operator, 210
exclusive-or (XOR), 538, 540
exhaustive search, 180-185
alternatives to, 185-193
exists statement, 215
exp_mod( ), 519
exp_recurse( ), 517
exp_slow( ), 517
expected_value( ), 575
expected value, 575-576
of continuous distribution, 576
expected_value_weighted( ), 576
explicit stacks, 140
exponentation, 517-520

exponential( ), 595
exponential distribution, 595
exponential_expected( ), 595
exponential_variance( ), 595
exponentiation, 479
export restrictions (cryptography), 527, 543, 559
expression( ), 400-401, 403
exterior vertices, 320
external searches, 174
external sorting, 150
extract( ), 98, 556
extract_bracketed( ), 410
extract_codeblock( ), 410
extract_multiple( ), 411
extract_quotelike( ), 410
extract_tagged( ), 411
extract_variable( ), 411
extracting submatrices, 259
extrapolation, 642-648
F
F-ratio, 617-620
factor( ), 399-401
factorial( ), 478, 572
factorials, 15, 574
factoring large numbers, 549
false hits (string matching), 357, 365
feedback methods (encryption), 543
fibonacci( ), 494
fibonacci_iterative( ), 494
Fibonacci sequence, 493

Field Programmable Gate Array (FPGA), 543
fields for sorting (see keys, sorting)
fieldsort( ), 106
FIFO order, 38
file_crypt( ), 547
files
B-trees to search for, 169
content changes, detecting, 526
downloading, security risks, 534
encrypting/decrypting entire, 547
mailing (security risks), 527
Filter module, 562
filtering Perl source code, 562
finding (see searching)
finite arithmetic, 510
finite automata, 395-396
deterministic vs. nondeterministic, 396
fitting data, 642-648
fitting lines to data, 622-624
fixed-goal searches, 193-202
A* algorithm, 200-202
branch and bound method, 196-200
greedy algorithms, 195
flipping coins, 585break
Page 666
floating-point numbers, 14, 472, 567
factorials and, 574
floor( ), 474, 490
Flow_Ford_Fulkerson( ), 347
flow networks, 345-350

Floyd-Warshall algorithm, 339-342, 352
transitive closure, 342-344
Ford-Fulkerson method, 345-347
forward edges 317
FPGA (Field Programmable Gate Array), 543
frac( ), 480
fractions, 480
from_chinese( ), 514
fuzzy (approximate) matching, 353, 379, 388
Baeza-Yates-Gonnet shift-add algorithm, 379-382
Baeza-Yates-Gonnet shift-OR algorithm, 377
longest common subsequence (LCS), 386
regular expressions (String::Approx), 387
Wu-Manber k-differences algorithm, 382-387
(see also phonetic algorithms)
fuzzy sets, 241
G
game interface, 176-180
gamma( ), 595
gamma distribution, 595
gamma_expected( ), 595
gamma_variance( ), 595
garbage collection, 37, 62-65
gaussian( ), 592, 595
Gaussian distribution, 566, 591, 595
Gaussian elimination, 263-265, 634
gcd( ), 502
GCD (greatest common divisor), 500-503
expressed as linear combination, 503
gcd_linear( ), 503, 514

GD module, 465
gen_RSA_keys( ), 550
general_chinese( ), 512
generality of algorithms, 6-8
generalized Chinese remainder theorem, 511
generalized least square methods, 648
generative searching, 158, 175-202
exhaustive search, 180-185
game interface for, 176-180
killer move strategy, 189, 202
minimax search, 185-187, 193
opening book strategy, 192
pruning, 187-189, 192
symmetry, 192
transpose tables, 190-191
pruning with, 192
geometric( ), 596
geometric algorithms, 425-468
area, perimeter, volume, 429-433
boundaries, 449-456
bounding boxes, 450-451
convex hull, 452-456
closest pair of points, 457-464
direction, 433-435
distance, calculating, 426-429
general references on, 650
inclusion within polygons, 443-449
intersections, 435-443
line intersection, 435-443
Manhattan intersections, 440-443

trigonometry, 491
geometric distribution, 591, 596
geometric_expected( ), 596
geometric_progression( ), 492
geometric progressions, 492
geometric_variance( ), 596
German stemming, 393
get_attribute( ), 299
gextri( ), 124
GIF images, 465
Gimp utility, 465
GL language, 466
Glazebrook, Karl, 245, 466
Glimpse indexing system, 382
gmax( ), 123
gmaxi( ), 124
gmini( ), 124
goldbach( ), 524
Goldbach conjecture, 524
Golden Ratio, 12
good-suffix heuristic, 373, 375break
Page 667
goodness of fit, 624
government controls (cryptography), 527, 543, 559
grade( ), 607
gradients, computing, 629-631
grading test results, 607
Graham's scan algorithm, 452-456
grammars, 396-398
context-free, 397-398

Graph package, 273, 351
Graph: :Base class, 290, 299
Graph: :BFS class, 310
Graph: :DFS class, 309
Graph: :Directed class, 278, 293, 299
Graph: :Kruskal class, 231, 352
Graph: :Undirected class, 278, 293, 299
(see also graphs)
graphical application development, 467
graphics, general references on, 650
graphics modules, 464-468
graphs, 273-352
attributes, 286, 299
classes and connectivity, 279-281, 296, 316-326
biconnected graphs, 320-323
flow networks, 345-350
minimum spanning trees, 326-332
shortest paths, 332-342
strongly connected graphs, 323-326
transitive closure, 342-344
Traveling Salesman problem, 350
CPAN modules for, 351
creating, 290
deleting edges and vertices, 297-299
density, 285, 296
derived graphs 281-285
complete graph, 282
graph transpose, 282
displaying, 299
packages for, 301

edges (see vertices, graph)
general references on, 650
isomorphism, 275, 281
paths and bridges, 310-312, 320
representing in computers, 287-301
strongly connected components, 282
traversing, 275, 301-310
breadth-first search, 301, 307, 310
depth-first search, 301-304, 309, 314
implementation, 307-310
topological sort, 304-307, 309
vertices (see vertices, graph)
graphviz package, 301
great circle distance, 429
great_circle_distance( ), 429
greatest common divisor (see GCD)
greedy search algorithms, 195
Grossman, Etienne, 393
guessing passwords, 529-532
Gurusamy, Sarathy, 36, 117
gzip utility, 421-424, 568
H
Hall, Joseph N., 106
Halting Problem, 183
Hamiltonian cycles, 311
Hamiltonian path, 311, 350
Hamming distance, 379
Baeza-Yates-Gonnet shift-add algorithm, 379-382
hardware
eavesdropping, 529, 532

identification values, 532
patents (cryptography), 527
harmonic( ), 495
harmonic_approx( ), 495
harmomic series, 494
has_attribute( ), 299
has_vertex( ), 291
hash_set_to_bit_vector( ), 208
hash values, 26
hashes, 2, 26, 72
arrays vs., 27-29, 33
avoiding searching with, 158
copying lists, 35-37
emulating sets, 205-206
counting members, 222
power sets, 236-239
set differences, 220
set relations, 224
union and intersection, 213
graph representation, 289-301
hashes of hashes (hohs), 29
hashes of lists (hols), 29, 118
Huffman encoding, 417
inserting and deleting elements, 55
binary search and, 164
lists of hashes (lohs), 29break
Page 668
(cont'd)
hashes
lists of lists (lols), 29

lookup searching and, 174
sorting, 117-118
token recognition, 408
hashing algorithm, 362
Hayward, Gwilym, 161
heap( ), 101
Heap: :Binary module, 99
Heap: :Binomial module, 99
Heap: :Fibonacci module, 99
heapdown( ), 95-99
heapdump( ) (Heap modules), 101
heapify( ), 97, 136
heapify_array_down( ), 96-97
heapify_array_up( ), 96
heaps, 91-101
binary heaps, 92-99
branch and bound method, 196
caching prime numbers, 505
efficiency of, 92
finding maximum/minimum, 122-125
Heap modules, 99
heapsort, 135-136
Janus heaps, 99
heapup( ), 95-97
Hellman, Martin, 548
Heron's formula, 429
heuristic password guessing, 531
hex( ) function, 482
hexadecimal numbers, 481-483
Hickey, Gerard 565

hiding data (steganography), 555-558
Hietaniemi, Jarkko, 227, 241, 351, 387, 491
hits (string matching), 357
hohs (hashes of hashes), 29
hols (hashes of lists), 29
reversing element order, 118
Horner's rule, 363
Howland, Gary, 568
HP program 183
huff_decode( ), 416
huff_encode( ), 418
huff_hash( ), 417
huff_hash_subtree( ), 417
Huffman encoding, 416-421
hybrid lookup searches, 171-172
hybrid sorts, 147-150
hypergeometri( ), 596
hypergeometric distribution, 596
hypergeometric_expected( ), 596
hypergeometric_variance( ), 596
hypotheses, judging, 609
I
IDEA (International Data Encryption Algorithm), 543
idea-ecb encryption algorithm, 543
identification values, hardware, 532
identity matrix, 261
imag( ), 247
image compression, hidden messages and, 557
Image: :Size module, 465
ImageMagick library, 466

images, secret messages in, 555
imaginary (complex) numbers, 485
implementations of algorithms, 6
in_degree( ), 297
in-degree, vertex, 279
in site (in place) sorting, 119
inclusion within polygons, 443-449
incremental sum (Rabin-Karp), 365
independent events, 569
independent variables, 620
index( ), 354, 377
indices
array and hash elements, 26, 29
search window, 2
individuals using cryptography, 527
infinite discrete distributions, 590-591
infinite lists, 71
infinite sets, 230
infix notation, 405
inflection, 389-393
inform( ), 530
Ing-Simmons, Nick, 467
inheritance, 27
initializing hash set values, 233
initializing scalars, 4
inject( ), 556
inorder vertex processing, 314
ins( ), 260
insensitive sorting algorithms, 119
insertion_merge( ), 129, 152

insertion sort, 128-131, 152
insertion_sort( ), 129
InSPEC product, 537break
Page 669
int( ), 473
integers, 469-480
arithmetic, 470-471
choosing randomly, 577, 579-581
exponentiation, 517
rounding to, 473
integrals, computing, 631-634
integrate( ), 632
integrity of data, 533-537
interior elimination (Graham's scan), 455
Internal module, 490
International Data Encryption Algorithm (IDEA), 543
internationalization and sorting, 113-114
interpolation, 642-648
interpreters, 405-406
intersection( ), 213
intersections of lines, 435-443
line intersection, 435-443
Manhattan intersections, 440-443
intersections of sets, 211-217
bit vectors for, 216
hashes for, 213
intractable problems, 183-184
inverse, matrix, 261
is_dense( ), 297
is_head( ), 577

is_prime( ), 520-522
is_source_vertex( ), 297
is_sparse( ), 297
is_subset( ), 225
ISO encoding, 363
isomorphism, graphs, 275, 281
iterative vs. recursive algorithms, 21
J
jacobian( ), 630, 640
Jacobian matrix, 629-631, 640
Janus heaps, 99
joining binary trees, 85-86
junk messages, adding (chaffing), 558
K
k-connected graphs, 286, 320
keys, encryption, 540, 542
converting from hex to bytes, 548
interchanging public and private, 552
lost or stolen, 564
keys, hashes, 26
emulating sets, 205, 213
keys, sorting, 102
killer move strategy, 189, 202
Kim, Gene, 536
k-mismatches measure, 379
Wu-Manber algorithm, 382-387
knuth_morris_pratt( ), 372
Knuth-Morris-Pratt algorithm, 395
knuth_morris_pratt_next( ), 371
Knuth-Morris-Pratt algorithm, 370-372

Kruskal's minimum spanning tree, 326-329, 352
Königsberg, 311
L
Landis, E. M., 78
laplace( ), 596
Laplace distribution, 596
laplace_expected( ), 596
laplace_variance( ), 596
last occurrence heuristic, 373
LCM (least common multiple), 504
lcm( ), 504
LCS (longest common subsequence), 386
ldump( ) (double_head), 70
leaf vertices, 312
least common multiple (LCM), 504
legal issues (cryptography), 526-527
Lehman, Marc, 465
Leroy, Jean-Louis, 228
Levenshtein edit distance, 379
Wu-Manber algorithm, 382
Lewis, Glenn M., 466
lexing, 394
modules for, 406-411
libgd library, 465
licensing (cryptography), 527
LIFO order, 39
#line directive, 563
line_intersect( ), 439
line_intersection( ), 436
linear( ), 636

linear combination theorem, 500
linear congruential generators, 567
linear least squares method, 622
linear search, 161

×