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

Mutex vs Semaphore

$
0
0
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. Our objective is to educate  the reader on these concepts and learn from other expert geeks. As per operating system terminology, the mutex and semaphore are […]

Memory Layout of C Programs

$
0
0
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 running process 1. Text Segment: A text segment , also known as a code segment or simply as text, is one of the […]

Understanding “volatile” qualifier in C

$
0
0
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 omitted from optimization because their values can be changed by code outside the scope of current code at any time. The system always […]

Pure Functions

$
0
0
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 only result of calling a pure function is the return value. Examples of pure functions are strlen(), pow(), sqrt() etc. Examples […]

Scope rules in C

$
0
0
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 following two categories. Global Scope: Can be accessed anywhere in a program. To restrict access to current file only, global variables can […]

Analysis of Algorithms | Set 1 (Asymptotic Analysis)

$
0
0
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 this is simple, we can have all the above things only if we have performance. So performance is like currency through which we can buy all […]

Analysis of Algorithms | Set 2 (Worst, Average and Best Cases)

$
0
0
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 Asymptotic analysis. We can have three cases to analyze an algorithm: 1) Worst Case 2) Average Case 3) Best Case Let us […]

Reservoir Sampling

$
0
0
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 list doesn’t fit into main memory. For example, a list of search queries in Google and Facebook. So we […]

The Ubiquitous Binary Search | Set 1

$
0
0
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 binary search. I request you to honor the code, “I sincerely attempt to solve the problem and ensure there are no corner cases”. After […]

Static and Dynamic Libraries | Set 1

$
0
0
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 functions (eg printf(), scanf(), sqrt(), ..etc) available to your program. A linker can accomplish this task in two ways, by copying […]

NP-Completeness | Set 1 (Introduction)

$
0
0
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 post, failure stories of computer science are discussed. Can all computational problems be solved by a computer? There are computational problems that can not be […]

Analysis of Algorithms | Set 3 (Asymptotic Notations)

$
0
0
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 machine specific constants, and doesn’t require algorithms to be implemented and time taken by programs to be compared. Asymptotic notations are mathematical tools […]

Analysis of Algorithms | Set 4 (Analysis of Loops)

$
0
0

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

$
0
0

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

$
0
0

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

$
0
0

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)

$
0
0

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

Time Complexity where loop variable is incremented by 1, 2, 3, 4 ..

Priority Inversion : What the heck !

$
0
0

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.

Viewing all 339 articles
Browse latest View live


Latest Images