Skip to content
# Asides

## Insertion sort

## UML for Design Based Software Development

## Exception handling in a python list

## Dynamic Fibonacci

## Greedy Algorithm

## Software Development Life Cycle

## searching algorithms

A software developer, and a data science enthusiast

Basic insertion sort

Before writing the actual code it is always handy to plan, and design what we want to build. There are so many ways to do so; UML (Unified Modelling Language) is one of them, and there are many types of UML diagrams, such as, Class Diagram, Use case Diagram, Component Diagram, Sequence Diagram.

In my personal opinion, writing codes without at least a class diagram seems very naive. Let’s see how class diagram can help us building a software rapidly.

Let’s assume we are given a task of reading an XML file, renaming the tags based on some given values, and generate a new XML file with the new tags. How would you map this problem!? If we just go for the coding right away, there is a higher chance of fragility somewhere during the development. So it is undoubtedly a better approach to draw a class diagram before writing the code. It doesn’t have to be precise, rather make it simple, and implementable.

As we can see from the diagram above that, we need three different classes to get the job done. And also the implementation becomes easier, reduces our future thoughts when we design a UML diagram of a solution.

It’s relatively an easier topic. But I realized that, it would be fine if I make a note on how I would process a list of data where multiple data loss might occur. Let’s see the example below.

If we want to understand the true essence of dynamic programming, we should consider the simple example of fibonacci series. Using the conventional algorithm the time complexity of the solution is O(2^n).

def fibonacci(n): i, a, b = 1, 0, 1 while(i<=n): a, b = b, a+b i += 1 return b

But using the dynamic programming we can reduce the function call, as well as the time complexity to O(n).

class Main { int[] f = new int[100]; public int fibonacci(int n) { f[0] = f[1] = 1; for(int i=2;i<=n;i++) { f[i] = f[i-1] + f[i-2]; } return f[n]; } }

Greedy approach gives a feasible solution to a problem where multiple solutions are possible. Greedy approach doesn’t give you the optimal solution, but if the feasible solution is optimal, then we can accept that solution.

Let’s consider the coin changing problem, which could be solved using greedy algorithm. Assume that, we are given a set of coins, and a sum to be changed. Then we can do so,

import math def greedy(coins, target): remaining = 0 count = 0 i = 0 times = 0 while(True): if(target is 0): break else: times = math.floor(target/coins[i]) remaining = target - (coins[i]*times) target = remaining print(coins[i]," needs: ", times," times.") i += 1 count += times return count

coins = [10,5,2,1] print("\ntotal coins needed: ", greedy(coins, 31))

10 needs: 3 times. 5 needs: 0 times. 2 needs: 0 times. 1 needs: 1 times. total coins needed: 4

As we can see that, we need total 4 coins to make 31 from the list of [10,5,2,1] coins. In this case it is an optimal solution, but if we are given [4,3,1] for 6 then the total number of coins we need would be 3 using the greedy algorithm. Unfortunately, the optimal solution would be 2. So we see that greedy algorithm has some drawbacks, but it could be optimized using the dynamic programming.

The termination of a software is considered to be the failure of the project. A software should be maintained, and optimized over the period of time. This is how a software turns into a technology, and that is where the success of a software belongs. In order to make a software project successful we need to follow the certain steps.

The figure drawn above shows the essential steps of the software development in my eyes.

Further reading: SDLC

Some of the essential searching algorithms.

i) Linear Search ii) Binary Search iii) Interpolation Search iv) Exponential Search v) Ternary Search vi) Hash Table vii) Newton's Method