Unit 1 Assignment 1 Frontsheet 1 Huy Bu Cac
Unit 1 Assignment 1 Frontsheet 1 Huy Bu Cac
Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.
Grading grid
P1 M1 D1
❒ Summative Feedback: ❒ Resubmission Feedback:
I. Introduction............................................................................................................................................................2
II. Content:.................................................................................................................................................................4
1. State your simple business problems to be solved...........................................................................................4
2. Analyze the problem and design the solutions by the use of suitable methods..............................................7
3. Demonstrate the compilation and running of a program...............................................................................9
4. Evaluate how the problem is solved from the designed algorithm to the execution program written by a
specific programming language..........................................................................................................................11
III. Conclusion.........................................................................................................................................................12
3
I. Introduction
4
Figure 1: Algorithms
An algorithm is an "algorithm" (method) for solving a problem. To make it easier to understand, each
problem is like a treasure chest (results, answers), and the key to open that box is the "algorithm". If you
use the wrong key, you can still open the box, but it will take a long time, or if you can open the box, the
treasure inside is distorted and incomplete. Using the right key will help you get the treasure easily and
quickly. Of course, each box will always need a different key, just like a problem always has a definite
algorithm. There is no single key that can open all the chests, just as there is no algorithm that can solve
all problems.
Sorting algorithms are crucial in organizing data in software products, particularly in e-commerce
websites. These algorithms help in sorting products based on different criteria such as price, popularity,
or relevance. Sorting algorithms are also useful in other industries, such as finance and healthcare, where
data needs to be sorted and organized efficiently.
In finance, sorting algorithms are used to analyze stock market trends and financial data. This helps in
identifying patterns and making informed decisions about investments. In healthcare, sorting algorithms
are used to organize patient records and medical data, making it easier for healthcare professionals to
access and analyze information.Sorting algorithms are crucial in organizing data in software products,
particularly in e-commerce websites. These algorithms help in sorting products based on different
criteria such as price, popularity, or relevance. Sorting algorithms are also useful in other industries, such
as finance and healthcare, where data needs to be sorted and organized efficiently.
5
In finance, sorting algorithms are used to analyze stock market trends and financial data. This helps in
identifying patterns and making informed decisions about investments. In healthcare, sorting algorithms
are used to organize patient records and medical data, making it easier for healthcare professionals to
access and analyze information.
Another important algorithm is the shortest path algorithm. This algorithm is commonly used in
navigation software and applications related to the transportation industry, such as Google Maps, Grab,
Uber, and fast delivery services. It helps in finding the shortest path between two points, in terms of
distance or minimum cost. The algorithm is also utilized in network systems and telecommunication to
direct signal transmission. For example, phone calls and internet data from a computer to the network
provider's server use this algorithm to achieve maximum speed.
The search algorithm is another famous algorithm that is used in many current software products. An
excellent example of this is Google, which uses a powerful search algorithm that enables users to find
the information they are looking for within seconds. The search algorithm is used to search through vast
amounts of data to find relevant information, and it is still being improved to this day.
Encryption algorithms are also essential in protecting personal and organizational information from
attacks or exploitation. They are used to encrypt information during transmission and storage of data.
This helps in safeguarding sensitive information from unauthorized access.
In software development, you may encounter small problems or issues that require you to choose the
right solution algorithm to solve them. For instance, you may need to find a computer priced from X to Y
that meets the user's maximum criteria in just one click. You may also need to come up with products or
articles that users are interested in based on their browsing history. However, as you progress in
programming, you may encounter more challenging problems that require advanced algorithms to solve.
During product development, teams may have to solve complex problems such as calculating and sorting
user's rank based on study and test history, count the number of user hits in a period to predict the
attack, or provide suggestions for exercises that users should do based on their access and operation
history on the system. These problems may seem daunting, especially when dealing with large amounts
of data and users. However, choosing the right algorithm can significantly improve processing speed and
efficiency, making it easier to solve complex problems.
In summary, algorithms are essential in software development, and they help in solving complex
problems efficiently. Choosing the right algorithm can significantly improve processing speed and
efficiency, making it easier to handle large amounts of data and users.
It is worth noting that the selection of algorithms is not always straightforward. One must consider the
trade-offs between the accuracy of the results, the speed of the algorithm, and the amount of memory
required for implementation. In some cases, the best algorithm for a particular problem may not be
immediately apparent, and developers may need to experiment with different algorithms to find the best
fit.
6
Moreover, algorithms are not static entities. They are subject to change and evolution as new challenges
arise and new technologies become available. Developers must stay up to date with the latest
developments in algorithm design to ensure that their software remains competitive and efficient.
Finally, it is essential to remember that algorithms do not exist in a vacuum. They are part of a broader
software development process that involves everything from requirements gathering to testing and
maintenance. As such, developers must consider how algorithms fit into the overall architecture of their
software and the needs of their users.
II. Content:
1. State your simple business problems to be solved.
- What is An algorithm:
7
Figure 2: What is Algorithm?
Overall, algorithms are a fundamental aspect of computer science and programming. They allow us to
solve problems, accomplish specific objectives, and create innovative new technologies.
An algorithm is a crucial component of computer programming. It is essentially a set of instructions that
a computer program follows to complete a task. Algorithms are used in a wide range of applications,
including computer science, mathematics, and engineering.
The process of creating an algorithm involves breaking down a problem into a series of smaller, more
manageable steps. Each step must be clearly defined and structured in a way that the computer can
understand. Algorithms are designed to be efficient and effective, meaning they are intended to solve
the problem in the most optimal way possible.
In computer science, algorithms are used in everything from data analysis to machine learning. They play
a critical role in enabling computers to perform complex tasks quickly and accurately. Without
algorithms, many of the technological advancements we enjoy today would not be possible.
One of the key advantages of using algorithms is that they can help automate repetitive or tedious tasks,
freeing up valuable time for more important work. For example, many businesses use algorithms to
analyze large amounts of data, allowing them to quickly identify patterns and make informed decisions.
8
Another advantage of algorithms is that they can be used to optimize processes and systems. By
analyzing data and identifying areas for improvement, algorithms can help streamline operations and
reduce costs.
Overall, algorithms are a powerful tool for solving problems and achieving specific goals. Whether you're
a programmer, engineer, mathematician, or business professional, understanding how algorithms work
and how to use them effectively can be in today's fast-paced, data-driven world.
- Sorting Algorithm: Bubble Sort
+ Bubble sort is a basic algorithm for arranging a string of numbers or other elements in the
correct order. The method works by examining each set of adjacent elements in the string, from left to
right, switching their positions if they are out of order. The algorithm then repeats this process until it
can run through the entire string and find no two elements that need to be swapped.
Here's a step-by-step description of how it works:
1. Start by comparing the first two elements of the list. If the first element is greater than the second
element, swap them. If not, leave them as they are.
2. Move on to the next pair of adjacent elements and repeat step 1.
3. Continue this process until you reach the end of the list. At this point, the largest element in the list
will have "bubbled up" to the end of the list.
4. Repeat steps 1-3, but this time only iterate through the unsorted elements. This means that the last
element of the list is now sorted and does not need to be compared again.
Bubble sort is not the most efficient sorting algorithm, as it has a worst-case time complexity of O(n^2).
However, it is easy to understand and implement, and can be useful for small lists or as a stepping stone
to more advanced sorting algorithms.
+ Binary search is an efficient algorithm that searches a sorted list for a desired, or target,
element. For example, given a sorted list of test scores, if a teacher wants to determine if anyone in the
class scored 8080, she could perform a binary search on the list to find an answer quickly. Binary search
works by halving the number of elements to look through and hones in on the desired value. Binary
search can determine if and where an element exists in a list, or determine if it is not in the list at all.
9
1. Start by setting two pointers, one at the beginning and one at the end of the array.
2. Calculate the middle index of the array by taking the average of the two pointers.
3. Check if the target value is equal to the middle element of the array. If it is, return the index of
the middle element.
4. If the target value is less than the middle element, move the end pointer to the middle index - 1.
This narrows the search to the lower half of the array.
5. If the target value is greater than the middle element, move the start pointer to the middle index
+ 1. This narrows the search to the upper half of the array.
6. Repeat steps 2-5 until the target value is found or the pointers cross each other.
The binary search algorithm has a time complexity of O(log n), which makes it a very efficient search
algorithm for large arrays. However, it only works on sorted arrays, which can be a limitation in some
cases.
2. Analyze the problem and design the solutions by the use of suitable methods.
- You need to gather information about the business problem and understand the requirements of the
application to be developed. Then, you can start designing the algorithm using suitable diagrams such as
Flowchart, Activity Diagrams, etc. The algorithm should be designed in such a way that it solves the
business problem effectively and efficiently.
10
Figure 3: Marth Flowchart
3. Read input number: A parallelogram shape represents the input operation, where the
4. Is input number > max-min? :A diamond shape represents a decision point. The
program checks if the input number is greater than the current maximum number
(max-min).
11
5. Yes: If the input number is greater than max-min, the program takes the path labeled
6. No: If the input number is not greater than max-min ,the program takes the path
7. Read next number: A parallelogram shape represents the input operation, where the
9. Yes: If there is another number available, the program takes the path labeled "Yes"
and returns to step 4 to compare the new number with the current max-min.
10.No: If there are no more numbers available, the program takes the path labeled "No"
11.Display max-min as the largest number: A rectangle shape represents the output
operation, where the program displays the value of max-min as the largest number.
1. In Solution Explorer, in the right pane, select Program.cs to display the file in the code editor
12
2. In the code editor, replace the default "Hello World" code that says Console.WriteLine("Hello World!")
Figure 4: Step 1
3. To build and run your app, press F5, or select the green arrow next to the name Calculator in the top
toolbar:
Figure 5: Step 2
A console window opens that shows the sum of 42 + 119, which is 161.
13
Figure 6: Result
5. Optionally, you can change the operator to change the result. For example, you can change the + operator in
the int c = a + b; line of code to - for subtraction, * for multiplication, or / for division. When you run the app, the
result changes accordingly.
4. Evaluate how the problem is solved from the designed algorithm to the execution program written
by a specific programming language
- In this part, you need to demonstrate how the problem is solved by using the application. Test plan
with test cases needs to include to make sure that the algorithm works properly.
1. Algorithm Design:
The algorithm for solving the problem of finding the sum of even numbers in a given list is
as follows:
+ Initialize a variable sum to 0.
+ Iterate through each element in the list.
+ Check if the element is even (i.e., divisible by 2 with no remainder).
+ If the element is even, add it to the sum.
+ Finally, return the sum.
2. Execution Program (C#):
Here's an implementation of the algorithm in C#:
14
Figure 7: implementation of the algorithm in C#
III. Conclusion
In conclusion, algorithms play a crucial role in solving various business problems efficiently and
effectively. Throughout this analysis, we explored the concept of algorithms, their importance, and how
they can be applied to simple problems. We began by providing an overview of algorithms, explaining
that they are step-by-step procedures designed to solve specific problems. Algorithms are crucial in
organizing and optimizing processes, making them an essential component of problem-solving in various
domains. We discussed two common types of algorithms: sorting algorithms and searching algorithms.
Sorting algorithms such as Selection Sort, Bubble Sort, and Insertion Sort help arrange data in a particular
order, while searching algorithms like Linear Search and Binary Search aid in finding specific elements
within a dataset. To further analyze the problem-solving process, we designed algorithms using suitable
diagrams such as flowcharts or activity diagrams. These visual representations provide a clear
understanding of the algorithm's logic and flow, facilitating the implementation phase. Next, we
demonstrated the implementation of the algorithms in specific programming languages like C, C++, and
C#. By providing code examples and explaining the compilation and execution process, we illustrated
15
how algorithms can be translated into executable programs. Furthermore, we emphasized the
importance of testing to ensure the correctness of the implemented algorithms. Test plans with well-
defined test cases are essential to validate the algorithm's behavior under various scenarios, including
normal and boundary cases. Through rigorous testing and evaluation, we can identify and address any
issues or discrepancies, leading to improved algorithmic solutions. Overall, algorithms serve as powerful
tools for solving business problems by providing systematic and efficient solutions. They are the
backbone of computational thinking and enable businesses to streamline processes, improve efficiency,
and achieve desired outcomes. By understanding algorithms, designing effective solutions, implementing
them 19 in programming languages, and conducting thorough testing, businesses can leverage the
power of algorithms to drive innovation and success.
16