Posts

Showing posts with the label Algorithm

Max Heap Create and Sorting

Image
Hi, this is Shubham Mishra. I write blogs on algorithms and new technologies. In today's blog, we will going to cover the max heap topic. Now before actually looking the code lets understand the max heap tree. A complete binary tree is a tree in which every levels are completely filled except the lowest one, which is filled from the left. And A max heap is a complete binary tree and the root node always have the max value of the tree, hence the name is max heap. Now with this max heap tree is have one more important property, the value of a node is always greater than or equal to the all chindren nodes. Confused, let me explain with a diagram: As can be seen in above tree, this is complete binary tree, since nodes are entered in such as way that all of the in between nodes are have 2 childrens. And any node's value is any time greater than all the children nodes. Take 6, it is greater than all the child nodes (5 -> 4, 2 And 3 -> 1). Similar to this 5 is greater than...

Study of Algorithm and its analysis

Image
In the world of computer science, every on heard of the term Algorithm. Now it's the time to know in-depth about it and also study to how to start writing an algorithm before actual coding. Writing an algorithm for a solution is 80% of the coding done. An algorithm is named for the ninth century Persian mathematician al-Khowarizmi, that is it is a set of rules used to compute some calculations. For any computer problems after understanding the problem, writing an algorithm is the second step. Once you have the algorithm ready now you can write code in any programming language you want. The famous algorithm, Euclid's algorithm for getting the greatest common divisor of two numbers is been written in ancient Greek.  Algorithm:  "An algorithm is defined as a set of unambiguous rules written in a specific sequence to produce expected output for predefined inputs." Let's come out of this bookies definition, and understand the steps for solving a problem in the ...

Naive String Matching Algorithm

Image
Hi, this is Shubham Mishra. I write blogs on algorithms and new technologies. In today's blog, we will be going to see a traditional way for string matching. For this blog, I have taken the reference of Analysis of Algorithm by A.A.Putambekar's book. String matching generally used in text processing. Normally text processing is done in the compilation of a program. The string matching is a vital part in software designing and system designing. String matching means finding one or more generally all the occurrences of a string in a text. These occurrences are called Pattern . Let, Text T is denoted by T0.....T(n-1) and pattern P is denoted by P0....P(m-1). String Matching Algorithm For String matching scenario we will be discussing many algorithms in upcoming blogs such as, The naive method (This blog) Rabin-Karp algorithm Finite automaton for string matching Knuth - Morris - Pratt method Naive String Matching Algorithm Naiv...

Radix Sort the best sorting algorithm

Image
Hi, this is Shubham Mishra, I write blogs on algorithms and on the technologies. Today we will be going to deals with one of the best algorithm for sorting of an array. Before doing this algorithm I recommend you to visit other algorithms such as  Merge Sort , so as to compare Radix sort algorithm with them. Radix sort is my favourite for its time complexity. Don't panic about time complexity for Radix, I will cover that later in this post. Radix sort is also known as bucket sort. The radix sort is to sort decimal numbers, where the radix or base is 10, which need 10 buckets. This all buckets are numbered from 0 to 9. The most important part of the algorithm is that the number of iterations required is equal to the number of digits in the largest number in the list. For example, refer to the table below, Radix Sort Algorithm Before moving on to the algorithm and code I would like to explain you in general terms that how radix sort works.  The number o...

Introduction to Recursion (A way to write an function in Computer Science world)

Image
Hi, I am Shubham Mishra a computer science engineer, passionate about writing technical posts. While writing posts for algorithms such as  Merge Sort  and others, I thought that I should write a post on Recursion, which is a way to write a function where a step is repeated for multiple times. But before reading this I would like you to read my previous post  Data Structure and Types . Now start with the term Recursion. When a function is defined in terms of itself that is it is called even inside its own body then it is called a Recursive function. Don't be confused just scroll down and see below picture for a better understanding. Suppose you want to calculate the factorial of '4'. The factorial is calculated by multiplying the terms itself with all the numbers below to it till one. It is as '4 * 3 * 2 * 1 * 1'. The '1' extra is the Factorial(0) = 1. The factorial function will work as it will return '1' if the factorial is called for zero (...

Merge Sort: What is Merge sort and Its complexity

Image
Hi, this is Shubham Mishra, today we will be going to discuss on a topic which deals with the sorting of an array. In my algorithm series, this is the first post but previously I also have written other posts such as  Python game develop using Pygames  and  Data structure and data structure types . The today's topic is Merge sort algorithm. In the series of the algorithm, we will discuss all the possible kind of algorithms and also its complexity with the condition for the use of such algorithms. Let's discuss Merge sort algorithm, its time complexity. Merge sort is a very efficient sorting algorithm with the near-optimal number of comparisons. It is best described using a Recursive algorithm approach . The working of merge sorting algorithm is to splitting and merging of two sorted lists into one sorted list. The recursive algorithm used for merge sort comes under the category of divide and conquer technique. An array of n elements is split around its c...

Data Structure and its Types in Computer Science

Image
Hello dear reader, I am Shubham Mishra writing this post to illustrate Data Structure and Data Structure types. For writing this post I have taken the reference from the book 'Data Structure - by Dilip Kumar Sultania'. What is Data: Data is a collection of numbers, alphabets and symbols which represent some information. A computer usually takes input as one form of data and returns output in another form of data. Basically, the data primarily divided into two types, Atomic Data : This data are the non-decomposable entity. These are basically an integer, characters that cannot be further divided. Composite data : It is a sum-up of individual atomic data. It can further be divided into atomic data. Data Structure : Algorithm As shown in the above diagram, 'Date of Birth' is a composite data which can further be divided into three atomic data. Now, let's begin with the actual discussion of today's topic 'Data Types' or 'Data Structures...