Mutex vs Semaphore
What are the differences between Mutex vs Semaphore? When to use mutex and when to use semaphore? Concrete understanding of Operating System concepts is required to design/develop smart applications....
View ArticleMemory Layout of C Programs
A typical memory representation of C program consists of following sections. 1. Text segment 2. Initialized data segment 3. Uninitialized data segment 4. Stack 5. Heap A typical memory layout of a...
View ArticleUnderstanding “volatile” qualifier in C
The volatile keyword is intended to prevent the compiler from applying any optimizations on objects that can change in ways that cannot be determined by the compiler. Objects declared as volatile are...
View ArticlePure Functions
A function is called pure function if it always returns the same result for same argument values and it has no side effects like modifying an argument (or global variable) or outputting something. The...
View ArticleScope rules in C
Scope of an identifier is the part of the program where the identifier may directly be accessible. In C, all identifiers are lexically (or statically) scoped. C scope rules can be covered under...
View ArticleAnalysis of Algorithms | Set 1 (Asymptotic Analysis)
Why performance analysis? There are many important things that should be taken care of, like user friendliness, modularity, security, maintainability, etc. Why to worry about performance? The answer to...
View ArticleAnalysis of Algorithms | Set 2 (Worst, Average and Best Cases)
In the previous post, we discussed how Asymptotic analysis overcomes the problems of naive way of analyzing algorithms. In this post, we will take an example of Linear Search and analyze it using...
View ArticleReservoir Sampling
Reservoir sampling is a family of randomized algorithms for randomly choosing k samples from a list of n items, where n is either a very large or unknown number. Typically n is large enough that the...
View ArticleThe Ubiquitous Binary Search | Set 1
We all aware of binary search algorithm. Binary search is easiest difficult algorithm to get it right. I present some interesting problems that I collected on binary search. There were some requests on...
View ArticleStatic and Dynamic Libraries | Set 1
When a C program is compiled, the compiler generates object code. After generating the object code, the compiler also invokes linker. One of the main tasks for linker is to make code of library...
View ArticleNP-Completeness | Set 1 (Introduction)
We have been writing about efficient algorithms to solve complex problems, like shortest path, Euler graph, minimum spanning tree, etc. Those were all success stories of algorithm designers. In this...
View ArticleAnalysis of Algorithms | Set 3 (Asymptotic Notations)
We have discussed Asymptotic Analysis, and Worst, Average and Best Cases of Algorithms. The main idea of asymptotic analysis is to have a measure of efficiency of algorithms that doesn’t depend on...
View ArticleAnalysis of Algorithms | Set 4 (Analysis of Loops)
We have discussed Asymptotic Analysis, Worst, Average and Best Cases and Asymptotic Notations in previous posts. In this post, analysis of iterative programs with simple examples is discussed. 1)...
View ArticleA Problem in Many Binary Search Implementations
Consider the following C implementation of Binary Search function, is there anything wrong in this? The above looks fine except one subtle thing, the expression “m = (l+r)/2″. It fails for large values...
View ArticleAn interesting time complexity question
What is the time complexity of following function fun()? For i = 1, the inner loop is executed n times. For i = 2, the inner loop is executed approximately n/2 times. For i = 3, the inner loop is...
View ArticleModular multiplicative inverse
Given two integers ‘a’ and ‘m’, find modular multiplicative inverse of ‘a’ under modulo ‘m’. The modular multiplicative inverse is an integer ‘x’ such that. a x ≡ 1 (mod m) The value of x should be in...
View ArticleDesign Patterns | Set 1 (Introduction)
Design pattern is a general reusable solution or template to a commonly occurring problem in software design. The patterns typically show relationships and interactions between classes or objects. The...
View ArticleTime Complexity of Loop with Powers
What is the time complexity of below function? Time complexity of above function can be written as 1k + 2k + 3k + … n1k. Let us try few examples: k=1 Sum = 1 + 2 + 3 ... n = n(n+1)/2 = n2 + n/2 k=2 Sum...
View ArticleTime Complexity where loop variable is incremented by 1, 2, 3, 4 ..
What is the time complexity of below code? The loop variable ‘i’ is incremented by 1, 2, 3, 4, … until i becomes greater than or equal to n. The value of i is x(x+1)/2 after x iterations. So if loop...
View ArticlePriority Inversion : What the heck !
Let us first put ‘priority inversion’ in the context of the Big Picture i.e. where does this come from. In Operating System, one of the important concepts is Task Scheduling. There are several...
View Article