Product of Complex Numbers using three Multiplication Operation
Given four integers a, b, c, and d which represents two complex numbers of the form (a + bi) and (c + di), the task is to find the product of the given complex numbers using only three multiplication operations.
Input: a = 2, b = 3, c = 4 and d = 5
Output: -7 + 22i
Product is given by:
(2 + 3i)*(4 + 5i) = 2*4 + 4*3i + 2*5i + 3*5*(-1)
= 8 – 15 + (12 + 10)i
= -7 + 22i
Input: a = 3, b = 7, c = 6 and d = 2
Output: 4 + 48i
Naive Approach: The naive approach is to directly multiply given two complex numbers as:
=> (a + bi)*(c + di)
=> a(c + di) + b*i(c + di)
=> a*c + ad*i + b*c*i + b*d*i*i
=> (a*c – b*d) + (a*d + b*c)*i
The above operations would required four multiplication to find the product of two complex number.
Efficient Approach: The above approach required four multiplication to find the product. It can be reduced to three multiplication as:
Multiplication of two Complex Numbers is as follows:
(a + bi)*(c + di) = a*c – b*d + (a*d + b*c)i
Simplify real part:
real part = a*c – b*d
Let prod1 = a*c and prod2 = b*d.
Thus, real part = prod1 – prod2
Simplify the imaginary part as follows:
imaginary part = a*d + b*c
Adding and subtracting a*c and b*d in the above imaginar part we have,
imaginary part = a*c – a*c + a*d + b*c + b*d – b*d,
On rearranging the terms we get,
=> a*b + b*c + a*d + b*d – a*c – b*d
=> (a + b)*c + (a + b)*d – a*c – b*d
=> (a + b)*(c + d) – a*c – b*d
Let prod3 = (a + b)*(c + d)
Then the imaginary part is given by prod3 – (prod1 + prod2).
Thus, we need to find the value of prod1 = a * c, prod2 = b * d, and prod3 = ( a + b ) * ( c + d ).
So, our final answer will be:
Real Part = prod1 – prod2
Imaginary Part = prod3 – (prod1 + prod2)
Below is the implementation of the above approach:
-7 + 22i
Time Complexity: O(1)
Auxiliary Space: O(1)