---
title: "Bisection method pseudo-code"
subject: "Numerical Method"
chapter: 2
key: "semester_4/numerical_method:bisection-pseudocode"
source: https://www.bctengineer.com/q/semester_4/numerical_method/bisection-pseudocode
site: BCT Engineering
---

# Bisection method pseudo-code

Numerical Method · Chapter 2: Solutions of Nonlinear Equations

- Asked in: 2073 Magh, 6 marks; 2069 Poush, 4 marks; 2068 Bhadra, 4 marks (asked 3 times)
- Video: [Regula Falsi and Bisection Method C Program || Computer Oriented Numerical Analysis | #clanguage](https://www.youtube.com/watch?v=3SoMHPQwEAE) — MS MATHS
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/numerical_method/bisection-pseudocode
- Whole chapter: https://www.bctengineer.com/md/semester_4/numerical_method/chapter-2

## Question

Write a pseudo-code (algorithm) to find a real root of a non-linear equation using the Bisection method.

## Short answer

Bisection repeatedly halves an interval where f(a)f(b) < 0, using midpoint c = (a+b)/2. If f(c)=0 or interval half-width below tolerance, c is the root; otherwise replace a or b with c keeping a sign change, then repeat.

## Answer

Bisection method repeatedly halves an interval [a, b] in which f(a)·f(b) < 0 and keeps the half that still contains the root.

#### Pseudo-code
```text
Algorithm: Bisection method
Input : function f(x), interval ends a and b,
        tolerance e, maximum iterations N
Output: approximate root

1.  Read a, b, e, N
2.  If f(a) * f(b) >= 0 then
        print "Root is not bracketed; choose other a, b"
        stop
3.  Set i = 1
4.  Repeat steps 5 to 9 while i <= N
5.      c = (a + b) / 2
6.      If f(c) = 0 or (b - a)/2 < e then
            print "Root =", c, "after", i, "iterations"
            stop
7.      If f(a) * f(c) < 0 then
            b = c
        else
            a = c
8.      i = i + 1
9.  End repeat
10. Print "Method did not converge in N iterations"
11. Stop
```

#### Notes
- The number of iterations needed for tolerance e is n ≥ log((b − a)/e) / log 2.
- The method always converges, but slowly (error is halved each step).

## Check yourself

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

1. The pseudo-code first checks:
   A. f(a)*f(b) < 0, else stops
   B. f(a) = f(b)
   C. f'(a) > 0
   D. b - a = 1
   Answer: A. A sign change guarantees a root in [a, b]. (Key point: Precondition)

2. Each iteration computes:
   A. c = (a*f(b) - b*f(a))/(f(b)-f(a))
   B. c = (a + b)/2
   C. c = a - f(a)/f'(a)
   D. c = b - a
   Answer: B. Bisection uses the interval midpoint. (Key point: Midpoint)

3. If f(a)*f(c) < 0 the algorithm sets:
   A. a = c
   B. c = 0
   C. b = c
   D. stop
   Answer: C. The sign change is in [a, c], so the upper end moves to c. (Key point: Update)

4. Iterations needed for tolerance e satisfy:
   A. n >= (b-a)*e
   B. n >= log e
   C. n = 2e
   D. n >= log((b-a)/e)/log 2
   Answer: D. Interval length is (b-a)/2^n. (Key point: Iterations)

## Related in Numerical Method

- [False position pseudo-code](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Afalse-position-pseudocode) — Numerical Method, chapter 2, asked 2×
- [Gauss-Jordan pseudo-code](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Agauss-jordan-pseudocode) — Numerical Method, chapter 3, asked 4×
- [Bisection method working principle](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Abisection-working-principle) — Numerical Method, chapter 2
- [Secant method algorithm](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Asecant-method-algorithm) — Numerical Method, chapter 2, asked 2×
- [Power method pseudo-code](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Apower-method-algorithm) — Numerical Method, chapter 3, asked 2×
- [Simpson 3/8 pseudo-code](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Asimpson-38-pseudocode) — Numerical Method, chapter 5

## Related in other subjects

- [Algorithm/pseudo-code for software PID](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Apid-software-algorithm) — Embedded System, chapter 7, asked 3×
- [Algorithm versus pseudo-code](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aalgorithm-vs-pseudocode) — Computer Programming, chapter 2
- [Real and pseudo-parallelism](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Areal-pseudo-parallelism) — Microprocessor, chapter 6
- [Preemptive vs non-preemptive; real-time scheduling](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Apreemptive-nonpreemptive-realtime) — Operating System, chapter 2
