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