0
What is the code for finding the number of times the minimum value appears in an array x
6 ответов
+ 3
DHANANJAY PATEL arf, yes: but you need to not forgot to reset counter to 0/1 when a new minimum is encountered ^^
+ 2
DHANANJAY PATEL run together?
did you mean only one loop?
yes, it could be done in only one loop, but you must count every items occurence... as you don't know what's minimum value...
that's seems more reasonable to do this by two independant loops, at least for beginner (and also for memory footprint): iterating twice an array doesn't provide a big time difference, unless you're working with wide data set (and if so, memory footprint as well as data structure creation/population should at best produce quite equivalent efficiency ^^
+ 2
visph
Yes in single loop
It's not complex logic
Start with first value as minimum and set occurrence counter to 1
When ever you encounter new minimum reset counter to 1 and set new minimum
If minimum is equal to current minimum increment minimum counter by 1
Please don't mind it two loops are not mandatory
Thanks for explaining that it is not needed when you are processing lesser data.
DHANANJAY
+ 1
you must iterate once the array to find the mnimum value, then iterate another once again to count how many minimum is encountered ;)
+ 1
According to me both can run together.
While finding minimum value counter can be reset to one(1) each time minimum new minimum value encounter and if value is same as minimum value counter can be incremented by one(1).
DHANANJAY
+ 1
When processing array for minimum it needs to be reset to 1 as the new minima is found it is counted as 1(first) minima.
DHANANJAY