Skip to content

KTH-DD2480-Group-2/Algorithms

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

License: MIT Java CI with Gradle README Checker

Algorithms & data structures project

Algorithms and data structures are fundamental to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. This repository's goal is to demonstrate how to correctly implement common data structures and algorithms in the simplest and most elegant ways.

DD2480 - Group 2 Paragraph

DIY Branch Coverage tool

Use the BranchCoverageAnalyser to mark all the branches in you function. See the getTreeDisplay() in TreePrinter.java for a full example how it should be used (The example is not perfect however, many branches are not checked). Remember to also put all the branch ids that you create in the diy-branch-coverage-control.txt file.

Pro tip! In order to also cover conditional expression, you can use the BranchCoverageAnalyser.markCoveredValue() function. See line 100 in getTreeDisplay().

To see the statistics report run gradle build first and then execute com.williamfiset.algorithms.utils.CoverageStatistics.main(). The report will be generated in build/reports/DIY-Coverage-Report.txt

Lizard Results

NLOC CCN token PARAM length location
58 17 551 1 81 TreeIsomorphismWithBfs::encodeTree@63-143@./src/main/java/com/williamfiset/algorithms/graphtheory/treealgorithms/TreeIsomorphismWithBfs.java
55 23 469 0 69 TspDynamicProgrammingIterative::solve@55-123@./src/main/java/com/williamfiset/algorithms/graphtheory/TspDynamicProgrammingIterative.java
26 17 399 0 26 SubstringVerificationSuffixArray::SuffixArray::construct@56-81@./src/main/java/com/williamfiset/algorithms/strings/SubstringVerificationSuffixArray.java
26 17 399 0 26 LongestCommonPrefixArray::SuffixArray::construct@54-79@./src/main/java/com/williamfiset/algorithms/strings/LongestCommonPrefixArray.java
26 17 399 0 26 LongestRepeatedSubstring::SuffixArray::construct@58-83@./src/main/java/com/williamfiset/algorithms/strings/LongestRepeatedSubstring.java
22 31 290 3 66 Solution::f@15-80@./src/main/java/com/williamfiset/algorithms/dp/examples/domino-and-tromino-tiling/Solution.java
35 20 593 4 68 LineSegmentLineSegmentIntersection::lineSegmentLineSegmentIntersection@41-108@./src/main/java/com/williamfiset/algorithms/geometry/LineSegmentLineSegmentIntersection.java
113 91 1384 4 150 QuadTree::Node::knn@166-315@./src/main/java/com/williamfiset/algorithms/datastructures/quadtree/QuadTree.java
30 17 442 0 31 SuffixArrayFast::construct@32-62@./src/main/java/com/williamfiset/algorithms/datastructures/suffixarray/SuffixArrayFast.java
83 24 468 3 93 GenericSegmentTree::GenericSegmentTree@165-257@./src/main/java/com/williamfiset/algorithms/datastructures/segmenttree/GenericSegmentTree.java
58 16 318 0 68 GenericSegmentTree2::GenericSegmentTree2@177-244@./src/main/java/com/williamfiset/algorithms/datastructures/segmenttree/GenericSegmentTree2.java
82 27 736 1 97 TreePrinter::getTreeDisplay@23-119@./src/main/java/com/williamfiset/algorithms/datastructures/utils/TreePrinter.java
72 21 611 0 101 GenericSegmentTreeTest::testAllFunctionCombinations@222-322@./src/test/java/com/williamfiset/algorithms/datastructures/segmenttree/GenericSegmentTreeTest.java
Total nloc Avg.NLOC AvgCCN Avg.token Fun Cnt Warning cnt Fun Rt nloc Rt
28870 9.4 2.5 84.5 2696 13 0.00 0.03

Statement of contributions

  • Lara: chose lineSegmentLineSegmentIntersection() in LineSegmentLineSegmentIntersection.java and construct() in SubstringVerificationSuffixArray.java, manually counted CC of lineSegmentLineSegmentIntersection(), wrote four tests for lineSegmentLineSegmentIntersection(), created a refactoring plan and refactored lineSegmentLineSegmentIntersection(), documented the process of this assignment.
  • Adam Jonsson: chose getTreeDisplay(), in TreePrinter.java.
    • Created 4+ tests to increase coverage
    • Manually counted CC
    • Create a refactoring plan and refactored
    • documented the process of this assignment.
    • Did also create the DIY coverage analyser
  • Isak: chose encodeTree() in TreeIsomorphismWithBfs. Manually counted CC of encodeTree(). Wrote four tests for encodeTree(). Wrote a refactoring plan for encodeTree(). Contributed to the assignment report.
  • Tony: Improved GenericSegmentTree() in GenericSegmentTree.java by writing 4 tests and a refactoring plan, as well as manually counted the CC for that method and knn() in QuadTree.java.
  • Hovig: chose knn() in QuadTree.java
    • Created 4+ tests to increase coverage.
    • Manually counted CC for this function and two other.
    • Create a refactoring plan and refactored achieving complexity reduction of >35%.
    • Developed the statistic tool for the DIY coverage analyser.
    • Documented the usage of the DIY tool in README.md.
    • Implemented the DIY coverage tool.

Contributing

This repository is contribution friendly πŸ˜ƒ. If you'd like to add or improve an algorithm, your contribution is welcome! Please be sure to checkout the Wiki for instructions.

Other programming languages?

This repository provides algorithm implementations in Java, however there are other forks that provide implementations in other languages, most notably:

Running an algorithm implementation

To compile and run any of the algorithms here, you need at least JDK version 8. Gradle can make things more convenient for you, but it is not required.

Running with Gradle (recommended)

This project supports the Gradle Wrapper. The Gradle wrapper automatically downloads Gradle at the first time it runs, so expect a delay when running the first command below.

If you are on Windows, use gradlew.bat instead of ./gradlew below.

Run a single algorithm like this:

./gradlew run -Palgorithm=<algorithm-subpackage>.<algorithm-class>

Alternatively, you can run a single algorithm specifying the full class name

./gradlew run -Pmain=<algorithm-fully-qualified-class-name>

For instance:

./gradlew run -Palgorithm=search.BinarySearch

or

./gradlew run -Pmain=com.williamfiset.algorithms.search.BinarySearch

Compiling and running with only a JDK

Create a classes folder

cd Algorithms
mkdir classes

Compile the algorithm

javac -sourcepath src/main/java -d classes src/main/java/ <relative-path-to-java-source-file>

Run the algorithm

java -cp classes <class-fully-qualified-name>

Example

$ javac -d classes -sourcepath src/main/java src/main/java/com/williamfiset/algorithms/search/BinarySearch.java
$ java -cp classes com.williamfiset.algorithms.search.BinarySearch

Data Structures

Dynamic Programming

Dynamic Programming Classics

Dynamic Programming Problem Examples

Adhoc

Tiling problems

Geometry

Graph theory

Tree algorithms

Network flow

Main graph theory algorithms

Linear algebra

Mathematics

Other

Search algorithms

Sorting algorithms

String algorithms

License

This repository is released under the MIT license. In short, this means you are free to use this software in any personal, open-source or commercial projects. Attribution is optional but appreciated.

About

A collection of algorithms and data structures

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 99.2%
  • Other 0.8%