Monostate Design Pattern explained with simple example

Monostate design pattern is a singleton design pattern variation in which a class will act like a singleton but this class will look like a normal class. This design pattern states that all data member of monostate classes are static but any number of instances can be created in the program.

Before going ahead have a look at Design pattern simplified version and Singleton design pattern.

(more…)
Monostate Design Pattern explained with simple example Read More

Finding number of ways to write “n” as sum of multiple smaller numbers

This problem can be solved using multiple approaches but here we will solve this problem using Dynamic Programming and showcase how dynamic programming will make the execution super-fast.

We will go through with the same steps as mentioned in Dynamic Programming post to tackle this problem step by step for better understanding.

Let’s explain the problem,

given n, find the number of different ways to write “n” as the sum of 1, 3, 4

Example:

for n = 5, the answer is 6

5 = 1+1+1+1+1

   = 1+1+3

   = 1+3+1

   = 3+1+1

   = 1+4

   = 4+1

Let’s apply the 3 Steps rule to tackle this problem.

(more…)

Finding number of ways to write “n” as sum of multiple smaller numbers Read More

Dynamic Programming approach explained with simple example

Dynamic Programming is a programming technique which is used for solving complex problems by breaking it into comparatively simpler subproblems and finding the optimal solutions of the complex problems by finding the optimal solutions of these subproblems.

Even though, the name “Dynamic Programming” might scare people but actually its kind of simple if we follow some basic techniques to approach any complex problem.

Steps to tackle a problem using Dynamic Programming approach:

1) Define smaller problems from the original complex problems.

2) Solve these smaller problems using recursion.

3) Use smaller problems results to solve the bigger complex problem.

(more…)

Dynamic Programming approach explained with simple example Read More

Heap sort explained with simple example

Heap sort is one of the fastest sorting algorithm, which works on Divide and Conquer algorithm. In this sorting algorithm, all the data elements are inserted into a heap (max or min) and then removes item from the root of the heap will give the sorted(descending or ascending) data list.

Pros:
1) Faster algorithm and best performance O(nlogn).
2) Simple implementation.
3) No extra space is needed.
4) Good for cases to find biggest/smallest or top k biggest/smallest element finding kind of scenarios.

Cons:
1) Not a stable sort means position of relative identical data items is not guaranteed.

(more…)

Heap sort explained with simple example Read More

Quick sort explained with simple example

Quick sort is one of the fastest sorting algorithm, which works on Divide and Conquer algorithm. In this sorting algorithm, an element is picked as a pivot element and list is divided into sub-lists around the pivot element. These divided sub-lists finally sorted into which results into sorted initial list.

Pros:
1) Faster algorithm and best performance O(nlogn) is for worst distribution case scenario.
2) Simple implementation due to recursive nature.
3) No extra space is needed.

Cons:
1) Worst case scenario performance is O(n*n).
2) Not good for Linked list kind of sorting data where memory is not contiguous.

(more…)

Quick sort explained with simple example Read More

Chain-of-Responsibility Design Pattern Explained With Simple Example: Behavioural Design Pattern Category

The Chain-of-Responsibility design pattern basically consists of a source of command objects and a hierarchical series of processing objects. Every processing unit will process only typical kind of commands and it will pass rest of the command to next processing unit, thus creating a chain of processing units and that’s why the name of this design pattern is Chain-of-Responsibility pattern. This pattern provides the idea of one of the best programming practice which is “loose coupling”. For Design patterns basic explanation see (Design Patterns Simplified Version).

(more…)

Chain-of-Responsibility Design Pattern Explained With Simple Example: Behavioural Design Pattern Category Read More

Proxy Design Pattern Explained With Simple Example: Structural Design Pattern Category

The Proxy design pattern allows to define a “proxy” class which will act as a wrapper object which will be called by the client to access the product object without exposing the details. This proxy class can also be used to add extra functionality without changing the product behavior. This design pattern can be used in cases to provide additional security access to an existing product or providing an interface for remote resources. For Design patterns basic explanation see (Design Patterns Simplified Version).

(more…)

Proxy Design Pattern Explained With Simple Example: Structural Design Pattern Category Read More

Diameter Agents Simple Explanation

Diameter protocol defines various nodes for specific purposes which are often known as Diameter Agents. These agents are designed to distribute administrations of a system including maintenance of security mechanism. These Agents can also be used for load balancing via routing the diameter protocol messages based on some routing algorithms.
They can also do some sort of processing of diameter protocol messages to forward messages towards the target in a complex network which contains a large number of nodes.

Diameter Agents can be divided into two groups:

(more…)

Diameter Agents Simple Explanation Read More

Diameter Protocol Message Structure

Diameter protocol is basically a Request/Response kind of protocol, hence this diameter protocol follows client/server model to communicate between nodes. In Diameter protocol, for every request message there will be an answer message for sure. For basic information related to Diameter protocol read article (Diameter Protocol Basics).

A Diameter protocol packet consists of Diameter message header along with variable number of AVP’s (Attribute-Value Pairs). Diameter message data is stored in form of AVP’s in the message.

(more…)

Diameter Protocol Message Structure Read More