Friend Function Explained With Simple Example

A Friend function is a function defined outside the class, but it has access to all private and protected members of the class. To declare a friend function, it’s prototype must be declared inside the class, preceding it with keyword “friend”. For eg:

class Demo
{
    private:
        int m;
        int y;

    public:
        friend int sum (Demo d);
        void print_val ();
        Demo (int m, int y);
};
(more…)
Friend Function Explained With Simple Example Read More

Inline Function Explained With Simple Example

Inline function is an important addition in C++. These inline functions mostly are not called and is expanded in line at the invocation place. Hence, these functions are called inline functions. To define a function as inline function, precede function definition with “inline” keyword. These functions are almost similar to Macros in C.
For eg:

inline int sum (int a, int b);
(more…)
Inline Function Explained With Simple Example Read More

Replace every character by character that is N positions down the alphabet of the String

Given a string ‘s’ and a number ‘n’, write a function that returns a string with each character in s replaced with another character that is ‘n’ positions down the alphabet.
For example:

  • If n is 1, A is replaced with B, B is replaced with C and so on.
  • If n is 2, A is replaced with C, B is replaced with D and so on.
  • If n is 3, X is replaced with A, Y is replaced with B and so on.
(more…)
Replace every character by character that is N positions down the alphabet of the String Read More

AVL Tree Deletion Of Node Explained With Simple Example

An AVL (Adelson-Velskii and Landis) Tree is a self balancing Binary Search Tree which has the following properties.

For any node “A”, the height of the left subtree of “A” and height of the right subtree of “A” differ by 1 at max.

In case of Binary search Trees worst case search complexity is O(n) in cases when the Binary Search Tree is skewed. In AVL tree, since heights of left and right subtree are balanced, hence search complexity improves to O(log n). Before going ahead have a look into AVL Tree Basics.

(more…)
AVL Tree Deletion Of Node Explained With Simple Example Read More

AVL Tree Insertion Of Node Explained With Simple Example

An AVL (Adelson-Velskii and Landis) Tree is a self balancing Binary Search Tree which has the following properties.

For any node “A”, the height of the left subtree of “A” and height of the right subtree of “A” differ by 1 at max.

In case of Binary search Trees worst case search complexity is O(n) in cases when the Binary Search Tree is skewed. In AVL tree, since heights of left and right subtree are balanced, hence search complexity improves to O(log n). Before going ahead have a look into AVL Tree Basics.

(more…)
AVL Tree Insertion Of Node Explained With Simple Example Read More

AVL Tree Self Balancing Rotations – Right Left Rotation explained

An AVL (Adelson-Velskii and Landis) Tree is a self balancing Binary Search Tree which has the following properties.

For any node “A”, the height of the left subtree of “A” and height of the right subtree of “A” differ by 1 at max.

In case of Binary search Trees worst case search complexity is O(n) in cases when the Binary Search Tree is skewed. In AVL tree, since heights of left and right subtree are balanced, hence search complexity improves to O(log n). Before going ahead have a look into AVL Tree Basics.

(more…)
AVL Tree Self Balancing Rotations – Right Left Rotation explained Read More