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.
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.
Some of the common types of Binary Tree are listed below : Full Binary Tree - In a full binary tree, each node has either 0 or 2 children. - Each node is either leaf or has exactly 2 children. Complete Binary Tree - All levels are full except possibly last. - All nodes in the last level are aligned towards the left. Perfect Binary Tree - All nodes have 2 children except leaf. - All leaf nodes are at the same level. Balanced Binary Tree - Very good performance, O(log n) Insertion, Deletion and Search - Every level above the lowest is full - Diff is maximum 1 between left subtree and right subtree Degenerate/Pathological Binary Tree - Each node has one child except leaf Traversal Preorder Node is visited before its left and right subtrees Postorder Node is visited after both subtrees Inorder Visit left subtree, then visit node and finally right subtree Binar...
Comments
Post a Comment