This module contains Java 17 implementations of two core Data Structures and Algorithms (DSA) concepts that directly model and support the operational flow of TaskFlow AI.
- Overview & Purpose
- Concept 1: Priority Queue Task Scheduler
- Concept 2: Topological Task Dependency Graph
- Complexity Analysis Table
- How to Run the Code
As a project management tool built for students, freelancers, and teams, TaskFlow AI relies heavily on sequencing workflows logically. This module translates those systems into Java code:
- Priority Queue: Schedules tasks in an optimal sequence based on priority levels, deadlines, and creation histories.
- Topological Sort: Resolves task-to-task dependency graphs and detects recursive loops (circular references) that prevent sprint execution.
In a project workspace, users deal with multiple tasks carrying varied deadlines and urgency tiers. A simple list doesn't scale for scheduling. This module implements a Priority Scheduler using a Binary Min-Heap representation to retrieve the next most urgent task instantly.
- Urgency Rank:
Critical>High>Medium>Low. - Deadline Tie-Breaker: Earlier due date wins.
- Creation Tie-Breaker: Earlier creation timestamp wins (First-In, First-Out for equal properties).
This logic mirrors the backend query sorting filters. When the AI Copilot builds the Daily Plan, it processes tasks in this order to guide the user's focus.
Tasks are often dependent on others (e.g., "Write API validation" must happen before "Integrate Frontend"). A Directed Graph maps these relations where vertices are tasks and directed edges represent dependencies.
To compute a chronological execution path, we use Kahn's Algorithm (Breadth-First Search topological sort):
- Compute the incoming dependency count (in-degree) for all task vertices.
- Store vertices with an in-degree of
0(no preceding dependencies) in a queue. - Dequeue a task, add it to the final execution order, and decrement the in-degree of all tasks depending on it.
- If a depending task's in-degree reaches
0, enqueue it. - If the final ordered list has fewer elements than the total vertices in the graph, it signifies a circular loop, and a
CircularDependencyExceptionis thrown.
| DSA Concept | Operation | Time Complexity | Space Complexity | Rationale |
|---|---|---|---|---|
| Priority Queue | Add Task (Enqueue) | Inserting elements into a Binary Heap takes logarithmic time to bubble up the tree structure. | ||
| Priority Queue | Next Task (Dequeue) | Removing the root element requires reheapification to maintain structural properties. | ||
| Priority Queue | Peek Task | Inspecting the root element takes constant time. | ||
| Graph & Topo Sort | Build Graph | Vertices ( |
||
| Graph & Topo Sort | Resolve Sort | Every vertex and edge is traversed exactly once during queue-based BFS reductions. |
Mentors can run and test both programs directly in the terminal:
Navigate to the directory and run:
cd priority-queue javac *.java java Main
========================================================
TaskFlow AI - Priority Queue Task Scheduler Demo
========================================================
Adding tasks to scheduler...
Initial queue size: 5
Retrieving tasks in scheduled priority order:
1. Task[ID=T3, Title='Fix Atlas connection timeout', Priority=CRITICAL, DueDate=2026-07-19]
- Title: Fix Atlas connection timeout
- Urgency Tier: CRITICAL
...
Navigate to the directory and run:
cd graph javac *.java java Main
========================================================
TaskFlow AI - Task Dependency Topological Sort Demo
========================================================
--- Scenario 1: Valid Dependency Schedule ---
Successfully resolved execution order!
Step 1: Design UI
Step 2: Backend API
Step 3: Write Docs
Step 4: Testing
Step 5: Deployment
--- Scenario 2: Circular Dependency Detection ---
...
SUCCESS: Expected exception caught!
Error Message: Circular dependency detected! A valid scheduling sequence cannot be resolved because some tasks form a dependency loop.
========================================================