Anyway, here goes:
The linear search is a lot less efficient than the binary search because the linear search has to go through every single element with in the array to search for the one thing you are looking for. It takes a lot more memory space (luckily Java has a garbage collector) and understandably, takes a lot less time. The binary search, on the other hand, finds the median of the set of numbers, cuts the list in half, and checks whether the value you are looking for is above or below middle value. If it is below, it takes the lower half and if it is above, it takes the upper half. It repeats this process until it finds the value (or doesn't find the value). This is much more efficient because you don't have to look at every single value - only the top, the bottom, and the average of top and bottom. It is just so much more efficient than the linear search, in which it goes back and forth - possibly even finding two of the same values, and returning either the lower one or the upper one depending on how it was coded. The binary search cuts the search in half compared to the linear search which looks through every single one individually. In this case, it is totally understandable that the binary search is ½ the time.
There are many different types of sorting algorithms, and this becomes very useful in binary searches, because binary searches require the list to be sorted before searching - otherwise the median value would be inaccurate. Paragraph to come later.
Also, here is an updated version of how the JTable will be organized (colour to think about later).
| Name | Place | Location | Date | Cost | Type | Other Info |
This will be the setup, and so all of the entries will have to be put into a 2 dimensional array, that has these types of angles - and that is how they will look. When I read to and from the file, they must all be in this order, otherwise nothing is going to work. I think I'm going to convert everything into a 2 dimensional array, and then do most of the JTable stuff like sorting and whatnot tomorrow. I'm not so concerned about the like illegal values or whatnot, but the creation of the table is a little intimidating.
So first off, I would have to create an array that contains all the table headings that will be in the JTable, and they have to be declared in the class so that the whatever listener thing can listen to it and find out what is going on.
Then, I would have to change the readFile and writeFile methods - not in like reading and writing, but where to store the data, because now the new array cannot be of type Location...that would not be useful.
I've gooogled a few stuff on like JTables and such, and it's a bit irritating cause they don't mention what happens when you have a one dimensional array of objects, whether a table would work as well. I don't think I'm going to take my changes on it. I'll leave all the one dimension array values in like...documentation, so I can can always go back to it if I need it.
No comments:
Post a Comment