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

Algorithm Flowchart

The document provides pseudocode and flowcharts for several algorithms: 1) Ninex calculates 9x of a given number. Volleyball Scoring checks if a team wins by at least 2 points when reaching 15. FizzBuzz prints "Fizz" if a number is divisible by 3, "Buzz" if by 5, and "FizzBuzz" if both. 2) Other algorithms include reversing an array, checking if a word is a palindrome, linear search, binary search, and selection sort. Pseudocode and flowcharts are provided for each algorithm. 3) The pseudocode uses common programming constructs like loops, conditional statements, functions and parameters to logically describe the algorithms. The flowcharts

Uploaded by

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

Algorithm Flowchart

The document provides pseudocode and flowcharts for several algorithms: 1) Ninex calculates 9x of a given number. Volleyball Scoring checks if a team wins by at least 2 points when reaching 15. FizzBuzz prints "Fizz" if a number is divisible by 3, "Buzz" if by 5, and "FizzBuzz" if both. 2) Other algorithms include reversing an array, checking if a word is a palindrome, linear search, binary search, and selection sort. Pseudocode and flowcharts are provided for each algorithm. 3) The pseudocode uses common programming constructs like loops, conditional statements, functions and parameters to logically describe the algorithms. The flowcharts

Uploaded by

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

Pseudocode(PC)

Flowchart (FC)

Ninex - PC
Gives the 9x of the input number
PROGRAM Ninex
PROMPT number
SET A = number
SET B = (number - 1)
SET C = 9 - B
SET Total = B*10 + C
PRINT Total
Alternate Psuedocode
Total = ((value - 1) * 10) + (9 - (value - 1))

Ninex
FC

Volleyball Scoring - PC
2 teams, wins at 15 points but must win by at least 2 points.
SET Game_Over = 0
WHILE (Game_over == 0)
IF ((Team1 > 14 OR Team2 > 14) AND (abs(Team1-Team2) >1))
THEN Game_Over = 1
ENDIF
ENDWHILE
*abs = absolute value, turn any negative number positive

Volleyball Scoring - FC

FizzBuzz - PC
If number divisible by 3 its a fizz, if by 5 its a buzz,if both fizzbuzz
PROGRAM FizzBuzz
SET A = 1
WHILE (A <= 100)
PRINT A
IF (A % 3 == 0)
THEN PRINT Fizz
ENDIF
IF (A % 5 == 0)
THEN PRINT Buzz
ENDIF
A = A+1
ENDWHILE

FizzBuzz - FC

Reverse An Array - PC
FUNCTION Reverse INPUT array
DECLARE result[array.length]
SET i = 0
SET x = result.length
WHILE (i < array.length)
result[x] = list[i]
i=i+1
x=x-1
ENDWHILE
RETURN result

Reverse an Array - FC

Palindrome - PC
Check if a word when reversed is still the same, eg.lol, wow
FUNCTION Palindrome INPUT string
SET A = 0
SET B = length(string) 1
WHILE (A < B)
IF (string(A) != string(B))
RETURN False
ENDIF
A=A+ 1
B=B-1
ENDWHILE
RETURN True

Palindrome FC

Linear Search - PC
FUNCTION LinearSearch INPUT array, target
SET found = False
SET index = 0
WHILE ((found == False) AND (index < array.length))
IF array[index] == target
THEN found = true
ELSE
index = index + 1
ENDIF
ENDWHILE
RETURN found

Linear Search - FC

Binary Search - PC
FUNCTION BinarySearch INPUT array, target
SET found = False
SET low = 0
SET high = array.length 1
WHILE ((found == False) AND (low <= high))
SET index = (low + high) / 2
IF target == array[index]
THEN found = True
ELSE
IF target < array[index]
THEN high = index 1
ELSE
low = index + 1
ENDIF
ENDIF
ENDWHILE
RETURN found

Binary Search - FC

FUNCTION Sort INPUT array


SET eIndex = array.length

Selection Sort - PC

SET maxPos = 0
WHILE eIndex > 0
maxPos = CALL FindMax WITH array, eIndex
CALL SwapPos WITH array, maxPos, eIndex
eIndex = eIndex 1
ENDWHILE
FUNCTION FindMax INPUT array, eIndex
SET biggest = 0
SET cIndex= 1
WHILE cIndex < eIndex
IF array[cIndex] > array[biggest]
THEN biggest = cIndex
ENDIF
cIndex = cIndex + 1
ENDWHILE
RETURN biggest

FUNCTION SwapPos INPUT array, eOne, eTwo


temp = array[eOne]
array[eOne] = array[eTwo]
array[eTwo] = temp

Selection Sort - FC

You might also like