Skip to main content

Posts

binary search tree

Binary search tree is a tree structure defined by the following rules: (1) for each parent node in the tree , the left child node value will be less than its value and the right child node value will be greater than its value. (2) there can not be any duplicate node. Clearly, creating a binary search tree, and searching a value in binary search tree works pretty much like bisection method; i.e. first we start with the root value, if it is lesser than the root value then we search with the lesser values only and if it greater than the root value, then we check with the greater values only. i.e. the algorithm looks like something below in pseudocode: search(value,node) {       if (node==NULL)      {         print(value not found )      }      elseif(value>node->data)      {           search(value,node->right)       }  ...

Review of machine learning by Andrew ng

Recently I have started to take machine learning course by Andrew ng. In this post, I will note down the non-trivial things in this course which do not come up in other courses. Course structure: First of all, it is clear in the course structure that this course intends you to know your basics well. The structure of the course includes the first week to know what the definition of machine learning is, and what is a linear regression in one variable.  Here I have encountered definition of machine learning by Tom mitchell from CMU: A well posed learning problem: A computer is said to learn from experience E with respect to a task T and some performance measure P, if its performance on T, as measured by P, improves with experience T. Week 1 is not interesting if you have taken a stat course, know what machine learning is some what but want to know the details only. So I attempted the quiz, and went to week 2 straight. There are actually two quizzes on week 1, one is o...

For those wanna-be statisticians

Introduction: Today, I found a question on Reddit asking that what do you have to read to be a statistician. I started to write an answer and immediately understood that it is going to be a good answer for those who want to have a certain checklist to complete a self-teaching journey. In any self-teaching journey, this is one of the problems, that you do not know where to stop and what to read exactly unless you get your checklist straight. So here is the answer and from this you can get your checklist correctly. For statistics, make sure you have a good probability background i.e. you understand random variables, expectations, variances, pdf, cdf , moment generating functions, techniques of solving probability questions, convergences etc basics of probability. Also, you will need to have a good linear algebra background as much of the statistics will need matrices and vector spaces. Then, once you have that, you can balance by taking MOOCs and read the topics taught in t...

non-linear sorting

(1) Heap sort: A heap is a complete binary tree. A complete binary tree means a tree which has all the nodes present before it enters the next layer. A heap is used in sorting process, by means of recursive rebuilding of the heap again and again and thus sorting the numbers. A heap is called max heap if in any node, the child nodes are less than or equal to the node. Similarly a min heap is also defined. As a heap is complete, we use array to store the heap rather than any dynamic or complex data structure. In this case, we store the child node values of a node stored at i, at 2*i+1, 2*i+2. In this case, we first build the heap once. Then we heapify it again and again replacing the root element each time, therefore, as the root is the highest element, so, we get smaller and smaller heaps and finish the sorting in finite many steps. Below I have written a program for heap sort which works for integer values and assumes the user will provide correct inputs only. #include <std...

Monk and prisoner of azkaban (application of stack data structure)

As mysterious it may sound, this is a problem in Hacker-earth practice problems under data structure criteria. The problem statement is as below: The problem is given an array  A  having  N  integers, for each i(1≤i≤N), find x+y, where  x  is the largest number less than  i  such that A[x]>A[i] and  y  is the smallest number greater than  i  such that A[y]>A[i]. If there is no x<i such that A[x]>A[i], then take x=−1. Similarly, if there is no y>i such that A[y]>A[i], then take y=−1. Input Format: First line consists of a single integer denoting  N . Second line consists of  N  space separated integers denoting the array  A . Output Format: Print  N  space separated integers, denoting x+y for each i(1≤i≤N) Constraints: 1≤N≤10⁶ 1≤A[i]≤10¹⁸ This problem was set by vaibhab jamini and was tested by prateek garg. It also appeared on a hacker-earth challenge named ...

A introduction to knapsack problem

Knapsack problem is a very well known problem. The reason of my interest in this problem is that as it may sound a computer science problem, it actually arises from different scenarios as economics, educations especially education technology , asset portfolio and many other applied fields too. In this post, I intend to get to the details of this problem, both theoretical and practical codes and applications. So sit tight and read on. The first scenario of the problem: Imagine a burglar entering a house. The burglar, like any human being, has brought a definite sized bag and can carry up to a certain weight only. This burglar is allowed to steal anything, but each thing has two characters, weight and volume. Now, from this, there can be three problems. (1) The items are binary in sense of stealing. i.e. each item can either be stolen or not. All items are present in 1 piece only. This is called 0–1 knapsack problem. (2) The items are present in finite number. The burg...

Shapiro-wilk test(python use included)

Introduction We will talk about shapiro-wilk, kruskal-wallis, Mann-whitney, wilcoxon rank test and some other tests in this and other continuing posts.These tests are crucial in establishing different assumptions about samples, tests and modelings. Let's start this series with this post describing shapiro wilk test. Shapiro wilk test: The first brick in buildings of statistics is samples and assumptions about them. When basic statistics courses are taught, we assume normality in a majority of things and later on going into details we drop this assumption from time to time and then we face number of difficulties. Now, this test in hand,   shapiro wilk test is to test the sample for normality . Basically the test was developed by S.S.Shapiro and M.B. Wilk in a 1965 paper published in biometrica.  Here is a link for the paper,(it may not open if you or your institute does not have a j-stor subscription). Description of the test: The test runs by producing a test...

Trees | introduction post | set 1

Trees are important data structures. In this post, we will explore basic code structures of C to advanced C codes and operations. So flex your muscles and let's climb tree. basic constructions: In the following code, I define basic structure of tree using typedef and struct. The driver program creates a tree with two nodes. Please read the program below and watch: #include <stdio.h> #include <stdlib.h> //without this calloc can not be used typedef struct node //tree structure definition { int data; struct branch *left; struct branch *right; }branch; // here we have set it as branch branch *createnode(int value) //createnode is the function to create a node of the tree and return it {  branch *stick; stick=(branch *)calloc(1,sizeof(branch)); stick->data=value; stick->left=NULL; stick->right=NULL; return stick; } //driver program int main(void) {     branch *root;     root= createnode(2);    ...

sorting,merge,insertion and bubble sort(with C programming code provided)

Sorting Sorting means arranging a set of data in the same order. In our daily life,we can see so many  applications using the data in sorted order as telephone directory,merit,list,roll number etc.So , sorting is nothing but storage of data in sorted order(it can be in ascending or descending order). Some Sorting techniques: Bubble sort Selection sort Insertion sort Merge sort Quick sort Heap sort Radix sort Shell sort Bucket Sort Counting sort The main component in any sorting is the key comparison because most of the time we need to  compare the key with elements in a list.The number of comparisons are more,then time for executing  the program is also more. Let ‘n’ be the input size of an array. If n increases,then time for execution also increases,So, execution  time will be varying with different volumes of data. The efficiency of ...