0% found this document useful (0 votes)
6 views

Pseudocode For The Algorithms

The document contains pseudocode for several algorithms including finding the maximum element in an array, checking for unique elements in an array, matrix multiplication, Gaussian elimination, counting binary digits, factorial calculation recursively, Tower of Hanoi recursively, and calculating Fibonacci numbers recursively.

Uploaded by

Precious
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Pseudocode For The Algorithms

The document contains pseudocode for several algorithms including finding the maximum element in an array, checking for unique elements in an array, matrix multiplication, Gaussian elimination, counting binary digits, factorial calculation recursively, Tower of Hanoi recursively, and calculating Fibonacci numbers recursively.

Uploaded by

Precious
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Pseudocode for the Algorithms

Find Maximum Element

Pseudocode:

“ function findMaximum(arr):
max_element = arr[0]
for elem in arr[1:]:
if elem > max_element:
max_element = elem
return max_element

Element Uniqueness

Pseudocode:

“function isUnique(arr):
n = length(arr)
for i from 0 to n-1:
for j from i+1 to n-1:
if arr[i] == arr[j]:
return False
return True

Matrix Multiplication

Pseudocode:

“function matrixMultiplication(A, B):


n = rows(A)
p = columns(A)
m = columns(B)
C = new matrix of size n x m with all elements 0
for i from 0 to n-1:
for j from 0 to m-1:
for k from 0 to p-1:
C[i][j] += A[i][k] * B[k][j]
return C

Gaussian Elimination

Pseudocode:

“function gaussianElimination(A):
n = rows(A)
for i from 0 to n-1:
for j from i+1 to n-1:
factor = A[j][i] / A[i][i]
for k from i to n:
A[j][k] -= factor * A[i][k]
return A

Counting Binary Digits

Pseudocode:

“function countBinaryDigits(n):
count = 0
while n > 0:
n = n // 2
count += 1
return count

Factorial (Recursive)

Pseudocode:

“function factorial(n):
if n <= 1:
return 1
else:
return n * factorial(n - 1)

Tower of Hanoi

Pseudocode:

“function towerOfHanoi(n, source, auxiliary, target):


if n == 1:
print "Move disk from source to target"
else:
towerOfHanoi(n-1, source, target, auxiliary)
print "Move disk from source to target"
towerOfHanoi(n-1, auxiliary, source, target)

Fibonacci Numbers (Recursive)

Pseudocode:

“function fibonacci(n):
if n <= 1:
return n
else:
return fibonacci(n-1) + fibonacci(n-2)

You might also like