mark cortez

Greenhorn
+ Follow
since Mar 29, 2015
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by mark cortez

mark cortez wrote:I am working on an assignment and the first part for me is to sort the arrays of Comparables. Then I am trying to sort the comparable[][] in ascending order by sub array, so the shortest sub array is first. There may be an easy way to do this but i did it the way i could figure out. I ended creating an int[] that contains the index locations of the sub arrays. The actual values in the intdex[] are not in order but correspond to the index locations in the Comparable[][]. I am simply trying move the sub array bases in the index[] location to a location in a sorted Comparable[][]. The problem is the last array swap. The values of the index locations are correct but the value os the sub array is wrong. I am not sure what is going on.
I left my working comments in, they may help to understand what I want to do and the see problem. Somewhere I am writing the value.




Main method









I figure it out. I needed to create a tempComp[] to store the values in then copy that to the correct location. I think I was overrate the compbarable[][] when I did tempComp[i] = collections2[indexArray[j]];.


Sorry about the formatting eclipse is auto-formatting on me.
8 years ago
I am working on an assignment and the first part for me is to sort the arrays of Comparables. Then I am trying to sort the comparable[][] in ascending order by sub array, so the shortest sub array is first. There may be an easy way to do this but i did it the way i could figure out. I ended creating an int[] that contains the index locations of the sub arrays. The actual values in the intdex[] are not in order but correspond to the index locations in the Comparable[][]. I am simply trying move the sub array bases in the index[] location to a location in a sorted Comparable[][]. The problem is the last array swap. The values of the index locations are correct but the value os the sub array is wrong. I am not sure what is going on.
I left my working comments in, they may help to understand what I want to do and the see problem. Somewhere I am writing the value.




Main method







8 years ago
Ares you tying to make a 2d array?
8 years ago
Is there a practical way to organize a multi dimensional array by the length of the arrays contained within?
I have
I would like them rearranged by collections[i].length.
I understand how to sort the content of the arrays but it would be helpful if I could get them in desc order first.
8 years ago
I have some sample code from a tutorial I am doing. Is there a simple way to open it all? I can not import it as a project since Eclipse says there is no project to be found.
The folders I have are:


Each of the folders in the src folder contain 3 classes all of which i can open but i can not run the main. I tried to make the example above look like a directory tree it is not actually code

Campbell Ritchie wrote:I looked up quadratic probing and found this.


np,
I am assuming after the first collision you rest the function back to k+1squared. I was not able to find anything that said how it functions after it place the item. I can only assume that means that it starts right back at k+1 squared.
8 years ago

Simon Roberts wrote:I think your question is misplaced (i.e. in the wrong forum.) This is, I believe, a question about (a college classwork assignment on the topic of) "Algorithms". That's not the same as "using the Java class called HashMap", and for sure not "Beginning Java" in any case

Meanwhile, I find the question intriguing and worthwhile, and realize I need to brush up on some long forgotten stuff that, as other commentators have observed, regular day to day programmers tend not to worry about!


I think this is correct
8 years ago

Campbell Ritchie wrote:Right. Stop writing hashcodes in decimal. Write them in hexadecimal.



I was given the hashcodes, I computed the modulo.

Campbell Ritchie wrote: If you have a 16‑element array, the result of that little formula is the same as the rightmost hex digit in the hashcode, after rehashing. You can see that easily if you write in hexadecimal.
Also, you not will reach the default load factor after 9 entries. The default size for a hash map is 16 and the default load factor is 75%, so using (13, 0.75f) will give you exactly the same as the default, and you reach the load factor at 12 entries



The professors instructions stated that it is an " initial array size of 13". Also the threshold is to be calculated on the number of items present and not the indexes that are filled and that the array will only resize when the next item added equals the threshold size. I do not believe the diagram should have 16 indexes even if it the default. As far writing in hexadecimal formatt, we have not covered that.

I am fairly confident in the diagram that illustrates separate chaining hashing but i was not ably to determine was the quadratic probing.
For example:
item one is in index 3
item two is in index 3 therefore it goes in k+1 (3+1) or index 4
If item three goes in index 4 do you compute its new location with k+1 again or k+2 squared.
When I did my problem I started at k+1 for each new collision.
If I am making no sense then I will rethink the problem.
8 years ago

Campbell Ritchie wrote:Stop worrying about the internals of classes. You don't need to know it.




I do, it was the assignment to worry about it.
8 years ago
I have an assignment that involves a hash map that I would like to review.
The HashMap has a load factor of .75
Initial array size of 13
Items are added in the order they appear

The items to be added in this order are:

Item >>Hashcode >> Computed modulus
Patriots >>1342415383 >> 10
Steelers >>700056533 >> 7
Chargers >>330628742 >> 2
Texans >>532139483 >> 5
Packers >>217142585 >> 10
49ers >>2112979549 >> 5
Saints >>207265348 >> 4
Giants >>1631149803 >> 4

I am assuming Since there are 8 items and load factor is .75 the array could have 9 items added before it needs to be resized.
I attached a pdf of the diagrams of the 2 conditions we were suppose to model, Separate Chaining hashing with an linked list and Quadratic probing.
With the Quadratic probing I did not know whether or not each collision starts with k+1 or is the quadratic cumulative?
For example:
item one is in index 3
item two is in index 3 therefore it goes in k+1 (3+1) or index 4
If item three goes in index 4 do you compute its new location with k+1 again or k+2 squared.
When I did my problem I started at k+1 for each new collision.

I was not sure how to get the diagram in the body of the post. hope the attachment works


8 years ago
It seems to work for everyone in the world but me.
Could it be the build path? the one that does not work is set CDC-1.1/Foundation-1.1 and the working one the build path is LavaSE-1.7
Added the system library in the properties box . Now it works.
9 years ago
I am work on an assignment, i needed to add a control loop and wanted to test it before I added it the existing code. I created a new java project and copy/pasted the class over. The new class (TestMain) gave me an error:
- Type mismatch: cannot convert from int to
Comparable
The original class only has a warning stating that comparable is a raw type and should be parametrized.
I am reading that ints can opt be cast as comparable, but I do not understand how it worked the first time.

Original Class that worked



Second class that had the errors
9 years ago

Henry Wong wrote:
Printing out the stack trace would likely help here. Especially, since the exception would also tell you which array index went out of bounds, and by how much.

Henry



I inserted the following

exception handling was only briefly covered so I am not sure if I wrote the try catch block correctly or what I woudl be looking for if I did.

(Bartender cleanup: fixed code tags)
9 years ago
I am working on a class that sorts and matches items in a collection of arrays. In the end, elements common to all 3 arrays should be printed. The idea is that as the first array is compared to the second it stores the matched items in tempArray. When all items are compared the tempArray should overwrite the checked array, and the process continues until all arrays are checked. I have set all the checking in a do loop that should run while the value is <= to the array length. This allows all items in the reference array to be checked. I get an index out of bounds message but not where I woudl expect it. I have tried varying the condition in the do while loop in the match method, but it did not change the result. There may be other issues I have not addressed with solving the algorithm, but this one has me stumped and I am not able to progress.




(Bartender cleanup: added code tags)
9 years ago