Class 2 Homework

Matrices

Check given matrix is magic square or not

                    
Input : n = 3
  2   7   6
  9   5   1
  4   3   8
Output : Magic matrix
Explanation:In matrix sum of each
row and each column and diagonals sum is 
same = 15.

Input : n = 3
  1   2   3 
  4   5   6
  7   8   9
Output : Not a Magic Matrix
Explanation:In matrix sum of each
row and each column and diagonals sum is
not same.
                    
                

Solution

Linked lists

Write a function (in any language) that takes a linked list and returns the length

Binary search tree

Given a binary search tree and a key, write a function (in any language) that returns true if the key is in the tree.

Example of a node for a binary search tree

                    
struct TreeNode {
    int key;
    int value;
    struct TreeNode *left;
    struct TreeNode *right;
};