Thursday 12 August 2021

To find the product of every element other than itself without using division operator in O (n) time.

 For Example: Consider the below array 

1

2

3

4

A[0]

A[1]

A[2]

A[3]

To get the product of every element other than itself without using division operator in O (n) time, we use

Product of all array elements except the current element =

Product of all elements below the current index * Product of all elements above the current index

 

So Product of all elements below the current index is

1

1

2

6

A[0]

A[1]

A[2]

A[3]

 

Product of all elements above the current index is

24

12

4

1

A[0]

A[1]

A[2]

A[3]

 

Product of both would be

24

12

8

6

A[0]

A[1]

A[2]

A[3]

 

 

No comments:

Post a Comment