Algorithm Design
Algorithm Design
able to do
1) Analyse algorithms for a given situation
You should be able to recognize/use and explain common algorithms such as:
(Your teacher/exam may specify which ones are required—tell me and I’ll tailor a study list.)
4) Distinguish between dynamic and static data structures
Characteristics:
Characteristics:
More flexible
Usually more overhead than arrays (extra pointers / memory management)
(a) Describe an algorithm for using the tree to read the names in alphabetic order
To read the names stored in a tree in alphabetical order, we use an in-order traversal of the tree.
First, we start from the root node and recursively visit the left subtree, because in a binary
search tree all names in the left subtree are alphabetically smaller than the current node’s name.
After finishing the left subtree, we output (print) the name stored in the current node. Then we
recursively visit the right subtree, where all names are alphabetically greater than the current
node. By repeating this process for every node, the names are visited and printed from smallest
to largest, which means they appear in alphabetical order.
(b) write an algorithm, in pseudocode, of a program that accepts any 200 positive numbers
and displays their sum.
SUM-200-POSITIVE()
sum ← 0
FOR i ← 1 TO 200 DO
REPEAT
READ x
UNTIL x > 0
sum ← sum + x
END FOR
PRINT sum
END
sum ← 0
This sets up a variable sum to store the running total. It starts at 0.
FOR i ← 1 TO 200 DO
This loop runs exactly 200 times. Each time through the loop, we will read one positive number.
sum ← sum + x
Once a valid positive number x is entered, it adds x to the running total sum.
END FOR
The loop finishes after 200 valid positive numbers have been added.
PRINT sum
Finally, the program outputs the total sum of those 200 positive numbers.
END
Marks the end of the algorithm.
Database design is important because it determines how efficiently and correctly data is
stored, organized, and accessed.
Accuracy & fewer errors: A good design reduces duplication and prevents inconsistent
data (for example, the same person’s details being entered differently in different places).
Efficient storage: It uses space better by structuring tables and relationships properly, so
the database doesn’t waste memory.
Fast queries and retrieval: Well-designed data makes it quicker to search, sort, and
generate reports—because data is stored in a logical way.
Data security and control: Good design supports proper user access (e.g., which
tables/records users can view or change) and helps protect sensitive information.
Consistency and reliability: Clear relationships (like primary keys and foreign keys)
ensure data stays linked correctly, even as the database grows.
Scalability and maintainability: With a strong design, it’s easier to update the system,
add new features, and handle more data without major rewriting.
✅ Final Answer: When N=5, the algorithm outputs 120, which is 5!.
Sub Main()
Dim rand As New Random
Dim face As Integer
Dim count As Integer
For i = 1 To 20
face = [Link](1, 7)
If face = 4 Then
count += 1
End If
Next