Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Personal implementation of some algorithms in "Introduction to Algorithms", third edition; new repo

License

NotificationsYou must be signed in to change notification settings

lxylxy123456/algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

algorithms

Personal implementation of some algorithms in "Introduction to Algorithms",third edition

Contents

Ch.NameAlgorithmPage
2InsertSortInsersion Sort18
MergeSortMerge31
Merge Sort34
4FindMaximumSubarrayFind Max Crossing Subarray71
Find Maximum Subarray72
 Square Matrix Multiply75
Square Matrix Multiply Recursive77
Square Matrix Multiply Strassen82
5HireAssistantHire Assistant115
Randomized Hire Assistant124
RandomPermutePermute By Sorting125
Randomize In Place126
OnLineMaximumOn Line Maximum140
6MaxHeapMax Heapify154
Build Max Heap157
Heap Sort160
Heap Maximum163
Heap Extract Max163
Heap Increase Key164
Max Heap Insert164
Build Max Heap prime167
7QuicksortQuicksort171
Partition171
Randomized Partition179
Randomized Quicksort179
8CountingSortCounting Sort195
RadixSortRadix Sort198
BucketSortBucket Sort201
9MinimumMinimum214
Maximum214
Min Max214
RandomizedSelectRandomized Select216
Randomized Select Iter219
SelectSelect220
10StackStackEmpty233
Push233
Pop233
QueueEnqueue235
Dequeue235
LinkedListList Search237
List Insert238
List Delete238
List Delete prime238
List Search prime239
List Insert prime239
StorageManageAllocate Object244
Free Object244
11DirectAddressDirect Address Search254
Direct Address Insert254
Direct Address Delete254
ChainedHashChained Hash Insert258
Chained Hash Search258
Chained Hash Delete258
HashDivision Hash263
Multiplication Hash263
Universal Hash263
OpenAddressHash Insert270
Hash Search271
12BinaryTreeInorder Tree Walk288
Preorder Tree Walk289
Postorder Tree Walk289
BinarySearchTreeTree Search290
Iterative Tree Search291
Tree Minimum291
Tree Maximum291
Tree Successor292
Tree Predecessor293
Tree Insert294
Transplant296
Tree Delete298
13RedBlackTreeLeft Rotate313
Right Rotate313
RB Insert315
RB Insert Fixup316
RB Transplant323
RB Delete324
RB Delete Fixup326
14OrderStatisticTreeOS Select341
OS Rank342
IntervalTreeInterval Search351
15CutRodCut Rod363
Momorized Cut Rod365
Momorized Cut Rod Aux366
Bottom Up Cut Rod366
Extended Bottom Up Cut Rod369
Print Cut Rod Solution369
MatrixChainOrderMatrix Multiply371
Matrix Chain Order375
Print Optimal Parens377
Recursive Matrix Chain385
Memorized Matrix Chain388
Lookup Chain388
LCSLengthLCS Length394
Print LCS395
OptimalBSTOptimal BST402
16ActivitySelectorRecursive Activity Selector419
Greedy Activity Selector421
HuffmanHuffman431
GreedyGreedy440
TaskScheduleTask Schedule446
17StackMulti Pop453
BinaryCounterIncrement454
DynamicTableTable Insert464
18BTreeB Tree Search491
B Tree Create492
B Tree Split Child494
B Tree Insert495
B Tree Insert Nonfull495
B Tree Delete502
19FibHeapMake Fib Heap510
Fib Heap Insert510
Fib Heap Minimum511
Fib Heap Union512
Fib Heap Extract Min513
Consolidate516
Fib Heap Link516
Fib Heap Decrease Key519
Cut519
Cascading Cut519
Fib Heap Delete522
20ProtovEBProto vEB Member541
Proto vEB Minimum542
Proto vEB Maximum542
Proto vEB Successor543
Proto vEB Predecessor543
Proto vEB Insert544
Proto vEB Delete544
vEBvEB Tree Minimum550
vEB Tree Maximum550
vEB Tree Member550
vEB Tree Successor551
vEB Tree Predecessor552
vEB Empty Tree Insert553
vEB Tree Insert553
vEB Tree Delete554
21DisjointSetConnected Components563
Same Component563
Make Set571
Union571
Link571
Find Set571
22BFSBFS595
Print Path601
DFSDFS604
DFS Visit604
TopologicalSortTopological Sort613
SCCStrongly Connected Components617
23MSTMST Kruskal631
MST Prim634
24BellmanFordInitialize Single Source648
Relax649
Bellman Ford651
DagShortestPathsDag Shortest Paths655
DijkstraDijkstra658
25FloydWarshallPrint All Pairs Shortest Path685
AllPairsShortestPathsExtend Shortest Paths688
Slow All Pairs Shortest Paths689
Faster All Pairs Shortest Paths691
FloydWarshallFloyd Warshall695
TransitiveClosureTransitive Closure698
JohnsonJohnson704
26FordFulkersonFord Fulkerson724
MaximumBipartiteMatchingMaximum Bipartite Matching733
RelabelToFrontPush739
Relabel740
Initialize Preflow740
Discharge751
Relabel To Front755
27FibFib775
P Fib776
MatVecMat Vec785
Mat Vec Main Loop785
RaceExampleRace Example788
MatVecMat Vec Wrong790
PSquareMatrixMultiplyP Square Matrix Multiply793
P Matrix Multiply Recursive794
P Matrix Multiply Strassen794
PMergeSortMerge Sort prime797
Binary Search799
P Merge800
P Merge Sort803
28LUPSolveLUP Solve817
LU Decomposition821
LUP Decomposition824
MatrixInverseMatrix Inverse828
LeastSquareApproxLeast Square Approx837
29SimplexPivot869
Simplex871
Initialize Simplex887
30RecursiveFFTRecursive FFT911
Inverse FFT913
Polynomial Multiply914
IterativeFFTIterative FFT917
Bit Reversal Copy918
31EuclidEuclid935
Extended Euclid937
ModLinEquationSolverModular Linear Equation Solver949
ModularExponentiationModular Exponentiation957
PseudoprimePseudoprime967
MillerRabinWitness969
Miller Rabin970
PollardRhoPollard Rho977
32NaiveStringMatcherNaive String Matcher988
RabinKarpMatcherRabin Karp Matcher993
FiniteAutomatonMatcherFinite Automaton Matcher999
Compute Transition Function1001
KMPMatcherKMP Matcher1005
Compute Prefix Function1006
33SegmentsIntersectSegments Intersect1018
Direction1018
On Segment1018
AnySegmentsIntersectInsert1024
Delete1024
Above1024
Below1024
Any Segments Intersect1025
GrahamScanGraham Scan1031
JarvisMarchJarvis March1038
ClosestPairPointsClosest Pair Points1043
35ApproxVertexCoverApprox Vertex Cover1109
ApproxTSPTourApprox TSP Tour1112
GreedySetCoverGreedy Set Cover1119
ApproxMinWeightVCApprox Min Weight VC1126
SubsetSumExact Subset Sum1129
Trim1130
Approx Subset Sum1131

Directory Structure

  • include/<Name>.hpp: header file that contains the actual algorithm
  • src/<Name>Main.hpp: C++ program that runs the algorithm on some data
  • src/<Name>Test.hpp: C++ program that runs test on the algorithm
  • bin/<Name>(Main|Test): Executable ofsrc/<Name>(Main|Test).hpp
  • bin/<Name>(Main|Test).d: Dependencies ofsrc/<Name>(Main|Test).hpp

Supplementary Files

  • Graph.hpp,GraphMain.cpp,GraphTest.cpp:Graph-related classes
  • graph_utils.hpp: utility functions for graphs
  • output_integers.hpp: print a vector
  • print_ptr.hpp: print a pointer
  • print_tree.hpp: print a tree using ASCII art (inspired by UBC CS221)
  • random_integers.hpp: generate a random integer or vector of integers
  • utils.hpp: utility functions for cpp files

Supplementary Programs

  • include_check.py: identifies unnecessary includes
  • dot.sh: generate a graphviz graph from stdin

Example

$ ls include/Fib.hpp src/FibMain.cpp src/FibTest.cppinclude/Fib.hpp  src/FibMain.cpp  src/FibTest.cpp$ make bin/FibMain> /dev/null$ bin/FibMainn       a       b       a == b10      55      55true$ bin/FibMain 19n       a       b       a == b19      4181    4181true$ make bin/FibTest> /dev/null$ bin/FibTest0       0       0       01       1       1       12       1       1       13       2       2       24       3       3       35       5       5       56       8       8       87       13      13      138       21      21      219       34      34      3410      55      55      5511      89      89      8912      144     144     14413      233     233     23314      377     377     37715      610     610     61016      987     987     98717      1597    1597    159718      2584    2584    258419      4181    4181    418120      6765    6765    6765$echo$?0$

Continuous Integration

.github/workflows/build.yml defines the continuous integration workflow ofthis project. All the targets are built and tested. The CI succeeds if all testspass.

Difference from the "algorithm" project

  • Separated header files from main functions.
  • Added tests to all algorithms.
  • Fixed some bugs in algorithms.
  • Added continuous integration (CI) using Github Actions.
  • Switched to usingstd::mt19937 to generate random numbers.
  • Removed dependencies on non-original work (printtree.hpp).
  • Resolved memory leaks.

About

Personal implementation of some algorithms in "Introduction to Algorithms", third edition; new repo

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp