Problem Given the Java cache interface below, write a singleton class that implements the interface so that no warnings are generated without using @SuppressWarnings annotations Solution The question is mainly about two points: Type checking warning must be fixed Singleton design pattern should be implemented here is how I approached the problem… I modified the map private
Introduction Today, I am going to dive into the awesome world of sorting. It reminds me with entry level computer science courses and algorithm design. The goal of this article is to summarize popular sorting algorithms and put it in one place so that it is easy to remember and refer to. My intention is
Problem Given an input text file as in the example below Write a script that prints the output below Solution Each line in the file contains a word and a list of positions at which the word is repeated in the printed output. Here is a python implementation:
Problem Given an input text file with format as in the following example: print the number of sub directory levels that are common to all paths in the file. In this case it is /foo/bar/x so the count is 3 Solution Here is a sample python code to implement that
Introduction One of the – confusing – topics in Algorithm design is the concept of NP completeness. If you search the topic on the internet you will probably find tons of articles and lectures on the subject however in this short article I will summarize it so that it is easy to remember by the
Insertion Sort Welcome to part 8 on loop invariants. Please refer to the first part (introduction) here. Today, we are going to discuss insertion sort algorithm. Let us get started. Problem definition Given an array (A) of (n) numbers. Assume the array starts at position (1). Develop an algorithm to sort the array in increasing
Bubble Sort Hello! This is part 7 in a series of short articles on loop invariants. You can refer to the first part (introduction) here. Today, we are going to discuss bubble sort algorithm in the context of loop invariants. Problem definition Given an array (A) of (n) numbers. Develop an algorithm to sort the
Linear Search Hello! This is part 6 in a series of short articles on loop invariants. You can refer to the first part (introduction) here. Today, we are going to develop an algorithm for linear search using loop invariants. Let us get started. Problem definition Given an array (A) containing (n) numbers and given some
Integer Division This is the 5th part in a series of short articles on loop invariants. You can refer to the first part (introduction) here. Our example for today is a little bit harder than the previous examples. We are going to develop an algorithm to do integer division. Let us see how can we
Factorial Hello everyone! This is the 4th part in a series of short articles on loop invariants. You can refer to the first part (introduction) here. We are going to continue talking about loop invariants. Let us see how to find an appropriate loop invariant to calculate the factorial of a positive integer. Problem definition