Data structure interview questions (Swift) I

Covered Questions: 1. Given an array A[] and a number x, check for pair in A[] with sum as x 2. Program to count the occurrences of each…

Data structure interview questions (Swift) Part-I

Covered Questions:
1. Given an array A[] and a number x, check for pair in A[] with sum as x
2. Program to count the occurrences of each character
3. Program to check whether a number exists in form of 4n+1 or not
4. Write Code to Determine if Two Trees are Identical

1. Given an array A[] and a number x, check for pair in A[] with sum as x

Time Complexity: O(nlogn)
Auxiliary Space: O(1)

2. Program to count the occurrences of each character

Time Complexity: O(n)
Auxiliary Space: O(n)

3. Program to check whether a number exists in form of 4n+1 or not

Time Complexity: O(logn)
Auxiliary Space: O(1)

4. Write Code to Determine if two binary trees are Identical

Time Complexity: O(m) where m < n, m & n are tree elements
Auxiliary Space: O(1)

To create a tree node and tree, Below code will work:

For checking two tree is identical or not