Skip to content

Chapter 16: Finding, Counting, and Listing All Triangles in Large Graphs

Programs of chapter 16 of the book Data Algorithms (O'Reilly, 2015), running on Spark 4.3.0.

Chapter notes: chap16/scala

Sample input: data/chap16/edges.txt

Run the commands from the repository folder after building the jar (Running the programs).

Spark (Java)

chap16.spark.CountTriangles

Source: CountTriangles.java

scripts/run_spark.sh org.dataalgorithms.chap16.spark.CountTriangles data/chap16/edges.txt /tmp/data-algorithms/chap16.spark.CountTriangles/output

chap16.spark.CountTrianglesWithLambda

Source: CountTrianglesWithLambda.java

scripts/run_spark.sh org.dataalgorithms.chap16.spark.CountTrianglesWithLambda data/chap16/edges.txt /tmp/data-algorithms/chap16.spark.CountTrianglesWithLambda/output

Spark (Scala)

chap16.scala.CountTriangles

Source: CountTriangles.scala

scripts/run_spark.sh org.dataalgorithms.chap16.scala.CountTriangles data/chap16/edges.txt /tmp/data-algorithms/chap16.scala.CountTriangles/output

MapReduce (Hadoop)

chap16.mapreduce.TriangleCounterDriver

Source: TriangleCounterDriver.java

scripts/run_mapreduce.sh org.dataalgorithms.chap16.mapreduce.TriangleCounterDriver data/chap16/edges.txt /tmp/data-algorithms/chap16.mapreduce.TriangleCounterDriver/output
  • Writes to triangles/ in the current directory; delete it first if it exists: rm -r triangles