Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Hi,

Hi,

I have array d[i][j] that stores values. By using map, i am able to get the number of times the values occur.

For example:

Values How many times occur

3.6667 =2

3.52 =3

3.51 =1

Is there a way if I want to find the occurances in range. For example,

how many times i get the value between and including 3.5 and 3.6 . Is there any other function or method to use...

For example, for the example above,

3.5 &&3.6 is 4 times

Hi,

I have array d[i][j] that stores values. By using map, i am able to get the number of times the values occur.

For example:

Values How many times occur

3.6667 =2

3.52 =3

3.51 =1

Is there a way if I want to find the occurances in range. For example,

how many times i get the value between and including 3.5 and 3.6 . Is there any other function or method to use...

For example, for the example above,

3.5 &&3.6 is 4 times

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

if it is the incremnent a counter for the number in the range

you can improve on this if you already have a map with the number of times each appears

in this case you can go thru the keys in your map (the values) and if in the range you inclement your counter by the number of times that value appeared.

let me know if u have any questions :)

on the both end values of the interval and then you have the number of values that fall in between

do a simple recursive traversal of the tree to find the starting value (call it S)

from the right child of S do an inroder traversal to obtain the data in ascending order

count the nodes you visit, until you reach the end of interval

this will eliminate the sort overhead (in a 1 dimensional array) but would also cause another overhead (traversal).

my first comment is good where you insert values only once but get range occurances many times

it costs only two binarysearch that is O(Log n)

then you only need to subtract the start index from the end index.

I didn't think so, as jasbir has been around for some time AFAICR

For example,if the program is runned five times(iterations=3 and years=2), this could be the output.

score[year][iteration]

Iterations 1 Iteratons 2 Iterations 3

Years 1 2.666667 2.66667 2.66667

Years 2 3.2224 3.2221 3.4

so what i need to do is to find the percentage for the range based on years

For example, for year 1 , how many times got value between 2.6 to 2.7

For example, for year 2,how many times, got value between 3.2 to 3.3, 3.3 to 3.4

I just realized that the map below takes all the value in and does not consider it based on years..Is there a way to make the map think in years.

I am posting a new question for map first coz without getting the map correct..i cant sorrt..PLEASE look AT THIS..THANKS A LOT.

Map <Double,Integer> map=new HashMap<Double,Integer>();

for(int i=0;years+1;i++)

{

for(int j=0;j<iterations;j++){

Integer val=map.get(score[i][j]);

if(val==null)

map.put(score[i][j],1);

else

{

int newVal=val+1;

map.put(score[i][j],newVal

}

}

}

pls help ..thanks

Now my map is like this:

ArrayList<Map<Double,Integ

for(int i=0;i<years+1;i++)

{

Map<Double,Integer> map = new HashMap<Double,Integer>();

maps.add(map);

for(int j=0;j<iterations;j++)

{

Integer val = map.get(score[i][j]);

if(val==null)

map.put(score[i][j],1);

else

{

int newVal=val+1;

map.put(score[i][j],newVal

}

}

}

How to use sorted map here ..Pls help..

You would need:

Map<Double,Integer> map = new TreeMap<Double,Integer>();

Map<BigDecimal, Integer> map = new TreeMap<BigDecimal, Integer>();

map.put(BigDecimal.valueOf

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialactually, now i have my map's scores based on years..

meaning map 1 would refer to scores for year 1,

map 2 would refer to scores for year 2..

however, for the scores in each map, i need find range

for example: between 3.2 and 3.3 ,how many times...

for (int i=0;i<years+1;i++)

{

Map<BigDecimal,Integer>map

maps.add(map);

for(int j=0;j<iterations;j++)

{

Integer val = map.get(score[i][j]);

int newVal=val+1;

map.put(BigDecimal.valueOf

}

}

I get error: cannot find symbol Floor

exception in thread "AWT-eventqueque-1" java lang.ClassCastException :java.math.BigDecimal..

pls help...thanks

i hope , my explaination is ok...

actually, i am finding range values which is needs to be based on years which is kept in the arraylist

maps 1 keeps the scores in map for year 1

maps 2 keeps the scores in map for year 2

my problem is that for each maps, i need to find the range..For example,

maps 1 for year 1

the scores stored in map would be { 2.66667=2 , 2.6661=1, 3.5=1}

so, now i find range of sorted map like this

2.6=3 (something like if value between 2.6 and 2.7, you add)

3.5=1

Data

score[year][iteration]

Iterations 1 Iteratons 2 Iterations 3 Iteration 4

Years 1 2.666667 2.6661 2.66667 3.5

Years 2 3.2224 3.2221 3.4

Are you putting in instances of BigDecimal? If you aren't and treating the Map as if it does have them, then you're going to get that kind of exception, although since you're using >= 1.5, you should ensure that you genericize the Map so this error is obvious at *compile* time

>>actually, i am finding range values which is needs to be based on years which is kept in the arraylist

Yes. What i'm suggesting needs to be done in a loop

nope this is not homework..actually, this was done earlier in array and was being used ..then, found out that it cant be done in array..it is the same graph project i am working on..

i am very sorry for troubling a lot..but thanks for helping a lot..

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21807189.html

Java

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.