0% found this document useful (0 votes)
139 views

Assignment of Algorithm (4 Files Merged)

The document discusses various algorithms and programming paradigms. It defines an algorithm as a procedure or method to solve a problem in a finite number of steps. Examples of algorithms mentioned include bubble sort and quick sort. It also discusses procedural programming, which breaks tasks into variables and procedures, and event-driven programming, where program flow is determined by user events. Real-life examples of algorithms in areas like social media are provided.

Uploaded by

Priyanka Kapoor
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views

Assignment of Algorithm (4 Files Merged)

The document discusses various algorithms and programming paradigms. It defines an algorithm as a procedure or method to solve a problem in a finite number of steps. Examples of algorithms mentioned include bubble sort and quick sort. It also discusses procedural programming, which breaks tasks into variables and procedures, and event-driven programming, where program flow is determined by user events. Real-life examples of algorithms in areas like social media are provided.

Uploaded by

Priyanka Kapoor
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

REPORT

. Algorithm

Definition

• Algorithm is a procedure or a method which is used for finding the solution of a problem as
it gives a clear solution in a finite number of steps. Algorithm is used to transfer the data into
information. this method is used for listing the steps of operations that can be used to solve a
problem. here are some examples of Algorithms such as bubbles sort quick sort, binary
search etc.

Real life example

The algorithm is used in today’s life as they are used in social technologies like on mobiles as we use
different apps like Facebook which shows us different sides such as our stories our posts our timelines
and on the feed side it shows us our posts which are related to our searching browser.so this means that
we are spending less time through algorithm. The Real Life example is that if we make burger. we
should follow the steps given below.

first step is that we need a bread for

burger. second step is we add grilled

cheese.

third step we add grilled meat

piece. forth step then the cooking

will start. Fifth step

then the food is cooked.


Characteristics of algorithm and benefits

In algorithm all steps should be clearly defined as input. The results should be given in output.
algorithm solves o with finite number of steps. this method solves the problems by defining them and it
is used in any languages. this method can give much benefits such as it gives proper logic when we use
it and it is easy to understand for the one who uses it.

Algorithm was tested in 20th century that it is used for computer works and in mathematics.
Basically, algorithm have characteristics such as input, output, definiteness and finiteness.

 An Input of algorithm shows that the computer stores data.


 An output of algorithm shows the result of the input data.
 Definiteness of algorithm means that everything should be clearly defined.
 Finiteness is a finite number which is used in algorithm and this process should be done
with finite numbers.
For example: Below is a simple algorithm to add two numbers and display its
sum.

Step 1: start diagram = Start Step 2: Take first

num 3 input of sum 3

Step 3: Take second num 4 input of sum 4

Step 4: display=3+4=7

display=3+4=7

step 5: end total =7 end total =7

Bubble Sort Algorithm

it is a form of algorithm which is continuously used to swap the ascending numbers if they are not in
proper sequence from left to right. This bubble Sort algorithm always works the limited numbers. In
its diagram the N is called the number of items in which the user sums them to find the values to
make in
sequence. This method is beneficial for the programmers because of algorithms as they are easier
to understand.

The diagram shown on right side is an example of a bubble sort algorithm which shows the elements
swapping as ascending order. Now thirteen is greater than 9 so, it is swapped and then thirteen is
greater than twelve so again it is swapped. but it is smaller than fourteen then it will not be swapped
because the smaller number never gets forward swap as it remains on its place otherwise it gets
backward swap. In other word’s the bubble sort remain incomplete until unless the elements get in
ascending order.
 bubbles sort picture

processing and operation -


2>45
45 is greater
no swap.

45>0 45 is
greater 45

be swapped.

45>11 45 is greater 45
is swap.

45>-9 45 is greater 45 is
swap
-2>0 no
0 is greater

No swapping

0>11 no

No swapping

11>-9 11 is

Greater 11 will
swapped

Till now not arranged

-2>0 no 0 is greater
No swapping

0>-9 yes 0 is greater so it is


swapped

11>45 no

45 is greater

Till now not


arranged
-2>-9 -2 is greater -2
is swap

Quick sort Algorithm

Quick sort algorithm is a highly active method of algorithm which is used to divide elements by
selecting them from arrays. this method starts from selecting an element which is called pivot from an
array and it divides or arranges all the elements in sequence as they are smaller or larger. this method is
used to divide the elements into two portions as the one array elements are of smaller and the other array
is larger. This method has a speed to partition the elements of arrays and saves time.

 Diagram processing and operation


1.select the first pivot element. Then compare it with the other elements with the first array.
2.the smaller elements will be placed on the left array and greater elements will be placed on the
rig

3.the pivot will be compared with the other element . if the element is smaller than the pivot so
the element will be swapped and the greater element will be set.

4.the process will be repeated again for the next greater element.it will be compared with another
small element of another array and then it will be swapped.
5. The process will be continued until unless the element is
swapped.

6.now the element is swapped with the second pointer.


Steps in Building an Application and Role of Algorithms in
it

The steps of building of are building an application including algorithm can b build in 6 steps

1. the explanation of problem


this step is very important for algorithm. all of the information of problems should be
given.
2. checking and inspecting the problem
This step is of analyzing in the problem which includes data that must be gained and
processed for a valid output.
3. the development of algorithm
This step is to solve the problems for programming.
4. coding
This step uses the language of program to write and implement the programming of the
upper steps.
5. testing and debugging
This step is to check the code running/solving the problem or not.
6. maintain the algorithm
this step is used to maintain the enhancement found. In the maintenance the all procedure
is repeated of each step.
References.

Tutorialspoint.com. 2021. Data Structures - Algorithms Basics. [online] Available


at:
<https://www.tutorialspoint.com/data_structures_algorithms/algorithms_basics.htm
Available at:
Downey, L., 2021. What Is an Algorithm?. Investopedia.
<https://www.investopedia.com/terms/a/algorithm.asp
Kumari, R., 2021. What is an Algorithm? Types, Applications, and Characteristics | Analytics
Steps. [online] Analyticssteps.com. Available at: <https://www.analyticssteps.com/blogs/what-algorith
m-types- applications-characteristics

GeeksforGeeks. 2021. QuickSort - GeeksforGeeks. [online] Available


at:
<https://www.geeksforgeeks.org/quick-sort/
.
REPORT

 Procedural Programming:
Procedural programming is a programming pattern or model based on the concept of the Procedures. It
simply contains a chain of computational steps to be carried out. The basic focus of the procedural
programming is to break down a programming task into a collection of variables or data structures.
Which means that any given procedure might be called at any point during the program's execution.
Some of the examples of procedural programming languages are COBOL, PASCAL, FORTRAN, C and
PL1.
The characteristics of procedural programming are:
 Procedural programming follows a top-down approach.
 The program is divided into blocks of codes called functions, where each function performs
a specific task.

Example:
The language C is an example of a strictly procedural language.
Example code:

Output:
hello world! (output of the
program)
 Event-Driven Paradigm:
Event-driven paradigm is a programming paradigm in which the flow of the program is determined by
the events such as user actions which can be mouse clicks or any key presses and to respond to actions
generated by the user or the system. Event-driven programming is very commanding and ruling
paradigm used in GUI’s and some other applications this is how the Event-driven programming separates
event- processing logic from the rest of a program's code.
Characteristics of event driven programming:

 Characteristics of event driven programming provides a comprehensive and


comprehensive pathway for students to see progress after the end of each module
 m of extremely dedicated and quality lecturers, characteristics of event driven programming
will not only be a place to share knowledge but also to help students get inspired to explore and
discover many creative ideas from themselves.
 Event driven programming are guaranteed to be the most complete and intuitive.

Code:
The following example of event loop helps in printing hello world by using the get event loop()
method. This example is taken from the Python official docs.
Output:
Hello World

 Object-oriented paradigm:
Object oriented programming is a programming paradigm characterized by the identification of classes
of objects closely linked with the methods with which they are associated. It also includes ideas of
inheritance of attributes and methods based on the concept of objects which can contain data and code
data in the form of attributes or properties and code in the form of methods. A feature of objects is that
an object's can access and often modify the data fields of itself

Characteristics Object-oriented paradigm:


Object-oriented methodology relies on three characteristics that define object-oriented languages
these are.

 Polymorphism
 Inheritance
 Encapsulation

Example:
Output:
15
Some text

Relationship between Procedural Paradigm, Object oriented, event driven


programming. Procedural paradigm:

 In procedural programming, program is divided into small parts called functions.


 The execution of program statements is predetermined and controlled by the
programmer.
 Procedural programming follows top down approach.

Event driven program:

 In event driven programming the execution of program is largely determined by the


system.
 One defines what will occur when a user executes an event.

Object Oriented Paradigm:


 In object oriented programming, program is divided into small parts called
objects.
 Object oriented programming follows bottom up approach.
References:
https://www.mooict.com/what-are-procedural-event-driven-and-object-orientated-programming/
https://www.technologyuk.net/computing/software-development/software-design/event-driven-
programming.shtml
https://www.tutorialspoint.com/concurrency_in_python/concurrency_in_python_eventdriven_pr
og ramming.htm
https://www.w3schools.com/cpp/cpp_classes.asp
REPORT

This program calculates the average of all the numbers entered by the
user.
C++ code on Visual Studio:

Output:
Debugging:

Execution process:
Preprocessor:
This is the first stage of any C/C++ program execution process; in this
stage Preprocessor processes the program before compilation.
The numbers are stored in the float array num, which can store up to 100
floating- point numbers.
We first ask the user to specify how many numbers we will be calculating. This
is stored in the variable n.
Complier:
This is the second stage of any C/C++ program execution process, in this
stage generated output file after preprocessing ( with source code) will be passed
to the compiler for compilation. Complier will compile the program, checks
the errors and generates the object file
If the user enters a value of n above 100 or below 100, a while loop is
executed which asks the user to enter a value of n until it is between 1 and 100.
Linker:
This is the third stage of any C/C++ program execution process, in this
stage Linker links the more than one object files or libraries and generates the
executable file.

while (n > 100 || n <= 0)


{
cout << "Error! number should in range of (1 to 100)." <<
endl; cout << "Enter the number again: ";
cin >> n;
}

Then, we use a for loop to input the numbers from the user and store them in
the num array.

for(i = 0; i < n; ++i)


{
cout << i + 1 << ". Enter number:
"; cin >> num[i];
sum += num[i];
}
Loader:
This is the fourth or final stage of any C/C++ program execution process, in
this stage Loader loads the executable file into the main/primary memory.
And program run.
By the end of the loop, the total sum of all the numbers is stored in sum.
After storing all the numbers, average is calculated and displayed.

average = sum / n;
REPORT

Compare and contrast the procedural, object oriented and event driven programming in
source code of application.

Contrast between procedural/OOP/Event Driven paradigm

Procedural  In procedural programming, program is divided into small parts called


programming. functions.
 In procedural programming the execution of program statements
is predetermined and controlled by the programmer.
 Procedural programming follows top down approach.
 There is no access modifiers in procedural programming.
 Procedural programming does not have any proper way for hiding data so
it is less secure.
 Procedural programming is based on unreal world.
 Languages supports: C, FORTRAN, Pascal, Basic etc.

Object oriented  In object oriented programming, program is divided into small parts
paradigm called objects.
 In object oriented programming computer programs are designed
using the
concept of objects that interacts with the real world.
 Object oriented program follows bottom up approach
 Object oriented programming provides data hiding so it is more
secure.
 Object oriented programming is based on real world.
 Languages supports: C++, Java, Python, C# etc.
Event-driven paradigm  In event-driven flow of the program is determined by events such as user
actions (mouse clicks or key presses) sensor outputs, or messages from
other programs or threads.
 In event driven programming the program execution is largely
determined by the system.
 In event-driven programming paradigm, one defines what will occur when
a user executes an event.

Comparison between procedural/OOP/Event Driven paradigm

Procedural  Procedural programming means that as a series of steps you describe a program
programming. and its subprograms.
 Declarative programs in procedural paradigm attempts to define the result
irrespective of the steps taken to calculate it but rather some description
or denotation of the desired result.
 Procedural programming relies on what’s known.
 Procedural code is quicker to implement for simpler code but gets
increasingly complex and difficult to manage as the program gets larger.
Object oriented  Object-oriented programming is a way to organize code around the concepts
paradigm of encapsulation, inheritance, replacement, programming to interfaces etc.
 Object oriented programming is meant to address the difficulties with
procedural programming paradigm.
 Object Oriented Programming allows for easy re-use of code and enabling
faster coding and managing on larger projects

Event Driven paradigm  Event-Driven Programming shares some features with OOP that include the use
of variables, procedures, classes and objects.
 Event based programming is about writing event handling procedures and
having the core event loop provided by the underlying system.
 You can save the trouble of writing your own event loop and benefit from
various libraries that already work with the system provided event loop.
 Event based programs are very often writing using object oriented style but not
always.
 This programs allow for reusability of codes and as such different programs
may use the same codes similar functions.
https://www.tutorialspoint.com/concurrency_in_python/concurrency_in_python_eventdriven_pr
og ramming.htm
https://www.w3schools.com/cpp/cpp_classes.asp

You might also like