Skip to content

How do you find the average of numbers in a list? This can be for any language, I just want to know the ways. #1671

Answered by Emojees
Kuefo asked this question in Q&A
Discussion options

You must be logged in to vote

Iterative Approach – O(n) Time and O(1) Space
The approach to solve this problem is to traverse the whole array and find the maximum among them.

Recursive Approach – O(n) Time and O(n) Space
The idea is similar to the iterative approach. Here the traversal of the array is done recursively instead of an iterative loop.

Using Library Methods – O(n) Time and O(1) Space
Most of the languages have a relevant max() type in-built function to find the maximum element, such as std::max_element in C++. We can use this function to directly find the maximum element.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Kuefo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants