Largest area in matrix [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've been aksed to write a program that finds the largest area of equal neighbour elements in a rectangular matrix and prints its size. I tried to construct a 2d array with some numbers but I think that I should switch to using a tree or something in order to solve this problem. Chould somebody suggest a possible way of solving it?
For example:
"Hint: use the algorithm Depth-first search or Breadth-first search."

Sounds like a standard maze search problem. I suggest you use recursion to find all the elements which you haven't been to before which have the same number as the one you have found. You can either update the matrix as you go or create a copy to keep track of the cells you have visited. So you don't need a tree or even an additional complex data structure.
use the algorithm Depth-first search or Breadth-first search
These are two types of recursive searches. I suspect you could implement both of these to see how they behave.

Related

hash table with chaining within the table [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have this assignment to complete. (I am new to java). I started to think about it and establish a plan. I am not looking for the answers just a feedback on my approach. I am supposed to enter integers into a hash table using a chaining scheme within the hash table (different from the regular chaining scheme). My idea is to use an arraylist so I can store data + pointer in each slot of the hash table. when a collision occurs, find an empty slot, insert the new integer and set the pointer from the original hashed slot to this new position in the arraylist. This way I am building a sort of linked list within the array. does that make sense? there is a hint about keeping track of the free space with a stack... here I have to say I am not sure how to use the stack in that instance
So prior to java8 hashmap internally will resolve collision using link list similar to your approach which brings the performance from O(1) to O(n) in case collision occurs, since java8 it is being handled via balanced tree which further improves the complexity to O(log n) in case of collision.
Your approach to use list is correct, but it comes to how you implement it.

Better than binary search [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I basically need to have a very fast search for huge numbers (in the 2^128 range). Is there anything out there that gves better performance than binary search, ie. better than O(log n) ?
[edit] The data is sorted and pretty much evenly distributed.
Binary Search works only when the data is sorted. A marginal improvement over binary search is interpolation search. However, the efficiency of Interpolation Search over Binary Search depends on the distribution of your data. If the data set is pretty uniformly distributed, then interpolation search can be favored.
This link may help,
http://blog.imaginea.com/interpolation-search-a-search-algorithm-better-than-binary-search/

Search a object without iterating a collection in java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How to look for a particular object in a large list(java collection) without iterating it. Assume we have a large collection and just need to check whether a object exists or not without iterating.
Ok, Let's step out of the binary world.
Think of a chest full of Lego parts. You want a 2x2 flat black piece.
How would you find it without looking in the chest?
There is no magical to find it, you need to jump into the chest and find the piece grabbing one by one and checking if it's the one you are looking for.
There are ways to speed up the process.
You can Organise (sort your collection) by colour for example and just look in the black pile.
Or you can map (Index your pieces) so you know the position of the piece and can go and retrieve from you know where the piece is.
That is, in a very simplistic way, the same idea for databases and collection.
So, summarizing, no, you can't not just find without looking. Sorry :(

complexity and big oh notation on algorithms [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need som help understanding how this works! how do I go about calculating the complexity of 'Computing the first half of an array of n items' or 'displaying the third element in a linked list' ? I need someone to explain how this works, theses are just examples, so be free to use your own if it helps explaining! thank you.
You should look at how the processing time of the algorithm grows as the size of the input grows. I'll take your two concrete examples:
Computing the first half of an array of n items
We need to process n/2 items. If n doubles, then the processing time should also double. Consequently, this is a linear operation (i.e. O(n)).
displaying the third element in a linked list
We always want to display the third element, so the size of the list doesn't actually matter. If it doubles, we don't care; the processing time is not affected. Consequently, this is a constant-time operation (i.e. O(1)), it doesn't depend on the size of the input.

Fibonacci Series generation using Matrices [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
There's one question posted about Fibonacci Series, which I am much familiar with it. But there are multiple answers and linked questions to it. As I was digging through it with some interest, there's a solution which is linked to here
This algorithm solves the problem by O(log(n)) quite impressive. But I couldn't understand the logic and so called Matrix exponentiation [looked wiki, but unable to relate to it].
So kindly anyone can explain exactly how they achieved with more details and better explanation [if you can explain with code, prefer in Java, much helpful].
Thanks :)
What you need to understand is the algorithm, not the implementation.
The first thing you need to understand is that this algorithm will not give you all the fibonacci numbers, only those with with a n that is a power of 2.
The second thing is that a multiplication of constantly sized matrices of course takes constant ( O(1) ) time.
The trick now is to correctly note that the n'th fibonacci number can be formed by n-times multiplication of the matrix described in your link, which i will call M.
You get the log complexity by now "reordering" the matrix operations from, for example M*(M*(M*M)) to (M*M)*(M*M). With each matrix squaring, you go to M^2n instead of M^n+1.

Categories

Resources