-
This repository of mine (Phan Hong Thuc), is to record my learning progress about algorithms, specifically, from the course Algorithm, part I and Algorithm, part II (soon, hope so) on Coursera.
-
This repository is not meant to be a complete/perfect solution for the course (or for others to reference/consult), but rather a collection of my notes, code implementations, and exercises that I find useful during my learning journey.
- Visual Studio Code with "Extension Pack for Java" installed
- JDK 8 or higher (with proper
JAVA_HOMEset in your system environment) - Git (for cloning the repository)
- Clone this repository here:
git clone https://github.com/Thuk7749/coursera-algorithm.git - Open the project in Visual Studio Code
code coursera-algorithm - Ensure Java extension recognizes the project structure
- Try running a simple example:
cd part-one/01_hello-world; .\run_local.bat(if you are using Windows PowerShell) orcd part-one/01_hello-world && run_local.bat(if you are using Windows Command Prompt).
coursera-algorithm/
├── .vscode/
│ ├── launch.json*
│ └── settings.json
├── class*/
│ └── ...
├── part-one/
│ ├── run_all.bat
│ ├── 00_topic-template/
│ │ ├── test/
│ │ | └── MainTemplateTest.java
| | ├── MainTemplate.java
| | ├── run_local.bat
│ ├── 01_hello-world/
| | ├── test/
│ │ | └── HelloWorldTest.java
│ │ ├── HelloWorld.java
│ │ └── run_local.bat
│ └── ...
├── slides/
├── .gitignore
├── README.md
(The file/folder marked with * should be generated while working with Visual Studio Code, and be ignored by Git)
-
The
.vscodedirectory contains configuration files for Visual Studio Code, includinglaunch.jsonfor debugging configurations (you should create it yourself) andsettings.jsonfor Java project settings. -
The
classdirectory is where the compiled.classfiles are stored (if you compile the.javafiles), used to be run with VS Code "Run | Debug" button or "Run and Debug" feature. -
The
part-onedirectory contains the code for the first part of the course, organized into "topic folders" (e.g.,01_hello-world,02_data-types, etc.). Each topic folder contains:- A
testfolder with test files (if applicable). - A
.javafile with the main code implementation. - A
run_local.batfile to run the code easily.
- A
-
The
slidesdirectory contains the slides for the course.
- All the
.javafiles here are in the default (unnamed) package (because the submit instructions on Coursera require this).
- Open any
.javafile with amainmethod - Click the "Run" button above
public static void main - Limitation: Cannot pass command-line arguments easily
- Create/edit
.vscode/launch.jsonwith your specific configurations - Use "Run and Debug" panel (Ctrl+Shift+D)
- Advantage: Full control over arguments and debugging
-
Configuration example:
{ "version": "0.2.0", "configurations": [ { "type": "java", "name": "Debug BCP Client", "request": "launch", "mainClass": "BCPClient", "projectName": "coursera-algorithm_4cc8b159", // Project name may vary "args": "part-one/06_mergesort/input8.txt" } ] }
cd part-one
run_all.bat
# Follow prompts to select folder and file
- First, you'll select the "topic folder", then pick the
.javafile you want to run.- The script will compile and run your chosen
.javafile. You can enter command-line arguments if needed.- If a test file exists in the
testsubfolder with the same name as your.javafile plusTest(for example,HelloWorldTest.javaforHelloWorld.java), you can ask the script to also run those test cases automatically.
cd part-one/01_hello-world
run_local.bat
# Runs files in current directory
- This method makes it easier to include file names as command-line arguments, since you don't need to type the full file path.
- Create a new folder in the
part-*directory. - Add the folder to the Java classpath, by add the folder name to the
settings.jsonfile in the.vscodefolder, under thejava.project.sourcePathsproperty.
- Just place the
.jarfile in thepart-*directory, under thelibfolder (e.g.,part-one/lib/your-library.jar).
{
"java.project.referencedLibraries": ["part-*/lib/*.jar"],
"java.project.sourcePaths": [
"part-one/00_topic-template",
"part-one/00_topic-template/test", // The test folder should be listed here, too
"part-one/01_hello-world",
"part-one/01_hello-world/test",
"part-one/02_union-find",
"part-one/02_union-find/test",
"part-one/03_algorithm-analysis",
"part-one/03_algorithm-analysis/test",
"part-one/04_stack-and-queue",
"part-one/04_stack-and-queue/test",
"part-one/05_elementary-sorts",
"part-one/05_elementary-sorts/test",
"part-one/06_mergesort",
"part-one/06_mergesort/test"
],
"java.project.outputPath": "class"
}