Assignment 1 Unit1 Programming
Assignment 1 Unit1 Programming
Programming
Sedra Kaied Oweis
Table of Contents
What is Algorithm?...................................................................................................................3
How do algorithms work?.....................................................................................................3
Algorithms in programming:.....................................................................................................5
Relationship between the written algorithm and code:.......................................................5
Bubble sort algorithms:........................................................................................................ 6
Programming language processors.......................................................................................... 8
Difference between the compiler, interpreter, and assembler...........................................10
Integrated Development Environments (IDE).........................................................................12
Programming paradigms........................................................................................................ 13
Procedural programming paradigm....................................................................................13
Object oriented programming............................................................................................13
Event-driven programming.................................................................................................14
Advantages of OOP and EDP over PP..................................................................................18
References.............................................................................................................................. 20
What is Algorithm?
An algorithm is a process or technique in programming that is used to solve an issue. It is
based on carrying out a series of predetermined steps that explain how to accomplish a task;
your computer will always carry out these activities precisely. An algorithm operates by
following a set of input-based steps. It will see an output, or result, when it has processed
every input. (Indicative, n.d.)
Fig.1
Google.com. (2023).
Characteristics of an algorithm
One would not follow the written instructions that come with the typical recipe. Algorithms
are not the same as written computer instructions. A few commands can be considered
algorithms only if they satisfy the following criteria:
Fig.2
Google.com. (2023).
2. Wash the rice: Put the measured rice in a strainer with a fine mesh and run cold
water over it until the water runs clear. By doing this, you may assist the rice stay less
sticky and remove extra starch.
3. The washed rice should be combined with the required amount of water in a
saucepan or rice cooker. To enhance flavour, feel free to add a tiny bit of oil or a
sprinkle of salt. In order to guarantee uniform dispersion, carefully mix.
4. Heat the saucepan on medium-high heat on the stovetop or preheat your rice cooker
to the proper setting in order to bring it to a boil. Boil the combination of rice and
water.
5. Reduce heat: Turn down the heat to low as soon as the water is rolling at a rolling
boil. Put a lid on the pot if you're using a hob. Observe the directions provided by the
rice cooker.
6. Simmer: Simmer the rice for around 18 to 20 minutes while covered. The precise
timing may change according on the kind of rice utilised. For advice, see the
directions provided with the rice packet or cooker.
7. Verify the rice's doneness by checking it after the suggested cooking time. It should
be largely absorbed in water and delicate. Simmer the rice for a few more minutes if
it's still too firm or if there's too much water.
8. Once cooked to your desired consistency, fluff the rice with a fork. Grain separation
and uniform texture are guaranteed by doing this.
9. Now that the rice is cooked, it may be served in any way you choose, whether as a
side dish or the foundation of a meal.
10. Savour: Savour your rice with your preferred sides or meals once it has been cooked
to perfection.
Algorithms in programming:
In programming, algorithms are essential. In a computer programme, they are collections of
precise instructions for doing tasks or resolving certain issues. Data processing, decision-
making, and programme flow control are all accomplished through the usage of
programming algorithms.
Algorithms are a collection of steps that, when completed in the correct order, solve
problems. Consequently, an algorithm for programming is a collection of instructions that
your software will follow exactly each time. The steps involved in such commands/tasks
must be followed exactly each time.
The outcome of the algorithm is referred to as an output, and those stages are known as
inputs.
Fig.3
Google.com. (2023).
n = len(arr)
for i in range(n):
# Flag to optimize the algorithm by checking if any swaps are made in the inner loop
swapped = False
swapped = True
# If no two elements were swapped in the inner loop, the array is already sorted
if not swapped:
break
# Example usage:
bubble_sort(my_list)
To gain a deeper understanding of bubble sort algorithms, one can create a flowchart that
details every loop iteration and the decisions taken. This flowchart illustrates the bubble sort
algorithm:
Fig.4
Google.com. (2023).
Programming language processors
High-level programming languages (such as C++, Python, and Java) are typically used to write
computer programmes. Moreover, a language processor must convert the source code into
machine code, also referred to as object code and composed of ones and zeroes, in order for
the computer to comprehend them.
Language processors come in three different flavours: interpreter, compiler, and assembler.
GeeksforGeeks. (2018).
1. Interpreter
The term "interpreter" refers to the device that converts a single statement from the source
programme into machine code and runs it instantly before going on to the next line. The interpreter
stops translating at that line and shows an error notice if the statement contains a mistake. When the
error has been fixed, the interpreter advances to the following line for execution. Programming or
scripting language instructions are immediately executed by an interpreter, without first being
translated into object or machine code. One line at a time, an interpreter performs what they have
translated.
Fig.5
Google.com. (2023).
2. Assembler
To convert an Assembly language programme into machine code, utilise the Assembler.
Instructions in assembly language are contained in the source programme, which is fed into
an assembler. Comprehending object code or machine code is what the assembler produces
as output for the computer. Simplified, the assembler is essentially the first human-machine
interface. For human-machine communication to occur, an assembler is required to bridge
the gap. Certain mnemonics, or instructions, such ADD, MUL, MUX, SUB, DIV, MOV, and so
on, are written in assembly language code. essentially converting these mnemonics into
binary code via the assembler. The machine's architecture also plays a role in these
mnemonics.
Consider the differences between the architectures of the Intel 8085 and 8086.
Fig.6
Google.com. (2023).
3. Compiler
A compiler is a language processor that reads a high-level program's whole source
code in one sitting and converts it into a machine-language counterpart. C, C++, and
C# are some examples.
Fig.7
Google.com. (2023).
Difference between the compiler, interpreter, and assembler
Compilers and interpreters convert High-Level languages whereas an Assembler is used to
convert Low-Level language. Nowadays, most of the languages like Java, C++ are converted
using a compiler whereas Python uses an interpreter.
Thakur, S. (n.d.).
Fig.8
Output:
The sum of the three numbers (result)
Steps:
1. Start
2. Read the first number (num1)
3. Read the second number (num2)
4. Read the third number (num3)
5. Add num1, num2, and num3 to calculate the sum:
o result = num1 + num2 + num3
6. Display the result, which is the sum of the three numbers.
7. End
Fig.9
Google.com. (2023).
# Output
This code reads the three digits from the user using the input function, then adds them
together using the + operator. In the end, the print function is used to display the result.
Certain paradigms primarily address consequences for the language's execution model, including
permitting side effects or determining whether the execution model determines the order of
operations. Other paradigms focus primarily on the structure of the code, for example, classifying a
code into units and the state this code modifies. The syntax and grammatical style, however, is the
primary focus of others.
Fig.10
Google.com. (2023).
Procedural Paradigm:
Software is organised around functions or procedures that work with data under the
procedural paradigm. The code is structured as a series of stages in this linear style to
programming.
It is possible to access and modify data by executing functions; data and functions
are two different things.
Tasks like data processing and mathematical calculations that may be divided into a
number of distinct parts benefit greatly from its use.
Pascal, Fortran, and C are examples of popular programming languages that adhere
to this method.
Fig.11
Google.com. (2023).
Advantages Disadvantages
Simplicity: Reasonably simple and easy to Limited Abstraction: Certain higher-level
comprehend, procedural programming is a great abstractions and features present in other
option for small-scale and basic applications. For paradigms, such as object-oriented programming
novices, it may be simpler to understand the (OOP), are absent from procedural programming.
code's linear movement from one function to It could thus be less appropriate for intricate,
another. large-scale applications.
Efficient programmes often have less memory Global Variables: Because they can pose
and processing overhead than other paradigms problems with data integrity and maintainability,
since they don't need to create and maintain global variables can be troublesome in procedural
objects or classes. programming.
Speed: Speed and efficiency are two Difficulty with Big Codebases: Procedural code
characteristics of procedural languages, such as C can get more difficult to maintain and
and Fortran, which make them appropriate for comprehend as a programme gets bigger and
high-performance applications like scientific more sophisticated. Complex function
computing and system-level programming. interconnections may result in spaghetti code.
Object-Oriented Paradigm:
The idea of objects—which are essentially instances of classes—is central to the
object-oriented paradigm. Both data (attributes or properties) and the functions
(methods) that manipulate the data are encapsulated in objects.
Advantages Disadvantages:
Modularity: Organisation of code and modularity Complexity: When working on extensive projects,
are encouraged by OOP. Classes and objects make OOP can result in intricate class structures and
up code; each is in charge of a certain functional interactions. It might be more difficult to read and
component. This facilitates code understanding, maintain the code as a result of its complexity.
maintenance, and extension.
Reusability: Classes and objects can be used again Performance Overhead: Because of the dynamic
in several projects or sections of an application. method dispatch, memory management, and
Time and effort are saved as a result of encouraging object construction involved with OOP, there may
code reuse. be performance overhead. Applications may run
slower as a result of this burden.
Encapsulation: OOP allows for the containment of Learning Curve: When it comes to grasping
data (attributes) and the methods that manipulate concepts like inheritance, polymorphism, and
them within the same class. This aids in preventing abstraction, OOP might be more difficult for
unwanted access to and alteration of the data. novices to pick up. When contrasted to procedural
programming, it could need a mental adjustment.
This paradigm's guiding concepts are polymorphism, inheritance, and encapsulation.
Encapsulation makes ensuring that data is protected from outside access and that
only authorised techniques may be used to alter it. New classes can be created based
on preexisting ones thanks to inheritance. Different objects can react appropriately
for their respective classes to the same method call thanks to polymorphism.
A popular option for software development, object-oriented programming (OOP) is
ideal for simulating real-world things and interactions. Python, C++, and Java are
examples of popular OOP languages.
Fig.12
Google.com. (2023).
Event-Driven Paradigm:
The goal of the event-driven paradigm is to react to user interactions or events.
Interactive apps and graphical user interfaces (GUIs) frequently employ it.
The programme normally begins under this paradigm by waiting for an event to
happen (such as a user clicking a button or pushing a key), and it then initiates a
reaction to that event using event handlers or callbacks.
The sequence of events determines the program's flow in event-driven
programming, which is non-linear.
Event-driven paradigms are highly relied upon by programming languages such as
JavaScript, which is widely used in web development.
Google.com. (2023).
Advantages Disadvantages
Event-driven programmes are very sensitive to Complexity: When thousands of events and
events that occur outside of their control and to interactions are handled, event-driven coding can
user inputs. Without the need for constant polling, get complicated. With an increasing number of
they may react instantly to user input like as event handlers, it might become more difficult to
keystrokes, mouse clicks, and sensor data. keep track of the program's flow.
Event-driven programming encourages the division Managing asynchronous behaviour might provide
of responsibilities and modularity. The code is some challenges. The possible race circumstances,
structured into manageable, self-contained callbacks synchronisation problems, and event handling order
or event handlers, which facilitates testing, that might result in difficult-to-debug defects should
understanding, and maintenance. be considered by developers.
Event-driven programmes may effectively manage Fig.13 Overhead: Systems with event-driven
Resource
several activities at once thanks to asynchronous architectures may incur resource overhead,
processing. They are capable of handling different particularly when many events are produced
events and the related actions on their own, which regularly. Performance and resource use of the
is essential for parallel processing and multitasking. programme may be impacted by this.
Fig.14
Google.com. (2023).
Fig.15
Google.com. (2023).
Fig.16
Google.com. (2023).
References
What Is A Programming Algorithm? Data Defined n.d., Indicative, viewed 31 October 2023,
<http://www.indicative.com/resource/programming-algorithm/#:~:text=A%20programming
%20algorithm%20is%20a>.
Simplilearn.com. (n.d.). What is Bubble Sort Algorithm? Time Complexity & Pseudocode |
Simplilearn. [online] Available at: https://www.simplilearn.com/tutorials/data-structure-
tutorial/bubble-sort-algorithm#:~:text=Bubble%20sort%20algorithm%2C%20also
%20known.
Vilmate LLC (2019). Advantages of Python over Other Programming Languages | Vilmate.
[online] Nearshore Software Development Company in Ukraine - VILMATE. Available at:
https://vilmate.com/blog/python-vs-other-programming-languages/.
Amazon Web Services, Inc. (n.d.). What is an IDE? IDE Explained - AWS. [online] Available
at: https://aws.amazon.com/what-is/ide/#:~:text=An%20integrated%20development
%20environment%20(IDE.