Range of IP addresses

Given a lower bound IP address and an upper bound IP address, this Python program writes all the IP addresses within the given range (bounds included) to a text file, which will be created in the same directory where this program resides.

Posted in Programming, Python | Leave a comment

Find the itinerary given a list of tickets

Two methods of solving the problem are provided here. Program is written in Python and takes O(n) time.

Posted in Programming, Python | Leave a comment

K-nearest neighbors: Max-heap implementation

Given one million points in a three dimensional space, this program prints the ‘k’ nearest points to a given point. In this implementation, one million 3D points, a reference point with respect to which k-nearest neighbors are to be found and the ‘k’ value are randomly generated by the program. The algorithm is based on […]

Posted in Programming, Python | Leave a comment

Extract text from XML files

This program is useful when we are focusing on the textual content enclosed between the XML tags. This program does not focus on extracting the any XML tag attributes or values. Sample input .xml file:

Output text extracted from XML above:

Python code:

Posted in Programming, Python | Leave a comment

Maximum sum sub-array – Kadane’s algorithm

This Python program returns the maximum sum of a contiguous sub-array, the start and end index of the sub-array, and the maximum sum of the non-contiguous sub-array. Kadane’s algorithm is implemented here, which is a linear time, O(n) algorithm.

Posted in Programming, Python | Leave a comment

Recursively copy files and sub directories from one directory to another – Python

Posted in Programming, Python | Leave a comment

Binary search on an ordered list – Python

Binary search can be used to efficiently search for an element in a sorted list. This is an example of recursive approach written in Python 2.7. Procedure: Step -1: The program starts by looking at the middle element of the ordered list. If that is the element we are looking for (let’s call it target_element) , the […]

Posted in Programming, Python | Leave a comment

String reversal – Python

Python program to reverse a given string.

Posted in Programming, Python | Leave a comment

Insertion Sort – Python

Insertion sort is a simple sorting algorithm efficient for small datasets and for partially sorted lists. It builds a sorted list (array) of elements. Best case time complexity is linear: O(n) Worst case and average case time complexities are quadratic: O() Following code is in Python2.7

Posted in Programming, Python | Leave a comment

WordNet: Word synonyms

This python script can be used to extract synonyms of a word given it’s part-of-speech from WordNet. Requirement: NLTK is to be installed first  

Posted in Programming, Python | 4 Comments