Featured Article

Diagonal Traversal of Binary Tree

Consider lines of slope -1 passing between nodes. Given a Binary Tree, print all diagonal elements in a binary tree belonging to same line. Input : Root of below tree Output : Diagonal Traversal of binary tree : 8 10 14 3 6 7 13 1 4 We strongly recommend you to minimize your browser… Read More »

Featured Article

Adapter Pattern

This pattern is easy to understand as the real world is full of adapters.   For example consider a USB to Ethernet adapter. We need this when we have an Ethernet interface on one end and USB on the other. Since they are incompatible with each other. we use an adapter that converts one to other.… Read More »

Featured Article

Branch and Bound | Set 2 (Implementation of 0/1 Knapsack)

We strongly recommend to refer below post as a prerequisite for this. Branch and Bound | Set 1 (Introduction with 0/1 Knapsack) We discussed different approaches to solve above problem and saw that the Branch and Bound solution is the best suited method when item weights are not integers. In this post implementation of Branch… Read More »

Featured Article

Decorator Pattern | Set 3 (Coding the Design)

We have discussed Pizza design problem and different naive approaches to solve it in set 1. We have also introduced Decorator pattern in Set 2. In this article, design and implementation of decorator pattern for Pizza problem is discussed. It is highly recommended that you try it yourself first. The new class diagram (Click on… Read More »

OpenCV Python Program to blur an image

Note: This post contains codes that cannot be run using an online compiler. Please make sure that you have Python 2.7 and cv2 module installed before trying to run the program on your system. Hi everyone! I read a brilliant work by Aditya Prakash – OpenCV C++ Program to blur an image, so I decided to… Read More »

OpenCV C++ Program to blur an image

The following is the explanation to the C++ code to blur an Image in C++ using the tool OpenCV. Things to know: (1) The code will only compile in Linux environment. (2) Compile command: g++ -w article.cpp -o article `pkg-config –libs opencv` (3) Run command: ./article (4) The image bat.jpg has to be in the… Read More »

Demystifying Machine Learning

Machine Learning”. Now that’s a word that packs a punch! Machine learning is hot stuff these days! And why won’t it be? Almost every “enticing” new development in the field of Computer Science and Software Development in general has something related to machine learning behind the veils. Microsoft’s Cortana – Machine Learning. Object and Face… Read More »

Strategy Pattern | Set 2 (Implementation)

We have discussed a fighter example and introduced Strategy Pattern in set 1. Strategy Pattern | Set 1 (Introduction) In this post, we apply Strategy Pattern to the Fighter Problem and discuss implementation. The first step is to identify the behaviors that may vary across different classes in future and separate them from the rest.… Read More »

Converting Strings to Numbers in C/C++

There are two common methods to convert strings to numbers: Using stringstream class or sscanf() stringstream() : This is an easy way to convert strings of digits into ints, floats or doubles. Following is a sample program using a stringstream to convert string to int. Output: Value of x : 12345 // A stringstream is… Read More »

Amazon Interview Experience | Set 257 (Off-Campus)

I was recently interviewed by Amazon, Bangalore for SDE position. It was an off campus drive in Delhi for TRMS team. Written Test : Q1) Find a peak element. http://www.geeksforgeeks.org/find-a-peak-in-a-given-array/ Q2) Top View of binary tree. http://www.geeksforgeeks.org/print-nodes-top-view-binary-tree/ Q3) Maximum difference between node and its ancestor in Binary Tree. http://www.geeksforgeeks.org/maximum-difference-between-node-and-its-ancestor-in-binary-tree/ Round 1 (F2F): Q1) In a… Read More »

Fifth root of a number

Given a number, print floor of 5’th root of the number. Examples: Input : n = 32 Output : 2 2 raise to power 5 is 32 Input : n = 250 Output : 3 Fifth square root of 250 is between 3 and 4 So floor value is 3. Method 1 (Simple) A simple… Read More »

Strategy Pattern | Set 1 (Introduction)

As always we will learn this pattern by defining a problem and using strategy pattern to solve it. Suppose we are building a game “Street Fighter”. For simplicity assume that a character may have four moves that is kick, punch, roll and jump. Every character has kick and punch moves, but roll and jump are… Read More »

Python Modules

A module is a file containing Python definitions and statements. A module can define functions, classes and variables. A module can also include runnable code. Grouping related code into a module makes the code easier to understand and use. Example:   The import statement We can use any Python source file as a module by… Read More »

Handling Ajax request in Django

Introduction This tutorial explains how to carry out a ajax request in Django web framework. We will create a simple post-liking app as a part of example. Glossary Project Initialization Create models Create views Write urls Carry out request with Jquery AJax. Register models to admin and add some posts.  Implementation: 1. Initiate the Django… Read More »

Laravel

What is Laravel ? Laravel is a web application framework created by Taylor Otwell in 2011 and like all other modern frameworks, it also follows the Model-View-Controller (MVC) architectural pattern. Laravel values Elegance, Simplicity, and Readability and if one talks of building applications with PHP frameworks, Laravel is second to none. Since Laravel is open-source,… Read More »