Mutex vs Semaphore
Memory Layout of C Programs
Understanding “volatile” qualifier in C
Pure Functions
Scope rules in C
Analysis of Algorithms | Set 1 (Asymptotic Analysis)
Analysis of Algorithms | Set 2 (Worst, Average and Best Cases)
Reservoir Sampling
The Ubiquitous Binary Search | Set 1
Static and Dynamic Libraries | Set 1
NP-Completeness | Set 1 (Introduction)
Analysis of Algorithms | Set 3 (Asymptotic Notations)
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) O(1): Time complexity of a function (or set of statements) is considered as O(1) if it doesn’t contain loop, recursion and call to any other non-constant […]
The post Analysis of Algorithms | Set 4 (Analysis of Loops) appeared first on GeeksforGeeks.
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 of l and r. Specifically, it fails if the sum of low and high is greater than the maximum positive int value […]
The post A Problem in Many Binary Search Implementations appeared first on GeeksforGeeks.
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 executed approximately n/3 times. For i = 4, the inner loop is executed approximately n/4 […]
The post An interesting time complexity question appeared first on GeeksforGeeks.
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 {0, 1, 2, … m-1}, i.e., in the ring of integer modulo m. The multiplicative inverse of… Read More »
The post Modular multiplicative inverse appeared first on GeeksforGeeks.
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 idea is to speed up the development process by providing tested, proven development paradigm. Goal: • Understand the problem and matching it with some pattern.… Read More »
The post Design Patterns | Set 1 (Introduction) appeared first on GeeksforGeeks.
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 = 12 + 22 + 32 +… Read More »
The post Time Complexity of Loop with Powers appeared first on GeeksforGeeks.
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 runs x times, then x(x+1)/2 Read More »
The post Time Complexity where loop variable is incremented by 1, 2, 3, 4 .. appeared first on GeeksforGeeks.
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 Scheduling methods such as First Come First Serve, Round Robin, Priority based scheduling etc. Each scheduling method has its pros and cons.… Read More »
The post Priority Inversion : What the heck ! appeared first on GeeksforGeeks.