General Discussions

algorithms

# Pointer and Types – C

This note covers various types of pointers to be aware of and a few notations used with pointers. Types of Pointers Pointer: Pointer is a variable which holds the address of another variable NULL Pointer: A null pointer has a value reserved for indicating that the pointer does not refer to a valid object. It… Continue reading Pointer and Types – C

General Discussions

# Printing 1 to N in Binary Using Queue

Originally posted on PH Bytes:
One of the popular interview question asked on queue data structure: Write a program to print the numbers from 1 to N in Binary Representation using QUEUE data structure. Example: Input: N = 3 Output: 1, 10, 11 Input: N= 5 Output: 1, 10, 11, 100, 101 Code will follow…

algorithms

# Fibonacci Versions – C

This post covers the three implementation(Iterative, Recursive and Dynamic) version of Fibonacci series. The correctness of the code covers for integer range numbers only. 1. Iterative Version   2. Recursive Version   3. Dynamic Programming Version

algorithms

# %d and %i format specifiers – C

What is a format specifier: It basically tells us what type of data we are dealing with, while reading(scanf()) or writing (printf()). It is a sequence starting with a % sign. While reading integers, we can go for %d or %i. %d assumes base 10 and %i auto detects it. To be more specific, %d specifies… Continue reading %d and %i format specifiers – C

algorithms

# Union-Find Data Structure: Intro

A disjoint-set data structure, also called a union–find data structure keeps track of a set of elements partitioned into a number of disjoint (non-overlapping) subsets. With this setting we define the following operations: Find: Determine which subset a particular element is in. This can be used for determining if two elements are in the same… Continue reading Union-Find Data Structure: Intro

algorithms

# Sum of Multiples of N – C

Let us say we want to compute the sum of all the multiples of 3, amidst the range 1 to 999. The brute force approach would be to run a loop from 1 to 999 and if the (loop_variable % 3) is 0, we add it to a variable which maintains the sum. We could… Continue reading Sum of Multiples of N – C

algorithms

# Setting Max and Min values for Integer – C

There are cases in programs where we will have to set variables with maximum (say like infinity) or with minimum values. We generally tend to see the input and initialize with a higher value like 9999 for maximum and -1 for minimum. Well, we all know that’s not right. What’s right is using the ‘limits.h’… Continue reading Setting Max and Min values for Integer – C

algorithms

# memset in C

memset is used to initialize a block a memory with desired value. The prototype of the function is: void *memset(void *ptr, int x, size_t n) where – ptr is the starting address of memory to be filled (note that the type of pointer is void) – x is the value to be initialized with – n… Continue reading memset in C

algorithms

# Asymptotic Notations

Let’s start with the basic question, ‘What are Asymptotic Notations?’ Asymptotic notations are mathematical notations that describe the limiting behaviour of a function when the argument tends towards a particular value (or may be infinity). The phrase ‘limiting behaviour’ here is important. The notations describe the restriction and boundaries towards a function. Let’s stay for… Continue reading Asymptotic Notations