Menu
Getting Started with Algorithms, Part I

Getting Started with Algorithms, Part I

🧰 Environment Setup & IDE Tips

This note documents the setup process for the Princeton Algorithms course. It uses Linux with IntelliJ IDEA and the algs4.jar library. It also captures key lessons from debugging the first assignment.


💡 IntelliJ IDEA: What Not to Do

  • Do not click “New Project” — this is meant for advanced configurations.
  • ✅ Always use “Open” and select the entire project folder, not individual .java files.
  • 🧭 Use the provided project zip from Lift Setup Guide to ensure correct structure and classpath.

🧭 What Happened During Setup

  1. Missing Libraries at Compile Time
    Attempted to compile Barnsley.java using javac-introcs, but got import errors for StdDraw and StdRandom.
    ➤ Cause: algs4.jar was missing from the classpath.

  2. Located algs4.jar
    Found inside /usr/local/lift/lib/, confirming the Lift installer worked.

  3. Patched Compile-Time Script
    Edited /usr/local/bin/javac-introcs to include algs4.jar in the CLASSPATH.

  4. Runtime Error: NoClassDefFoundError
    Compilation succeeded, but running with java-introcs failed due to missing runtime classpath.

  5. Patched Runtime Script
    Edited /usr/local/bin/java-introcs similarly to include algs4.jar.


📦 Assignment 0: Hello, World

Based on Assignment Spec:

  • Write HelloWorld.java and HelloGoodbye.java to test basic compilation and command-line arguments.
  • Use RandomWord.java to test StdIn, StdOut, and StdRandom from algs4.jar.
  • Compile using:

    javac-introcs HelloWorld.java
    
  • Run using:

    java-introcs HelloWorld
    

🔗 Solution: HelloWorld.java

See the solution file in the repository: HelloWorld.java

public class HelloWorld {
   public static void main(String[] args) {
      System.out.println("Hello, World");
   }
}

🧪 Verification Checklist

  • ✅ Java 11 installed (java -version)
  • algs4.jar accessible in /usr/local/lift/lib/
  • ✅ IntelliJ configured with correct SDK and project folder
  • javac-introcs and java-introcs patched with correct classpath

📚 References


This note is part of the structs-algos-unix series and will be auto-synced to My Portfolio using the netlify-build.sh script.