Big O Notation, Programming Paradigms
Big O Notation, Programming Paradigms
The big O notation also known as the time complexity defines the longest time it can take to perform an
operation. Some common complexities include:
The O(1) complexity Constant time complexity: This is used when you try to access a value with its
index in an array.
The O(n) Linear time complexity: This is used when inserting an item into a hash table, or in real life,
reading book with a number of pages, simple search. Here, time increases s input increases.
O(log n) Logarithmic time complexity: Binary search in a sorted array. As input size grows, operation
time increases slowly in a linear manner.
Programming Paradigms.
It refers to a way of solving problems using the features available in a particular programming language,
i.e. the style of programming.
This uses the imperative mood which involves making a command or a request. It uses a series of
command which specify what the computer had to do, and when, in order to achieve a desired result e.g
Java, Basic, Fortran, Assembler etc Here, we'll be seeing concepts like procedural programming and
object-oriented programming.
This focuses more on what a program should accomplish and less on how to go about it. It describes
their desired results without texting the commands that must be performed. It may seem like magic but
there's a lot of work going on under the hood. Here, concepts involved include the functional
programming concept, eg furniture assembly. While imperative programming provides for assembly,
declarative programming provides a picture of the finished piece of furniture as a template. the
integrative functional programming concept for example for assembly instructions for assembly
instructions for assembly declarative programming provides a picture of the finished piece of furniture
as a template so let's take the example again so when you're trying to assemble furniture imperative
programming would say okay I have to go through this particular steps and so on but the declarative
programming paradigm would give you a picture of the finished piece of furniture as a template to work
with. Most modern language support both paradigms to an extent but let's talk a bit more about
procedural programming. Procedural programming follows a simple step-by-step approach to creating
software. Each procedure is usually a function or a set of functions. Languages that follow procedural
concepts include Pascal, Fortran and the rest of them. for example an application to use a library when
written in procedural programming formats would look like:
function register () {}
function addBook () {}
function removeBook () {}
function findBook () {}
function borrowBook () {}
function returnBook () {}
So generally these are the steps involved in using a library. so that is how the procedural programming
concepts would list it out for you.
- Easy to learn.
- The data is exposed to the whole program, hence it is not very safe.
- ait can be hard to modify and debug as the application gets managed.
OOP structures a software program into simple, reusable pieces of code blueprints (usually called
classes), which are used to create individual instances of objects. Classes represent broad categories,
like car or dog that share attributes. Classes define what attributes an instance of this type would have,
like color, but not the value of those attributes for a specific object. Classes can also contain functios
called methods available only to objects of that particular type. See the illustration in fig 1 below:
Encapsulation
Abstraction
Inheritance and
Polymorphism
The encapsulation principle states that all important information is contained inside an object and only
select information is exposed.
For abstraction, applying it means that each object should only expose a high level mechanism for using
it. This mechanism should be easy to use and should rarely change over time. It's like a small set of
public methods which any other class can call without knowing how they work.
Inheritance, as a property of OOP forces a more thorough data analysis, reduces development time and
ensures a higher level of accuracy.
Polymorphism gives a way to use a class exactly like its parent so there's no confusion with mixing types,
but each child class keeps its own methods as they are.
Advantages of OOP
- Modularity:
- Flexibility:
- Security:
Using encapsulation and abstraction, complex code is hidden, software maintenance is easier and
internet protocols are protected.
- Reusability: