Narrative Report COMP 212 4
Narrative Report COMP 212 4
Submitted By :
Submitted to:
AUGUST 2024
1
LEARNING OBJECTIVES :
By the end of this lesson, students should be able to :
A. Define and understand how Algorithm works;
B. Understand what is Flowchart;
C. Differentiate Algorithm and Flowchat;
D. Use Flowchart to represent Algorithm.
I. Algorithm
An algorithm is a set of commands that must be followed for a computer to perform
calculations or other problem-solving operations.According to its formal definition,
an algorithm is a finite set of instructions carried out in a specific order to perform a
particular task. It is not the entire program or code; it is simple logic to a problem
represented as an informal description in the form of a flowchart or pseudocode.
● Input: After designing an algorithm, the algorithm is given the necessary and desired
inputs.
2
● Processing unit: The input will be passed to the processing unit, producing the desired
output.
Algorithms are step-by-step procedures designed to solve specific problems and perform
tasks efficiently in the realm of computer science and mathematics. These powerful sets of
instructions form the backbone of modern technology and govern everything from web
searches to artificial intelligence. Here's how algorithms work:
● Input: Algorithms take input data, which can be in various formats, such as numbers,
text, or images.
● Processing: The algorithm processes the input data through a series of logical and
mathematical operations, manipulating and transforming it as needed.
● Output: After the processing is complete, the algorithm produces an output, which
could be a result, a decision, or some other meaningful information.
3
What is the Need for Algorithms?
Scalability - It aids in your understanding of scalability. When you have a sizable real-world
problem, you must break it down into small steps to analyze it quickly.
Performance - The real world is challenging to break down into smaller steps. If a problem
can be easily divided into smaller steps, it indicates that the problem is feasible.
Algorithms are essential to many disciplines because they offer organized, practical
answers to challenging issues. Here are a few significant applications of algorithms in
various fields:
Algorithms are used in data analysis and machine learning to find patterns in big datasets and
forecast outcomes. Thanks to machine learning methods like support vector machines,
decision trees, and neural networks, computers can learn from data and improve over time.
These techniques are essential for applications such as recommendation systems, natural
language processing, and picture recognition.
4
3. Information Retrieval and Search Engines
Search engines can efficiently index and retrieve pertinent information thanks to search
algorithms such as PageRank and Hummingbird. By prioritizing web pages according to their
significance and relevancy, these algorithms assist users in locating the most relevant
information available online. Effective search algorithms are necessary to manage the
enormous volume of online information.
4. Optimization problems
Optimization methods are utilized to select the optimal answer from various options. In
various industries, including banking, engineering, logistics, and artificial intelligence,
sophisticated issues are resolved using methods like gradient descent, linear programming,
and genetic algorithms. These algorithms increase productivity, reduce expenses, and
optimize resources for operations and decision-making.
Due to their ability to analyze medical images, forecast disease outbreaks, and recognize
genetic changes, algorithms are indispensable in medical diagnostics. Personalized medicine
has been transformed by machine learning algorithms, in particular, which enable the
creation of customized treatment regimens based on each patient's unique genetic profile.
Additionally, algorithms help to speed up the sequencing and interpretation of genomic data,
improving biotechnology and genomics research.
Characteristics of an Algorithm
5
1. Finiteness - An algorithm must always have a finite number of steps before it ends. When
the operation is finished, it must have a defined endpoint or output and not enter an endless
loop.
2. Definiteness - An algorithm needs to have exact definitions for each step. Clear and
straightforward directions ensure that every step is understood and can be taken easily.
3. Input - An algorithm requires one or more inputs. The values that are first supplied to the
algorithm before its processing are known as inputs. These inputs come from a
predetermined range of acceptable values.
4. Output - One or more outputs must be produced by an algorithm. The output is the
outcome of the algorithm after every step has been completed. The relationship between the
input and the result should be clear.
6. Generality - Rather than being limited to a single particular case, an algorithm should be
able to solve a group of issues. It should offer a generic fix that manages a variety of inputs
inside a predetermined range or domain.
6
II. FLOWCHART
Flowcharts to document business processes came into use in the 1920s and ‘30s. In 1921,
industrial engineers Frank and Lillian Gilbreth introduced the “Flow Process Chart” to the
American Society of Mechanical Engineers (ASME).
7
How do flowcharts work?
Flow charts are simple diagrams that map out a process, so that you can easily
communicate it to other people. You can also use them to define and analyze a process, build
a step-by-step picture of it, and then standardize or improve it.
● Define the process to be diagrammed. Write its title at the top of the work surface.
● Discuss and decide on the boundaries of your process: Where or when does the
process start? Where or when does it end? Discuss and decide on the level of detail to
be included in the diagram.
● Brainstorm the activities that take place. Write each on a card or sticky note.
● Arrange the activities in proper sequence.
● When all activities are included and everyone agrees that the sequence is correct,
draw arrows to show the flow of the process.
● Review the flowchart with others involved in the process (workers, supervisors,
suppliers, customers) to see if they agree that the process is drawn accurately
Characteristics of a Flowchart
● Start and end points. One or more start and end points linked to a core idea, system,
or process.
● Substeps and processes. These guide readers through the entire process or flow, from
the beginning to the end.
● Directional arrows. These indicate the sequence of steps, providing a clear, visual
order.
8
● Decision points. Decision points break charts into multiple directions, allowing for
different outcomes.
● Flowchart symbols. Standardized flowchart symbols represent specific actions within
a system or process.
9
Advantage of Algorithm
3. Every step in an algorithm has its own logical sequence so it is easy to debug.
Disadvantage of Algorithm
1. The phases of an algorithm are similar to writing the final code, making it harder to
debug than a flowchart.
Advantage of Flowchart
2. Easy debugging and takes less effort in writing down logic (as it uses symbols).
Disadvantage of Flowchart
1. Time consuming
2. Larger and more complicated problems are difficult to illustrate with flowcharts.
10
Common symbols applied in a Flowchart
1) Classification By Approach
11
Search. These algorithms are efficient because they reduce the problem size at each step,
often resulting in logarithmic or linearithmic time complexity (like O(log n) or O(n log n)).
•Dynamic programming
•Greedy Algorithm
Greedy algorithm decides what to do in each step, only based on the current situation,
without a thought of how the total problem looks like. In other words, a greedy algorithm
makes the locally optimal choice in each step, hoping to find the global optimum solution in
the end. In Dijkstra's algorithm for example, the next vertex to be visited is always the next
unvisited vertex with the currently shortest distance from the source, as seen from the current
group of visited vertices.So Dijkstra's algorithm is greedy because the choice of which vertex
to visit next is only based on the currently available information, without considering the
overall problem or how this choice might affect future decisions or the shortest paths in the
end.
•Backtracking Algorithm
12
search. If a partial solution violates constraints, the algorithm backtracks to explore
alternatives.
•BruteForce Algorithm
Examples:
*String Matching Algorithms are techniques used to find the occurrence of a substring
within a larger text. They are crucial in fields like text processing, search engines, and
bioinformatics.
2) Classification By Purpose
• Searching Algorithms
Searching algorithms are crucial for efficiently finding elements within data structures
like arrays or lists. They are essential in programming, improving both problem-solving and
logical thinking skills. These algorithms are widely used in software development, from
optimizing database queries and search engines to enhancing e-commerce platforms. Mastery
13
of search algorithms is key for optimizing code performance, critical in fields like data
science, AI, and cybersecurity, where they aid in data analysis, pathfinding, and threat
detection. Understanding them also builds a strong foundation for learning advanced
algorithms, technical interviews, and competitive programming, Example of the searching
algorithm are Binary Search, Linear Search
*Linear search is the simplest search algorithm. It works by iterating through each element of
a data structure until it finds the target element or reaches the end of the data structure. It is
straightforward but not the most efficient for large datasets because its time complexity is
O(n), where n is the number of elements in the data structure.
*Binary search is an efficient algorithm for searching sorted data structures. It works by
repeatedly dividing the search range in half using the divide-and-conquer technique. The
search compares the middle element to the target; if they match, the search is successful. If
the target is smaller, the search continues on the left half; otherwise, it moves to the right.
This method drastically reduces comparisons. Note that binary search only works on sorted
data. it is much faster than linear search, making it ideal for large datasets."
• Sort Algorithms
Sorting algorithms are used to arrange data in a particular order, often numerical or
lexicographical. These algorithms can be broadly classified into two categories:
comparison-based and non-comparison-based. Comparison-based sorting algorithms, like
Quick Sort, Merge Sort, and Bubble Sort, compare elements to determine their order.
Non-comparison-based algorithms, such as Counting Sort and Radix Sort, use different
techniques like counting occurrences or exploiting digit properties to sort data. Each sorting
algorithm has unique characteristics and complexities.
14
•Graph algorithm
Examples:
*Depth-First Search (DFS) is an algorithm used for traversing or searching tree or graph data
structures. The algorithm starts at a specified node (often called the root or start node) and
explores as far as possible along each branch before backtracking. DFS uses a stack data
structure, either explicitly or through recursion, to keep track of the nodes to be explored
*Breadth-First Search (BFS) is an algorithm for traversing or searching tree or graph data
structures. It starts at a given node and explores all its neighboring nodes at the present depth
before moving on to nodes at the next depth level. BFS uses a queue data structure to keep
track of the nodes to be explored. Below is the graphical illustration on how Breadth-First
Search done in a Graph.
3) Classification By Application
String matching algorithms are fundamental tools in computer science and are widely
used in various applications such as text processing, data mining, information retrieval, and
pattern recognition. These algorithms aim to locate occurrences of a pattern within a larger
text or string.
15
•Cryptographic Algorithms
are methods used to secure data through encryption and decryption, ensuring
confidentiality, integrity, and authenticity in communication and data storage. These
algorithms fall into three main categories:
1. Symmetric-Key Algorithms -The same key is used for both encryption and decryption.
2. Asymmetric-Key Algorithms- Uses a pair of keys – a public key for encryption and a
private key for decryption.
- Examples: RSA, ECC (Elliptic Curve Cryptography), DSA (Digital Signature Algorithm).
3. Hash Function - Converts data into a fixed-size hash value, primarily for integrity checks.
These algorithms are fundamental to secure communications, digital signatures, and data
protection in various applications like online banking, e-commerce, and secure file sharing.
Machine learning algorithms are categorized mainly into supervised and unsupervised
learning. Supervised learning uses labeled data to train models for tasks like regression and
classification. Examples include linear regression, logistic regression, decision trees, random
16
forests, Support Vector Machines (SVM), K-Nearest Neighbors (KNN), Naive Bayes, and
neural networks. In contrast, unsupervised learning deals with unlabeled data to uncover
hidden patterns or groupings, using techniques like K-means clustering, hierarchical
clustering, and Principal Component Analysis (PCA). Semi-supervised learning combines a
small amount of labeled data with a large amount of unlabeled data, while reinforcement
learning involves agents learning optimal actions through interactions with an environment,
aiming to maximize rewards. These algorithms underpin various applications, from
predictive analytics to autonomous systems.
•Recursive Algorithms
Recursion is a programming technique where a function calls itself within its own
definition. It is usually used to solve problems that can be broken down into smaller instances
of the same problem. For Example: Towers of Hanoi (TOH), Factorial Calculation and
Fibonacci Sequence etc.
The point which makes Recursion one of the most used algorithms is that it forms the
base for many other algorithms such as Tree traversals, Graph traversals, Divide and
Conquers Algorithms and Backtracking algorithms.
•Iterative Algorithm
17
•Parallel algorithms
Parallel Algorithms solve problems by dividing tasks into smaller, concurrent subtasks
that can be executed simultaneously across multiple processors or cores. This approach
enhances efficiency and handles larger datasets effectively. Examples include parallel sorting
algorithms, like Parallel Merge Sort, which speed up the sorting process, and parallel search
algorithms, such as Parallel Binary Search, which improve data retrieval. Parallel matrix
operations handle large matrices efficiently, while parallel graph algorithms speed up tasks
like graph traversal. The MapReduce framework divides data processing into "map" and
"reduce" stages for large-scale tasks. Divide and conquer strategies also use parallel
processing to break down problems into smaller parts, solve them concurrently, and combine
the results. These algorithms are essential for leveraging multi-core and distributed
computing systems.
For visualizing abstract processes, it is necessary to determine the purpose of the flowchart.
This helps in choosing the suitable types of process maps to build.
18
Designers can employ one of the following main flow chart types:
1. Process Flowchart: As the most common type, a process flowchart illustrates the steps of
plans, projects, production processes, etc. It visualizes and explains how something is done
from start to end so that teammates, managers, an external team, and other viewers
understand business processes.
2. Workflow Chart: These organizational charts indicate the flow of materials and data in an
organization. It works wonders in training newbies, identifying problems in the workflow,
planning new procedures, or explaining business operations.
19
3. Swimlane Flowchart: The purpose of this graphical representation is to clarify the
interaction process between different employees, departments, and processes, such as sales
process steps that involve other parts of a business. Each diagram can consist of six or more
swimlanes.
20
Step 2 - Map out major steps using flowchart symbols
This step involves listing out all the phases and assigning the proper shapes to each of them.
Different process maps comprise varied components, depending on their type, purpose, and
content. The following are some of the most popular elements used in basic process mapping:
Flowchart Symbols
1. All flowcharts begin with the START symbol. This shape is called a terminator.
21
4. The DECISION symbol checks a condition before carrying on, eg is the drilling
accurate?
6. All flowcharts end with the END symbol. This shape is called a terminator.
Now that all the components have been visualized, the next step is to place the steps in the
correct order to sketch out the basic process map.
In addition, the diagram maker needs to add lines and arrows to illustrate the direction of
flow and the relations between critical elements.
Although the entire process is close to finishing, there may be changes in this process step,
such as alternating the step order and adding components. Also, remember to use keywords
and phrases only, do not write an entire sentence in each box.
Once all the flow lines and terminal symbols are added, you now have a complete flowchart,
ready for review.
An excellent way to assess the flowchart is to get help from people unfamiliar with the
process. Ask them to view the diagram and determine whether they understand what it is
supposed to convey.
22
VI. Use Flowchart To Represent Algorithm
Understanding Flowcharts
Example:
Write an algorithm and flowchart to find the area of the rectangle.
Algorithm:
Step 1: Start
Step 2: Input l & w
Step 3: Area = l x w
Step 4: Print Area
Step 5: Stop
23
VII. References
Ensmenger, (2016) "The multiple meanings of a flowchart."
utexaspressjournals.org
W3 Schools
https://www.w3schools.com/dsa/dsa_intro.php
24
Difference Between Algorithm and Flowchart
https://www.geeksforgeeks.org/difference-between-algorithm-and-flowchart/
Figma. (n.d.). Types of flow charts. Figma. Retrieved August 20, 2024, from
https://www.figma.com/resource-library/types-of-flow-charts/
American Society for Quality. "Flowchart." ASQ, American Society for Quality, n.d.,
https://asq.org/quality-resources/flowchart#:~:text=A%20flowchart%20is%20a%20pic
ture,process%2C%20or%20a%20project%20plan
25