You are on page 1of 10

DATA STRUCTURES AND ALGORITHMS

Introduction and Definition of terms.

• Programming strategies
A programme strategy is a coherent set of programme activities designed to achieve a specified goal
or set of objectives. Computer programming is the process of writing code to facilitate specific actions
in a computer, application or software program, and instructs them on how to perform. Programming
is the implementation of logic to facilitate specified computing operations and functionality. It occurs
in one or more languages, which differ by application, domain and programming model. Programming
language semantics and syntax are used when constructing an application. Thus, programming
requires knowledge of application domains, algorithms and programming language expertise.

Programming language logic differs by developer. From a high level, good code can be evaluated with
factors such as:

• Robustness: Focuses on program continuation capability, regardless of errors or incorrect data


• Reliability: Focuses on correct design and algorithm implementation
• Efficiency: Focuses on memory, hardware or other properties used to optimize programs
• Readability: Proper documentation and indentation availability, which provides insight to
other program developers or designers

Advantages of Programming

o It enhances problem-solving skills.


o Using programming, we can solve complex problems.
o It is also learning with fun.
o It can perform multiple tasks can be bundled into one module.
o It saves time and effort.

Disadvantages of Programming

o Knowledge of computer is mandatory.


o Logical thinking should be strong.

Programming Paradigms

Programming paradigms are different ways or styles in which a given program or programming
language can be organized. Each paradigm consists of certain structures, features, and opinions about
how common programming problems should be tackled.

GEORGE WAINAINA 0718313173/0731919231 georgewainaina58@gmail.com Page 1


Types of Programming Paradigms

There is the following two programming paradigm:

o Imperative Programming Paradigm


o Declarative Programming Paradigm

Imperative Programming Paradigm

Imperative programming is a programming paradigm that uses statements that change a program's
state. An imperative program consists of commands for the computer to perform. It describes the
detail of how the results are to be obtained. How means describing the inputs and describing how the
outputs are produced.

Examples of imperative programming paradigm are C, Fortran, Basic, Java, C++, Python, Ruby, PHP,
etc.

Advantages

o Easy to implement.
o It contains loops, variables, etc.
o It is efficient.

Disadvantages

o We cannot choose it for solving complex problems.


o It is less efficient and less productive.
o It is not suitable for parallel programming.
o Order is crucial.

GEORGE WAINAINA 0718313173/0731919231 georgewainaina58@gmail.com Page 2


Types of Imperative Programming Paradigm

There are the following types of imperative programming paradigms:

o Object-oriented Programming
o Procedural Programming
o Parallel Processing Approach

Object-oriented Programming

The object-oriented programming paradigm is based on the concept of object. An object contains
data in the form of fields that are known as attributes and the procedures are known as methods.

Since objects work independently, they are encapsulated into modules. we can communicate with an
object by using message passing.

Object-oriented programming can be achieved by using programming languages such as Java, C++,
C#, PHP, and Python, etc.

Procedural Programming

The paradigm deals with procedure calls that are called routines or functions. the functions contain a
series of computational commands to be carried out to achieve a certain outcome.

It is just like a procedure, with a list of step-by-step instructions for the computer program to follow.
The code can easily be reused in different parts of the program. The advantage of the paradigm is that
the code can be easy to learn and read in simple programs. Though, while dealing with a complex
problem, we run the risk of ending up with a huge volume of code.

Example of procedural programming is BASIC, C, and Pascal.

Parallel Processing Approach

The parallel programming paradigm breaks the problem or task into chunks that are distributed
among multiple processors. These chunks work on the same problem, simultaneously. It reduces the
total time to solve a problem. It connects multiple processors to the memory. It is either pooled across
all processors or distributed over a network.

There are several programming languages that support parallel processing.

Example of parallel programming paradigm is SISAL, Parallel Haskell, SequenceL, System C (for
FPGAs), Mitrion-C, VHDL, and Verilog, MPI.

GEORGE WAINAINA 0718313173/0731919231 georgewainaina58@gmail.com Page 3


Declarative Programming Paradigm

Declarative programming is a style of building the structure and elements of computer programs. It
expresses the logic of a computation without describing its control flow. In other words, styles of
programming that are not imperative are called declarative programming paradigm. It
emphasizes what the program should accomplish.

Examples of declarative programming paradigm are Scala, Haskell, Erlang, Lisp, ML, Closure,
SQL, XSQL, etc.

Advantages

o Efficient and shortcode


o Referential Transparency
o Idempotence
o Error recovery
o Readability
o Commutativity
o Easy optimization

Disadvantages

o Difficult to understand.
o It is abed on an unfamiliar conceptual model.
o Difficult to accept characteristics of specific applications into account while programming.

Types of Declarative Programming Paradigms

o Functional Programming
o Logical Programming
o Database Processing Approach

Functional Programming

It is a subset of declarative programming. Programs that are written using the paradigm use functions,
blocks of codes, intended to behave like mathematical functions. It discourages changes in the value
of variables through the assignment. Instead makes a great deal with recursion.

Examples of functional programming Haskell, SML, Clojure, Scala, Erlang, Clean, F#, etc.

GEORGE WAINAINA 0718313173/0731919231 georgewainaina58@gmail.com Page 4


Logical Programming

The Logical Paradigm adopts a decisive strategy to critical thinking. Different consistent declarations
about a circumstance are made, setting up totally known realities. The paradigm is divided into three
sections:

1. A series of definitions/affirmations that characterize the problem domain


2. Statements of facts that are relevant
3. Statement of objectives or goals in the form of query

Example of logical programming is PROLOG, SQL, etc.

Database Processing Approach

The data-driven programming paradigm depends on information and its development. In this
paradigm, the program statements are characterized by data instead of hard-coding a progression of
steps. A data set program is the core of a business data framework and gives document creation,
information section, update, query, and reporting functions.

There are a few programming dialects that are developed for the most part for data set applications.
For example, SQL. It is applied to surges of organized information, for filtering, transforming,
aggregating, or calling different projects. So, it has its own wide application.

Example of database processing approach programming is SQL (only DQL), QML,


RDQL, and SPARQL.

Apart from the imperative and declarative programming approach, there is another paradigm that is
known as the multi-paradigm.

Multi-Paradigm

The programming languages that support more than one programming paradigm fall into this
category. The design goal of such languages is to allow programmers to use the most suitable
programming style associated with languages constructs for a given job.

The example of multi-paradigm programming languages is C++, Java, Python, etc. The languages
support object-oriented programming greater or lesser degree, typically in combination with
imperative and declarative programming paradigm.

Usually, in a program, distinctive programming standards are utilized. Henceforth, programming


dialects offer help (with various degrees) for the different standards.

The following table provides a brief description of programming paradigms.

GEORGE WAINAINA 0718313173/0731919231 georgewainaina58@gmail.com Page 5


Paradigms Key Program Program Execution Result
Concept

Procedural Command Sequence of commands Execution of commands Final state of


computer memory

Functional Function Collections of functions Executions of functions Value of the main


function

Logic Predicate Logic formulas: axioms Logic proving of the Failure of success of
and a theorem theorem proving

Object- Object Collections of classes of Exchange of messages Final state of the


oriented objects between the objects object's state
The object-oriented paradigms state is the most abstract, as it's basic ideas can be easily combined
with the principles and programming techniques of the other styles.
Programming Paradigm Programming Languages

Procedural FORTRAN, COBOL, ALGOL, BASIC, C, and Pascal.

Functional Haskell, SML, Clojure, Scala, Erlang, Clean, F#, etc.

Object-oriented Java, Python, C++, C#, Kotlin, Scala, Swift, Ruby, Perl, etc.

Logical PROLOG, SQL, etc.

Parallel Processing SISAL, Parallel Haskell, SequenceL, System C (for FPGAs), Mitrion-C,
VHDL, and Verilog, MPI.

Database Processing SQL (only DQL), QML, RDQL, and SPARQL.


Approach

• Objects and ADTS

An abstract data type (ADT) is the specification of a data type within some language, independent of
an implementation. The interface for the ADT is defined in terms of a type and a set of operations on
that type. The behavior of each operation is determined by its inputs and outputs. An ADT does not
specify how the data type is implemented. These implementation details are hidden from the user of
the ADT and protected from outside access, a concept referred to as encapsulation. An object,
in object-oriented programming (OOP), is an abstract data type created by a developer. It can include
multiple properties and methods and may even contain other objects. In most programming
languages, objects are defined as classes.

Objects provide a structured approach to programming. By defining a dataset as a custom object,


a developer can easily create multiple similar objects and modify existing objects within a program.

GEORGE WAINAINA 0718313173/0731919231 georgewainaina58@gmail.com Page 6


Additionally, objects provide "encapsulation," meaning the data within an object is protected from
being modified or destroyed by other functions or methods unless explicitly allowed.

A simple example of an object may be a user account created for a website. The object might define
as class user Account and contain attributes such as:

• first name
• last name
• email address
• password
• age
• location
• photo
Instead of recreating these properties each time a new user account is created, a web script can simply
instantiate a user Account object. Data assigned to the object may be stored in a database if the user
account is saved.

• Objects and Destructors


Destructor is an instance member function which is invoked automatically whenever an object is
going to be destroyed. Meaning, a destructor is the last function that is going to be called before an
object is destroyed.
• Destructor is also a special member function like constructor. Destructor destroys the
class objects created by constructor.
• Destructor has the same name as their class name preceded by a tilde (~) symbol.
• It is not possible to define more than one destructor.
• The destructor is only one way to destroy the object create by constructor. Hence
destructor can-not be overloaded.
• Destructor neither requires any argument nor returns any value.
• It is automatically called when object goes out of scope.
• Destructor release memory space occupied by the objects created by constructor.
• In destructor, objects are destroyed in the reverse of an object creation.

GEORGE WAINAINA 0718313173/0731919231 georgewainaina58@gmail.com Page 7


Constructor in programming is a special method that is invoked automatically at the time of
object creation. It is used to initialize the data members of new objects generally. The constructor
has the same name as the class or structure. Constructor is invoked at the time of object creation.
It constructs the values i.e. provides data for the object which is why it is known as constructors.
• Constructor does not have a return value; hence they do not have a return type.
• The prototype of Constructors is as follows:
• <class-name> (list-of-parameters);

• Data Structures
A data structure is a storage that is used to store and organize data. It is a way of arranging data
on a computer so that it can be accessed and updated efficiently. A data structure is not only used
for organizing the data. It is also used for processing, retrieving, and storing data. There are
different basic and advanced types of data structures that are used in almost every program or
software system that has been developed.

Data Structures help programmers manage the data efficiently. They are a vital component of many
computer algorithms. With a data structure, vital operations can be performed with fewer resources.
An informed selection of data structures can improve the performance of a computer program or
software.

Algorithms and complexity

An algorithm is a specific procedure for solving a well-defined computational problem. The


development and analysis of algorithms is fundamental to all aspects of computer science: artificial
intelligence, databases, graphics, networking, operating systems, security, and so
on. Algorithm development is more than just programming. It requires an understanding of
the alternatives available for solving a computational problem, including the hardware, networking,
programming language, and performance constraints that accompany any particular solution. It also
requires understanding what it means for an algorithm to be “correct” in the sense that it fully and
efficiently solves the problem at hand. The (computational) complexity of an algorithm is a measure
of the amount of computing resources (time and space) that a particular algorithm consumes when it
runs. Computer scientists use mathematical measures of complexity that allow them to predict, before

GEORGE WAINAINA 0718313173/0731919231 georgewainaina58@gmail.com Page 8


writing the code, how fast an algorithm will run and how much memory it will require. Such
predictions are important guides for programmers implementing and selecting algorithms for real-
world applications.

Computational complexity is a continuum, in that some algorithms require linear time (that is, the
time required increases directly with the number of items or nodes in the list, graph, or network
being processed), whereas others require quadratic or even exponential time to complete (that is, the
time required increases with the number of items squared or with the exponential of that number).

A well-defined algorithm has five important features or properties:


▪ Free from Ambiguity (Definiteness). Each step of an algorithm must be precisely defined;
the actions to be carried out must be rigorously and unambiguously specified for each case
▪ Efficient (Finiteness). An algorithm must always terminate after a finite number of steps.
▪ Effectiveness. An algorithm is also generally expected to be effective. This means that all of the
operations to be performed in the algorithm must be sufficiently basic that they can in principle
be done exactly and in a finite length of time
▪ Input. An algorithm has zero or more inputs, i.e, quantities which are given to it initially before
the algorithm begins.
▪ Output. An algorithm has one or more outputs i.e, quantities which have a specified relation to
the inputs.

Generally, there is always more than one way to solve a problem in computer science with
different algorithms. Therefore, it is highly required to use a method to compare the solutions in
order to judge which one is more optimal. The method must be:
• Independent of the machine and its configuration, on which the algorithm is running
on.
• Shows a direct correlation with the number of inputs.
• Can distinguish two algorithms clearly without ambiguity.

There are two such methods used, time complexity and space complexity:

Time Complexity: The time complexity of an algorithm quantifies the amount of time taken by
an algorithm to run as a function of the length of the input. Note that the time to run is a function
of the length of the input and not the actual execution time of the machine on which the
algorithm is running on.

Space Complexity: The space complexity of an algorithm quantifies the amount of space taken
by an algorithm to run as a function of the length of the input.

GEORGE WAINAINA 0718313173/0731919231 georgewainaina58@gmail.com Page 9


• Methods
A method is a set of code which is referred to by name and can be called (invoked) at any point in
a program simply by utilizing the method's name. A function takes parameters and returns a value.
A "method" is a specific type of function: it must be part of a "class", so has access to the class'
member variables. A function is usually discrete and all variables must be passed in.

We have declared a method named addNumbers() in a program. Now, to use the method, we need
to call it.

• Pre and Post Conditions


A precondition is a statement placed before the segment. It must be true prior to entering the
segment in order for it to work correctly. Preconditions are often placed either before loops or at
the entry point of functions and procedures. A postcondition is a statement placed after the end
of the segment.

GEORGE WAINAINA 0718313173/0731919231 georgewainaina58@gmail.com Page 10

You might also like