Quantcast
Channel: Articles– GeeksforGeeks
Browsing all 339 articles
Browse latest View live

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 Article


Memory 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 Article


Understanding “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 Article

Pure 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 Article

Scope 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 Article


Analysis 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 Article

Analysis 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 Article

Reservoir 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 Article


The 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 Article


Static 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 Article

NP-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 Article

Analysis 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 Article

Analysis 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 Article


A 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 Article

An 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 Article


Modular 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 Article

Design 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 Article


Time 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 Article

Time 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 Article

Priority 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
Browsing all 339 articles
Browse latest View live