0% found this document useful (0 votes)
16 views22 pages

Assignment 1 Unit1 Programming

Uploaded by

sedraowies
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views22 pages

Assignment 1 Unit1 Programming

Uploaded by

sedraowies
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Assignment 1 Unit1

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).

How do algorithms work?


By using input and output, computer algorithms function. After information is input, the
system evaluates it and determines which instructions to run in order to get the intended
outcome. To answer our search question, for instance, a search algorithm tries to locate the
pertinent data that is kept in the data structure's storage.
University of York. (2022).

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).

Creating an algorithm to perform a task: Cooking rice.


1. With a dry measuring cup, measure out the desired amount of rice. Two cups of
water to one cup of rice is the typical ratio for rice to water. According on your taste
or the kind of rice you're using, adjust the ratio as necessary.

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.

The following are some benefits of using algorithms in programming:


 a simple, step-by-step explanation of a problem's solution.
 employs a certain process.
 Not reliant on any one programming language.
 An algorithm is simple to debug since each step follows a logical order.

Relationship between the written algorithm and code:


Though they are distinct concepts, algorithms and code are connected. Algorithms are
expressed through code, and that's the relationship. More than one language—natural
language, machine language, computer languages, and pseudocode—could be used to
represent the same algorithm. (Software Engineering Stack Exchange, n.d.)
Bubble sort algorithms:
Known by another name, sinking sort or bubble sort, this is the most basic sorting algorithm
that iteratively traverses the list, compares neighbouring members, and swaps elements that
are out of order.
If a programmer tried to put a collection of integers in ascending order using bubble sort, it
may look like this:
‌Simplilearn.com. (n.d.).

Fig.3

‌Google.com. (2023).

Making a bubble sort algorithm:


here's a simple implementation of the Bubble Sort algorithm in Python:
def bubble_sort(arr):

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

for j in range(0, n-i-1):

if arr[j] > arr[j+1]:

# Swap the elements if they are in the wrong order

arr[j], arr[j+1] = arr[j+1], arr[j]

swapped = True

# If no two elements were swapped in the inner loop, the array is already sorted
if not swapped:

break

# Example usage:

my_list = [64, 34, 25, 12, 22, 11, 90]

bubble_sort(my_list)

print("Sorted array is:", 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.

Matlab, Python, and Perl are a few examples.

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.

When a source code is error-free, a compiler successfully converts it to object code. If


the source code has any errors, the compiler lists them at the conclusion of the
compilation along with the line numbers. A number of executions of the object
programme without requiring translation are possible if the defects are eliminated
prior to the compiler effectively recompiling the source code.

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

Algorithm to add 3 numbers:


Input:
Three numbers (num1, num2, num3)

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).

Here's a simple Python code snippet that implements this algorithm:


# Input

num1 = float(input("Enter the first number: "))

num2 = float(input("Enter the second number: "))

num3 = float(input("Enter the third number: "))


# Calculation

result = num1 + num2 + num3

# Output

print("The sum of the three numbers is:", result)

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.

Why I used python?


1. ease of use. Beginning programmers are drawn to study Python because of its clear-
cut and uncomplicated syntax.
2. A strong toolkit.
3. velocity of development.
4. Flexibility.
5. The ability to move.
6. A robust community.
Vilmate LLC (2019).

Integrated Development Environments (IDE)


A software tool that aids programmers in writing code more effectively is called an
integrated development environment, or IDE. It boosts developer productivity by integrating
software editing, building, testing, and packaging functions into a user-friendly programme.
Software developers use IDEs to simplify their work, much as writers use text editors and
accountants use spreadsheets.
Writing code is possible with any text editor. Beyond text editing, the majority of integrated
development environments (IDEs) include additional features. The process of developing
software is considerably more efficient since they offer a centralised interface for widely
used developer tools. Instead of manually integrating and configuring disparate tools,
developers may get started immediately on new application development. In addition, they
may concentrate on a single application and do not need to learn about every tool.
Amazon Web Services, Inc. (n.d.).
Programming paradigms
function to categorise programming languages according on their characteristics. Multiple paradigms
can be used to categorise different languages.

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.

Wikipedia Contributors (2019).

Fig.10

Google.com. (2023).

Procedural programming paradigm


Programmes are thought of as collections of instructions that must be carried out, according
to the procedural programming paradigm. Partially because they are similar to functions,
they place a lot of emphasis on dividing programmes into named groups of instructions
called procedures.
deepsource.com. (n.d.).

Object oriented programming


Rather than structuring software architecture around functions and logic, object-oriented
programming (OOP) organises data or objects. A data field with distinctive characteristics
and behaviour might be referred to as object.
‌SearchAppArchitecture. (n.d.).
Event-driven programming
When it comes to computer programming, event-driven programming refers to a paradigm
where user inputs via devices like keyboards, touchpads, and touchscreens control the
program's flow. Programmatic events, such as message transmission from other threads or
programmes, or sensor inputs can also be the source of non-user initiated events. Graphical
user interfaces and other programmes (such JavaScript web apps) that are focused on
executing specific tasks in response to user input are mostly written using the event-driven
programming paradigm. P in USB device driver stacks is an example of how programming for
device drivers likewise follows this rule.
Wikipedia Contributors (2019).

What are procedural, object-oriented, and Event-oriented paradigms.


The three ways of arranging and structuring code in computer programming are procedural,
object-oriented, and event-driven paradigms. Every paradigm has its own qualities and
benefits, and they each provide a distinctive approach to problem-solving and thinking. A
quick synopsis of each is given below:

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.

Advantages of OOP and EDP over PP


Compared to procedural programming, object-oriented programming (OOP) and event-
driven programming (EDP) have some advantages. With the use of classes and objects,
OOP's modular and structured methodology encourages code reuse and maintainability. It
provides abstraction, which frees developers to concentrate on higher-level ideas, and wraps
data, improving security. While OOP facilitates concurrent development and is effective for
large-scale projects, inheritance and polymorphism allow for code reuse and flexibility.
In contrast, EDP is a great choice for real-time applications because of its exceptional
responsiveness to both external events and user inputs. Development of event-based
applications is made easier by asynchronous processing and its user-friendly nature, which
supports interactive interfaces. It is easier to troubleshoot with event-driven systems since
they provide effective event logging and debugging. Extensibility is another feature that EDP
supports, making it simple to integrate additional event collectors. Beyond the restrictions of
traditional procedural programming, these paradigms—OOP and EDP—offer organised,
effective, and user-friendly solutions for contemporary software development.
Example of procedural programming:

Fig.14

Google.com. (2023).

Example event-driven programming:

Fig.15
Google.com. (2023).

Example object oriented programming:

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>.

Google.com. (2023). Redirect Notice. [online] Available at: https://www.google.com/url?


sa=i&url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fwww.simplilearn.com%2Ftutorials%2Fdata-structure-tutorial
%2Fwhat-is-an-
algorithm&psig=AOvVaw1hIwIziOBpJrS254wNywdl&ust=1698865505636000&source=imag
es&cd=vfe&opi=89978449&ved=0CBIQjRxqFwoTCMi7iKr9oIIDFQAAAAAdAAAAABAE.

‌University of York. (2022). How do algorithms work? [online] Available at:


https://online.york.ac.uk/how-do-algorithms-work/#:~:text=An%20algorithm%20is%20a
%20coded.
Google.com. (2023). Redirect Notice. [online] Available at: https://www.google.com/url?
sa=i&url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fwww.codingninjas.com%2Fstudio%2Flibrary%2Fcharacteristics-
of-an-
algorithm&psig=AOvVaw3kT5qIZGtKSkTSd2uYsybJ&ust=1698867337336000&source=image
s&cd=vfe&ved=0CBIQjRxqFwoTCJiYqeCFoYIDFQAAAAAdAAAAABAE [Accessed 31 Oct. 2023].

‌Software Engineering Stack Exchange. (n.d.). terminology - Difference between Algorithm


and Code. [online] Available at:
https://softwareengineering.stackexchange.com/questions/423254/difference-between-
algorithm-and-code#:~:text=Algorithm%20and%20code%20are%20different.

‌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.

‌Google.com. (2023). Redirect Notice. [online] Available at: https://www.google.com/url?


sa=i&url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fwww.productplan.com%2Fglossary%2Fbubble-sort
%2F&psig=AOvVaw2VV_JkNK-
0wGypNDO5J9Rr&ust=1698871776872000&source=images&cd=vfe&opi=89978449&ved=0
CBIQjRxqFwoTCMDqs9iUoYIDFQAAAAAdAAAAABAE [Accessed 31 Oct. 2023].

Google.com. (2023). Redirect Notice. [online] Available at: https://www.google.com/url?


sa=i&url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fwww.c-programming-simple-steps.com%2Fbubble-
sort.html&psig=AOvVaw3wXXgzfsy3f10wTdrzKFe4&ust=1698873825377000&source=image
s&cd=vfe&opi=89978449&ved=0CBIQjRxqFwoTCMCMxKmcoYIDFQAAAAAdAAAAABAY
[Accessed 31 Oct. 2023].

GeeksforGeeks. (2018). Language Processors: Assembler, Compiler and Interpreter -


GeeksforGeeks. [online] Available at: https://www.geeksforgeeks.org/language-processors-
assembler-compiler-and-interpreter/.

Thakur, S. (n.d.). Difference Between Compiler, Interpreter And Assembler // Unstop


(formerly Dare2Compete). [online] unstop.com. Available at:
https://unstop.com/blog/difference-between-compiler-interpreter-
assembler#:~:text=Compilers%20and%20interpreters%20convert%20High [Accessed 31 Oct.
2023].
Google.com. (2023). Redirect Notice. [online] Available at: https://www.google.com/url?
sa=i&url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fundefined.photos%2Fphoto-gallery%2Fwhat-is-difference-
between-compiler-interpreter-and-assembler&psig=AOvVaw3xFU2Srxd-
hh3RCPBk8EPj&ust=1698876486753000&source=images&cd=vfe&opi=89978449&ved=0CB
QQjRxqFwoTCJi44p6moYIDFQAAAAAdAAAAABAn [Accessed 31 Oct. 2023].

Google.com. (2023). Redirect Notice. [online] Available at: https://www.google.com/url?


sa=i&url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Ftechnologystrive.com%2Fflow-chart%2Fsum-of-three-
numbers&psig=AOvVaw0sKD8y7x_6ct8P6NDIaOPr&ust=1698877420602000&source=image
s&cd=vfe&opi=89978449&ved=0CBQQjRxqFwoTCICwvNupoYIDFQAAAAAdAAAAABAE
[Accessed 31 Oct. 2023].

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.

Wikipedia Contributors (2019). Programming paradigm. [online] Wikipedia. Available at:


https://en.wikipedia.org/wiki/Programming_paradigm.

deepsource.com. (n.d.). DeepSource | The Modern Static Analysis Platform. [online]


Available at: https://deepsource.com/glossary/procedural-programming#:~:text=Procedural
%20programming%20is%20a%20programming.

‌SearchAppArchitecture. (n.d.). What is Object-Oriented Programming (OOP)? [online]


Available at: https://www.techtarget.com/searchapparchitecture/definition/object-
oriented-programming-OOP#:~:text=Object%2Doriented%20programming%20(OOP)%20is
%20a%20computer%20programming%20model.

Wikipedia Contributors (2019). Event-driven programming. [online] Wikipedia. Available at:


https://en.wikipedia.org/wiki/Event-driven_programming.


You might also like