Min heap implementation - C++

I have discussed the priority queue and implementations of queue, vector. Now, we are gonna discuss about min heap, also known as a priority queue. So, what’s this data structure? It has 4 main methods: size() - returns the number of the elements front() - return the current minimum element pop() - deletes the current minimum element push(element) - insert new element to the heap How do we implement this?...

October 13, 2023 · 4 min · 839 words · Me

Dynamic array implementation - C++

We discussed queue implementation in here and about vector here. Like a queue we will now discuss vector implementation in this post. A vector is a simple data structures similar to an array, but its size is dynamic. The main feature is that we can access any element in vector in O(1) time. Vector has three main methods size() - returns the number of elements. push(element) - inserts a new element at the back of the vector....

October 4, 2023 · 6 min · 1088 words · Me

Queue implementation - C++

We talked about queue in this post. Now, I’m gonna explain how to implement this data structure. What we need is a basic understanding of pointer and memory. Queue has 4 main methods size() - returns the number of the elements top() - returns the first element of the queue pop() - deletes the first element push(element) - insert new element back of the queue How hard can it be?...

September 24, 2023 · 4 min · 729 words · Me

Memory Management - PART 1

Memory and pointer We learned how to declare variables array, vector etc. But how do these things works under the hood? Lets start with memory. All the are stored in memory. For example if we declare array or vector, c++ will allocate new memory, which we can then use directly. If we no longer need these variable, they will be cleaned up automatically, like variables declared within a function. But, how do we know where they are stored?...

September 2, 2023 · 3 min · 476 words · Me

Prime numbers

Prime number A prime number is a natural number with exactly 2 distinct divisors. For example 2, 3, 5, 7 and so on. Given number N, How do we determine if it is prime? One approach is to iterate through the numbers [1, N] and count how many of them divide N. Can we check it faster than this? If prime number has only 2 divisors, that means it s divisible by only 1 and itself....

June 20, 2023 · 3 min · 457 words · Me

Binary search

Binary search algorithms are everywhere, and for good reason. They embody a simple yet powerful idea. In general, algorithms are named with purpose. Let’s take a closer look at this algorithm through an example problem. Problem We are given an ascending sequence of length N and Q requests. Each request consists of a number, and the answer indicates whether that number exists in the sequence. 1 <= N, Q <= 10^5, abs(a[i]) <= 10^9....

May 11, 2023 · 3 min · 525 words · Me

Step by Step Programming - C

How to learn programming? In my experience, I have familiarized myself with the basics of programming and understand the fundamental concepts, then I start solve competitive programming problems. To begin with, it’s recommended to focus on learning the fundamentals of C and C++ programming languages, as they provide a solid foundation. As I mentioned earlier, problem-solving skills are paramount. Platforms like Hackerrank, Codeforces, and Codechef are excellent resources to enhance your problem-solving abilities....

February 2, 2023 · 11 min · 2310 words · Me