---
title: "DDA algorithm with advantages"
subject: "Computer Graphics"
chapter: 2
key: "semester_5/computer_graphics:dda-algorithm-detail"
source: https://www.bctengineer.com/q/semester_5/computer_graphics/dda-algorithm-detail
site: BCT Engineering
---

# DDA algorithm with advantages

Computer Graphics · Chapter 2: Scan-Conversion

- Asked in: 2073 Chaitra, 8+4 marks
- Video: [DDA Line Drawing Algorithm in Computer Graphics | Easiest Explanation with examples ](https://www.youtube.com/watch?v=XjFaV39OzJ4) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/computer_graphics/dda-algorithm-detail
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-2

## Question

Discuss the Digital Differential Analyzer (DDA) line drawing algorithm in detail. Also give its advantages and disadvantages.

## Short answer

DDA computes steps = max(|dx|,|dy|) and increments xinc = dx/steps, yinc = dy/steps. For |m| ≤ 1, x steps by 1 and y by m; otherwise y steps by 1 and x by 1/m. Pixels are plotted by rounding after each addition. It is simple but uses floating-point arithmetic with rounding errors that accumulate.

## Answer

The **Digital Differential Analyzer (DDA)** is a scan-conversion algorithm that draws a line by computing the pixel positions at unit intervals along one axis, using the line's slope. The other coordinate is calculated by adding a constant increment and rounding.

#### Principle
For a line from (x1, y1) to (x2, y2): dx = x2 − x1, dy = y2 − y1, slope m = dy/dx.
Number of steps = max(|dx|, |dy|). The increments are

```text
xinc = dx / steps,   yinc = dy / steps
(one of them is ±1)
```

- If |m| ≤ 1: x changes by 1, y by m: x_k+1 = x_k + 1, y_k+1 = y_k + m.
- If |m| > 1: y changes by 1, x by 1/m: y_k+1 = y_k + 1, x_k+1 = x_k + 1/m.

#### Algorithm
```text
1. Input (x1, y1), (x2, y2).
2. dx = x2 − x1; dy = y2 − y1.
3. steps = max(|dx|, |dy|).
4. xinc = dx / steps; yinc = dy / steps.
5. x = x1; y = y1; plot (round(x), round(y)).
6. Repeat steps times:
      x = x + xinc; y = y + yinc;
      plot (round(x), round(y)).
```

```c
void dda(int x1,int y1,int x2,int y2){
    int dx=x2-x1, dy=y2-y1, steps, k;
    float x=x1, y=y1, xinc, yinc;
    steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);
    xinc = (float)dx/steps;  yinc = (float)dy/steps;
    putpixel(round(x), round(y), WHITE);
    for(k=0;k<steps;k++){
        x += xinc;  y += yinc;
        putpixel(round(x), round(y), WHITE);
    }
}
```

**Example:** (2,3) to (7,6): dx=5, dy=3, steps=5, xinc=1, yinc=0.6. Points: (2,3), (3,3.6→4), (4,4.2→4), (5,4.8→5), (6,5.4→5), (7,6).

#### Advantages
- Simple to understand and implement.
- Faster than the direct equation y = mx + b, because no multiplication is used per step.
- Works for lines of any slope and direction.

#### Disadvantages
- Uses floating-point arithmetic and a rounding operation at every step, which is slow.
- Round-off error accumulates for long lines, so pixels may drift from the true line.
- Not suitable for direct hardware implementation.
- Division is needed to find the increments.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. steps =
   A. |dx| + |dy|
   B. min
   C. max(|dx|, |dy|)
   D. dx*dy
   Answer: C. Larger axis. (Key point: Steps)

2. xinc =
   A. dx*steps
   B. steps/dx
   C. dy/dx
   D. dx / steps
   Answer: D. Normalised increments. (Key point: Increments)

3. For (2,3)-(7,6) yinc =
   A. 0.6
   B. 0.5
   C. 1
   D. 1.67
   Answer: A. 3/5. (Key point: Example)

4. A DDA disadvantage is
   A. integer only
   B. floating point, rounding, accumulated error
   C. exact
   D. hardware friendly
   Answer: B. Slow and drifts. (Key point: Disadvantage)

## Related in Computer Graphics

- [DDA versus Bresenham line algorithm](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Adda-vs-bresenham-line) — Computer Graphics, chapter 2, asked 6×
- [Compare DDA/Bresenham; midpoint ellipse](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Acompare-dda-bresenham-midpoint-ellipse) — Computer Graphics, chapter 2
- [Ellipse symmetry and drawing algorithm](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aellipse-symmetry-algorithm) — Computer Graphics, chapter 2
- [Write Bresenham's line algorithm](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Abresenham-line-algorithm) — Computer Graphics, chapter 2, asked 3×

## Related in other subjects

- [Short note: Digital Subscriber Line](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Ashort-note-dsl) — Telecommunications, chapter 8, asked 2×
- [List digital-to-digital line coding techniques](https://www.bctengineer.com/question.md?key=semester_5%2Fdata_communication%3Aline-coding-techniques-list) — Data Communication, chapter 5
