# (DD50) Business Logic — quiks.quickSort() [12 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `algo_Calc.quiks` |
| Layer | Utility |
| Module | `algo_Calc` (Package: `algo_Calc`) |

## 1. Role

### quiks.quickSort()

This method implements the recursive Quick Sort control routine for an integer array segment. Its business role is to sort a contiguous range of numeric values in ascending order by delegating the pivot selection and partitioning work to `partition()` and then recursively sorting the left and right subranges around the returned pivot index. In practical system terms, it is a reusable in-memory ordering utility rather than a domain transaction service, and it can be called whenever the application needs to present or further process numeric data in sorted sequence. The method follows a divide-and-conquer dispatch pattern: it first determines the pivot boundary, then conditionally recurses only into subranges that still contain more than one element. Because it operates only on the provided array slice and uses no external resources, its effect is limited to rearranging values in the caller-owned array.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START["quickSort(num, start, end)"]
    P1["Call partition(num, start, end)"]
    D1{"partition - 1 > start"}
    R1["Call quickSort(num, start, partition - 1)"]
    D2{"partition + 1 < end"}
    R2["Call quickSort(num, partition + 1, end)"]
    END_NODE["Return / Next"]

    START --> P1
    P1 --> D1
    D1 -- "Yes" --> R1
    D1 -- "No" --> D2
    R1 --> D2
    D2 -- "Yes" --> R2
    D2 -- "No" --> END_NODE
    R2 --> END_NODE
```

The method starts by partitioning the target array range and receiving the final pivot index. It then checks whether the left subrange contains at least two elements; if so, it recursively sorts the left side. After the left recursion completes or is skipped, it checks whether the right subrange contains at least two elements; if so, it recursively sorts the right side. If either subrange is already reduced to zero or one element, the method skips that recursion branch and returns to the caller.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `num` | `int[]` | The numeric working set to be sorted. The method mutates this array in place, so the caller receives the same array reference with values reordered into ascending sequence. |
| 2 | `start` | `int` | The inclusive lower boundary of the subarray currently being sorted. It determines where the algorithm begins partitioning and whether the left recursive branch must continue. |
| 3 | `end` | `int` | The inclusive upper boundary of the subarray currently being sorted. It determines the pivot position used by `partition()` and whether the right recursive branch must continue. |

This method reads no instance fields and no external state. Its behavior is fully determined by the three input parameters and by the array contents in `num`.

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `quiks.partition` | quiks | - | Calls `partition` in `quiks` |
| - | `quiks.quickSort` | quiks | - | Calls `quickSort` in `quiks` |

Analyze all method calls within this method and classify each as a CRUD operation.
Use the pre-computed evidence above. If SC Code or Entity/DB is missing, try to infer from:
- The SC Code (Service Component code, e.g., `EKK0361A010SC`, `EKK1081D010CBS`) — look at the class name of the called method or its containing class.
- The Entity/DB tables — search for table name constants (often `KK_T_*` pattern), SQL references, or entity names in the called method's source code.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `partition` | quiks | - | Delegates to the local partitioning routine to compute the pivot boundary for the current array segment. |
| - | `quickSort` | quiks | - | Recursively invokes the same sorting routine for the left and right subranges of the array. |

## 5. Dependency Trace


Trace who calls this method and what this method ultimately calls.
Use the pre-computed evidence and caller search results from Step 2 above.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch / utility code in `quiks` | `quiks.quickSort` | `partition [R] -` |
| 2 | Batch / utility code in `quiks` | `quiks.quickSort` -> `quickSort` | `quickSort [R] -` |
| 3 | Batch / utility code in `quiks` | `quiks.quickSort` -> caller at line 296 in `Sortingss.java` | `quickSort [R] -` |

## 6. Per-Branch Detail Blocks

**Block 1** — **CALL** `(start of quickSort)` (L19)

> Begins recursive sorting for the current inclusive array range.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `int partition = partition(num, start, end);` |

**Block 2** — **IF** `(partition - 1 > start)` (L21)

> Checks whether the left partition still contains more than one element.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `quickSort(num, start, partition - 1);` |

**Block 3** — **IF** `(partition + 1 < end)` (L25)

> Checks whether the right partition still contains more than one element.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `quickSort(num, partition + 1, end);` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `quickSort` | Method | Recursive in-memory sorting routine that arranges numeric values in ascending order using the Quick Sort algorithm. |
| `partition` | Method | Pivot placement routine that divides the array segment into values lower than the pivot and values higher than the pivot. |
| `num` | Field / Parameter | Integer array being sorted. In business terms, this is the working data set or list of numeric values. |
| `start` | Parameter | Inclusive beginning index of the current subrange under sort processing. |
| `end` | Parameter | Inclusive ending index of the current subrange under sort processing. |
| pivot | Algorithm term | Reference value used to separate smaller and larger elements during partitioning. |
| recursive sort | Algorithm term | Self-invoking processing pattern where the same routine is called on smaller subranges until each segment is fully ordered. |
| divide-and-conquer | Algorithm term | Design approach that splits the problem into smaller independent parts, solves them recursively, and combines the result by position. |
| ascending order | Business term | Sequence arrangement from smaller numeric value to larger numeric value. |
| Utility | Layer | Shared helper logic that performs local computation without owning a business transaction or persistence responsibility. |