Assignment of Algorithm (4 Files Merged)
Assignment of Algorithm (4 Files Merged)
. 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.
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.
cheese.
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.
Step 4: display=3+4=7
display=3+4=7
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
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
-2>0 no 0 is greater
No swapping
11>45 no
45 is greater
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.
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.
The steps of building of are building an application including algorithm can b build in 6 steps
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:
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
Polymorphism
Inheritance
Encapsulation
Example:
Output:
15
Some text
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.
Then, we use a for loop to input the numbers from the user and store them in
the num array.
average = sum / n;
REPORT
Compare and contrast the procedural, object oriented and event driven programming in
source code of application.
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.
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