A Binary Heap is a complete binary tree, which satisfies either the min-heap property or the max-heap property . Min-Heap property - Root is element with minimum value. - Value at each node is greater than or equal to the value at its parent node. Max-Heap property - Root is element with maximum value. - Value at each node is less than or equal to the value at its parent node. Binary Heap is partially ordered. The ordering amongst elements at the same level doesn't matter. It must satisfy only the requirements of being a binary heap. Binary Heaps can be stored in arrays as they are complete binary trees. Some applications of binary heaps include : -Priority Queues -Order Statistics -> Kth largest element, merge K sorted arrays, ... Binary Heap can be implemented using arrays. In an array starting from index 0, to access elements corresponding to a node with index n : Current Node -> n Parent of Current Node -> (n-1)/2 Left Chi...
I n-Place Algorithms are required to solve those problems which have limited memory constraints. You are not allowed to use extra memory and hence all operations need to be performed on the original data structures themselves. Usually, the algorithms should use O(1), constant memory. You are allowed to declare variables but not complete data structures. For example, you are given an array [1,2,2,4] and you need to delete all values which are equal to 2. One approach could be by checking each element of the array. If it is 2 then skip otherwise store the value in a new array and at the end of the loop[ when traversed every element of array ], return the new array. But this approach is not In-Place as it requires O(n) memory [ Worst case when no element of given value in array ]. For an In-Place algorithm we would need to delete the elements with value in the original array and then return the original array as the answer to the problem.
When you create a variable, you reserve some space in memory. Different data types take up different amount of space. Some of the fundamental data types in C++ are : source : https://www.tutorialspoint.com/cplusplus/cpp_data_types.htm Calculation for range of int : 1 int contains 4 bytes and 1 byte contains 8 bits So, 1 int contains = 4x8 = 32 bits n bits can have 2^n patterns So, 32 bits have 2^32 = 4294967296, which is the range of unsigned int. Size of data types can also vary by machine.
Comments
Post a Comment