0% found this document useful (0 votes)
73 views5 pages

Gaussian Elimination

problem set for Algorithms course

Uploaded by

Usman Alam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views5 pages

Gaussian Elimination

problem set for Algorithms course

Uploaded by

Usman Alam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1 Introduction

In this homework, we will formalize the famous algorithm called Gaussian elimination.
The method we use is attributed to Gauss, and some books classify the method
as the Transform and Conquer method. In this paradigm, one either simplifies the
instance to a more amenable one or represents the instance differently, which enables
employing efficient algorithms for it. The latter is an example application of reduction,
an algorithm design paradigm, that we will discuss in great detail when we study
complexity theory.

Transform and Conquer: That’s the secret to life... replace one worry with
another.

Charles M. Schulz

2 Gaussian Elimination for Larger Systems


Gaussian elimination is an elegant method for solving such large systems, that trans-
form the system into an equivalent form which is far easier.

2.1 Upper Triangular Matrix


    
a11 a12 . . . a1n x1 b1
 a21 a22 . . . a2n   x2   b2 
Given a system Ax = b :=   ..  =  .. .
    
.. .. ..
 . . ... .  .   . 
an1 an2 . . . ann xn bn
Suppose we know that the matrix A is upper triangular (all the numbers below the
main diagonal are 0), i.e.
 
a11 a12 a13 ... a1n
 0 a22 a23 ... a2n 
 
A= 0 0 a33 ... a3n
 

 .. .. .. 
 . . . 
0 0 0 ... ann

Problem 1. Given the above system of equation in upper triangular form, use the
substitution method to solve the system. [3 marks]

Solution.

1
3 Transforming System of Equation into an upper
triangular matrix
Transform a system of linear equations into an upper triangular matrix using Gaussian
elimination.

Problem 2. Solve the system using Gaussian elimination:

x1 + 2x2 + 3x3 = 9 (1)


2x1 + 3x2 + x3 = 8 (2)
3x1 + x2 + 2x3 = 7 (3)

[5 marks]

Solution.

Problem 3. Transform the following system into upper triangular form using Gaus-
sian elimination:

2x1 + 3x2 + x3 = 1 (4)


4x1 + x2 − 2x3 = 2 (5)
−2x1 + 5x2 + 3x3 = 3 (6)

[5 marks]

Solution.

4 Back Substitution
Back substitution is used to solve an upper triangular system.

Problem 4. Solve the system using back substitution:

2x1 − 4x2 + x3 = 6 (7)


1
0 + 5x2 − x3 = 2 (8)
2
6 36
0 + 0 − x3 = − (9)
5 5
[5 marks]

Solution.

2
Problem 5. Transform
 the
 following matrix into upper triangular form using Gaus-
1 2 3
sian elimination: 4 5
 6 [5 marks]
7 8 9
Solution.

Problem 6. Given the upper triangular matrix from the previous problem, perform
back substitution to find the solution vector. [5 marks]

Solution.

5 Pseudocode for Gaussian Elimination


Now we are ready to provide a step-by-step algorithm for Gaussian elimination.

5.1 Pseudocode for Converting Matrix to Upper Triangular


Form

Algorithm 1 Convert to Upper Triangular Form


1: procedure ConvertToUpperTriangular(A, b)
2: n ← number of rows in A
3: for k = 1 to n do
4: for i = k + 1 to n do
5: f actor ← A[i][k]/A[k][k]
6: for j = k to n do
7: A[i][j] ← A[i][j] − f actor × A[k][j]
8: b[i] ← b[i] − f actor × b[k]
9: return (A, b)

3
5.2 Pseudocode for Backward Substitution

Algorithm 2 Backward Substitution


1: procedure BackwardSubstitution(A, b)
2: n ← number of rows in A
3: x ← zero vector of length n
4: for i = n downto 1 do
5: sum ← b[i]
6: for j = i + 1 to n do
7: sum ← sum − A[i][j] × x[j]
8: x[i] ← sum/A[i][i]
9: return x

6 Pseudocode for the Complete Gaussian Elimi-


nation Algorithm

Algorithm 3 Gaussian Elimination


1: procedure GaussianElimination(A, b)
2: n ← number of rows in A
3: for k = 1 to n do
4: for i = k + 1 to n do
5: f actor ← A[i][k]/A[k][k]
6: for j = k to n do
7: A[i][j] ← A[i][j] − f actor × A[k][j]
8: b[i] ← b[i] − f actor × b[k]
9: // Perform Backward Substitution
10: x ← zero vector of length n
11: for i = n downto 1 do
12: sum ← b[i]
13: for j = i + 1 to n do
14: sum ← sum − A[i][j] × x[j]
15: x[i] ← sum/A[i][i]
16: return x

7 Runtime of Gaussian Elimination


The runtime of Gaussian elimination can be analyzed by considering the number of
operations required to transform the matrix into an upper triangular form and then
perform back substitution. Let’s break it down step by step.

4
7.1 Total Runtime

Problem 7. Prove that the time complexity of Gaussian elimination is O(n3 ). [5


marks]

Solution.

7.2 Space Complexity

Problem 8. Explain why Gaussian elimination is not suitable for solving very large
systems of equations in practice. [5 marks]

Solution.

You might also like