array « algorithm « Java Collection Q&A

Home
Java Collection Q&A
1.algorithm
2.array
3.Array Byte
4.Array Char
5.Array Convert
6.Array Dimension
7.Array Integer
8.Array Object
9.Array String
10.ArrayList
11.collection
12.comparator
13.Development
14.Garbage Collection
15.Generic
16.hash
17.HashMap
18.HashTable
19.iterator
20.LinkedList
21.List
22.Map
23.queue
24.Set
25.Sort
26.tree
Java Collection Q&A » algorithm » array 

1. Sparse matrices / arrays in Java    stackoverflow.com

I'm working on a project, written in Java, which requires that I build a very large 2-D sparse array. Very sparse, if that makes a difference. Anyway: the most ...

2. Ordering coordinates problem    stackoverflow.com

Have been scatching my head about this - and I reckon it's simple but my geometry/algebra is pretty rubbish, and I can't remember how to do this stuff from my school ...

3. Java: Max/min value in an array?    stackoverflow.com

It's trivial to write a function to determine the min/max value in an array, such as:

/**
 * 
 * @param chars
 * @return the max value in the array of chars
 ...

4. Given a string s and an array of smaller strings, T, how to design a method to search s for each small string in T?    stackoverflow.com

Given a string s and an array of smaller strings, T, design a method to search s for each small string in T. Thanks.

5. Undirected (Multi) Graph (Hierholzers Algorithm)    stackoverflow.com

I am very stuck with the looping structure for my graph to work out Eulers tour. This is the graph I am drawing, remember it's undirected, so a journey from N1 to ...

6. How to find the last element of array in binary search    stackoverflow.com

In binary Search algorithm, the upper-bound element is array.length-1, then how can I find the last element of an array? If the lower-bound and upper-bound for element of an array of ...

7. Transformation of Linear Column-Major Array Data to Row-Major    stackoverflow.com

I have Fortran-based 3D column-major order array flattened into linear memory. What formula/algorithm can I use map it back to a Java 3D row-major order array? For example,

|1, 2, 3| |10, ...

8. Counting viable sublist lengths from an array    stackoverflow.com

This is for a genetic algorithm fitness function, so it is important I can do this as efficiently as possible, as it will be repeated over and over. Lets say there is ...

9. Rotate array clockwise    stackoverflow.com

I have a two dimensional array that I need to rotate 90 degrees clockwise, however I keep getting arrayindexoutofbounds...

public int[][] rorateArray(int[][] arr){

        //first change ...

10. Delete item from array in Java    stackoverflow.com

What is wrong here? I want delete an item from an array, but it shows me

error ArrayIndexOutBound exception
public class delete {

    public static void main(String[]args) ...

11. 2D Array values frequency    stackoverflow.com

If I have a 2D array that is arranged as follows :

  String X[][] = new String [][] {{"127.0.0.9", "60", "75000","UDP", "Good"},
         ...

12. Algorithm for data alignment of float arrays in Java    stackoverflow.com

I have two float arrays representing y values in a line chart. Now I want to align these two charts. Are there any existing algorithms for alignment of the two arrays? A ...

13. Select i th smallest element from an array    stackoverflow.com

I have a divide and conquer method to find the i th smallest element from an array. Here is the code:

public class rand_select{
    public static int Rand_partition(int a[], ...

14. Array Recursion    stackoverflow.com

I've got an assignment I can't figure out, any pointers will be much appreciated, it goes like so: There's a series of light bulbs represented as an array of true/false, there's a ...

15. question on reverse array    stackoverflow.com

we know algorithm how reverse array of n integers

 for (int i=0;i<n/2;i++){
  swap(a[i],a[n-1-i]):
}
is this method better according the speed of algorithm or not because swap ...

16. Removing duplicate character from array    stackoverflow.com

While reading one book named Cracking the coding interview by Gayle Laakmann, i came across this question Design an algorithm and write code to remove the duplicate characters in a string without ...

17. Finding the longest down sequence in a Java array    stackoverflow.com

Given this array

int [] myArray = {5,-11,2,3,14,5,-14,2};
I must be able to return 3 because the longest down sequence is 14,5,-14. What's the fastest way to do this? PS: Down sequence is a ...

18. Efficient array elements un-ordering in Java    stackoverflow.com

I just wanted to know what is the best way to un-order the elements in an ordered array in Java, Thanks

19. Find the longest decreasing sequence    stackoverflow.com

I am trying to find the longest sequence of decreasing numbers in an array. I am not sure what I am doing incorrectly in the following code.

public static int getDecSeq(double[] ...

20. Finding index of array where min value occurs    stackoverflow.com

This one is making my head spin. Just when I think I got it, I realize something's not right. I have to use recursion for this assignment. Any hints?

/**
 * ...

21. Enumerate all k-partitions of 1d array with N elements?    stackoverflow.com

This seems like a simple request, but google is not my friend because "partition" scores a bunch of hits in database and filesystem space. I need to enumerate all partitions of an ...

22. example about array in java    stackoverflow.com

assume that i have an array int [] arr={1,2,4,5,7} and also have number 6 so i need the result to be 01100 that means that 2+4=6 in the array so the ...

23. best way to check the indices around a certain index in a 2d array    stackoverflow.com

I'm working on this bacteria life game thing I have to make. Basically I have a 2d string array let's say 20 by 20. What would be the best way to check ...

24. Detect non-null reference in an array    stackoverflow.com

I just asked a similar question, but then I realized I actually need something else. Since that question already has two answers, I do not want to edit my question. ...

25. Find combinations in arrays    stackoverflow.com

I have an 2D-array like this in java

transmission communication tv television  
approach     memorycode  
methodact
I need to get all combinations like:
{transmission,approach,methodact},{transmission,memorycode,methodact},{communication,approach,methodact},...
Can someone provide an example that ...

26. Java prefixAverages/array help    stackoverflow.com

I am attempting to translate two separate algorithms into Java code in order to test them; the first algorithm (PrefixAverages1) is:

For i = 0 to n-1
    Let s ...

27. deleting an object from an array    stackoverflow.com

I have an array of objects of my custom class and i want to delete a random object(chosen by some criteria). how do i do this and keep the array ordered? ...

28. Most efficient method to box/unbox multidimensional primitive arrays    stackoverflow.com

Is this most efficient method to box/unbox multidimensional primitive arrays in Java without using an external library?

private Float[][] toFloatArray(float[][] values)
{
   Float[][] objArray = new Float[values.length][values[0].length];

   for ...

29. Sliding an array in java - algorithm based    stackoverflow.com

I'm writing a program in java where I need to slide the elements of the array and it should be performing as less as possible number of operations as it's inside ...

30. Search an array    stackoverflow.com

I have an array int x[] and a number. I like to do search on the array such that x[i] + x[i+1] = number. What is the most efficient and fastest way ...

31. searching in n 2-dimensional arrays    stackoverflow.com

Help with how to implement on n-2dimenssional-array. To be more specific: If I have 6 tables and I am putting these into a 2-dimensional array.I will provide a value say 10 like ...

32. Checking conditions on array elements    stackoverflow.com

I have an array of numbers nums[] and target such that it satisfies the below condition {{nums[],target}

 1> {{8, 2, 2, 1},12} --> returns true      ...

33. Java firstPosition Algorithm    stackoverflow.com

int firstPosition(int x, int [] a) {

    int lower = 0;
    int upper = a.length;

    while (lower != upper) {
   ...

34. Getting an ArrayIndexOutOfBoundsException when working with markov chains    stackoverflow.com

I have an array to store a set of coordinates for painting a piece of line. So here are some example coordinates

double[][] plotMatrix = {{10,20},{55,80},
       ...

35. Create an array of array in java    stackoverflow.com

I need to create an array of array with Strings in java... For example, I read a file that contain for each column a sport and a player name..like: The goal at the ...

36. Help understanding java algorithm using arraycopy to remove duplicate elements    stackoverflow.com

Im having difficulty understanding how the array is being copied in this algorithm. Im am fine with the code till i get to line 12 shown below. This code was from ...

37. Comparing arrays in Java    stackoverflow.com

I had 2 integer arrays, one original and one modified w.r.t the original array. Elements can be added or removed from the original to convert it to the modified. My problem ...

38. Traverse String Clockwise using 1D Array only    stackoverflow.com

I have implemented a function TraverseStringClockwise which takes a comma separated string of integers, and a width and a height, and returns a new string by walking in a clockwise order ...

39. Finding non-empty grid cell in 2-dimensional array    stackoverflow.com

I have a 2-dimensional integer array (say 1000 by 1000), let's call it matrix. Each cell in this matrix has a X- and Y-coordinate (each from 0 to 999 in this ...

40. help with hasDuplicate array method without using java.util? and is O(n) achievable?     stackoverflow.com

Hi guys I had an interview today which involved this very question and in order to widen my algorithmic knowledge im trying to see if there are any better suggestions. I was ...

41. Completely stumped on a Java problem    stackoverflow.com

Please Note: I am not "looking for teh codez" - just ideas for algorithms to solve this problem. This IS a homework assignment. I thought I was in the home stretch, about ...

42. Efficient Algorithm/code to print a 2D Array into Spiral Format    stackoverflow.com

Please write a efficient code/algorithm in java to print a two dimensional array [m][n] in a spiral format ? For ex. if the array provided by the user is : 1 2 ...

43. Search algorithm - Java    stackoverflow.com

I am finding it a little bit difficult to get a search algorithm to work properly in Java. Basically, the program has an array initialized. The user is supposed ...

44. How to return maximum sub array in kadane's algorithm?    stackoverflow.com

  public class Kadane {

  double maxSubarray(double[] a) {

    double max_so_far = 0;
    double max_ending_here = 0;

    for(int i = ...

45. Java: Contiguous region in a multi-dimensional array, used to implement a Latin Square    stackoverflow.com

I am writing a program that reads in a potential Latin Square and tells whether or not it is a valid latin square or not. Now I am ...

46. What constitutes 'array access' in the context of algorithms?    stackoverflow.com

Below is an LSD Radix sort implementation in Java from a textbook to sort an array of strings where each string contains exactly W characters. I want to count the number of ...

47. Shifting Elements in an Array    stackoverflow.com

I have an array of objects, and I am trying to pull one element to the top and shift the rest down by one. Assume I have an array of size 10, ...

48. Comparing arrays that have same elements in different order    stackoverflow.com

I wrote below code to compare to arrays that have same elements but in diff order.

 Integer arr1[] = {1,4,6,7,2};
 Integer arr2[] = {1,2,7,4,6};
For example, Above arrays are equal as they ...

49. algorithm to find max and min in a increasing,decreasing, increasing and decreasing array    stackoverflow.com

Given an array , in which either the values are only increasing or only decreasing or increasing and then decreasing, How to find the max and min value of such and ...

50. Given an array arr[], find the maximum value of j – i such that arr[j] > arr[i]    stackoverflow.com

Given an unsorted array arr[], find the maximum value of j – i such that arr[j] > arr[i]. Finding this in O(n2) is possible using 2 for loops, but can we do ...

51. Getting Access To The State Of A Node In NxN 2D Array    stackoverflow.com

I'm implementing NxN puzzle in 2D array in Java. I have the following classes:

public class Node {

    //private members
    private int boardSize;
   ...

52. Need Some Clarification About Successors(Neighbours) In NxN Puzzel in 2D Array    stackoverflow.com

I am struggling a little bit when it comes to generating the successors of a node in puzzle. Let me start with 1D array puzzle int[]={0,1,3,4,2,5,7,8,6} as the start node for the ...

53. Binary search in 2 dimensional array with duplicates Java    stackoverflow.com

Design an algorithm , FindElement(a,p), where "a" is two-dimensional square array of positive integers with duplicates and each row of integers is in non - decreasing order: a[i][0] ? ...

54. Algorithm for operating on 2d array with radius    stackoverflow.com

trying to think of the best way to handle this problem with my 2d game. I want to be able to specify a coordinate pair (x,y) and a radius value. Given ...

55. algorithm question about array    coderanch.com

no it is nothing to do with 2d arrays actually. right now I have this long string and I want to divide into an array but not as one word each but like 4-5 groups of words long. so if I do this: String myArray[] = mystring.split(" "); since it splits every gap, it gives me an array full of words, ...

56. array algorithm    coderanch.com

Originally posted by Victoria Preston: I have been given a snipit of code and I am suppose to find a better algorithm for determining the max vale. My problem would be I do not see anything wrong. Any help would be appricated. It looks fine... You only access the members of the array once and only once. There doesn't seem to ...

57. Algorithm for finding max and min in an array.    java-forums.org

Also, in case you need some help on how euclidean GCD works, here is a bit of a tip: Given two integers, a and b, if r is the remainder of a divided by b, then the common divisor of a and b is also a divisor of r. It is straightforward enough to develop this recursively.

59. Multiple return arrays --algorithm    forums.oracle.com

60. algorithm to find that duplicate entry in Array    forums.oracle.com

Please help me to solve this algorithm. There is an array of length 1000 which has 1000 integers. All integers are in the sequence like 1,2,3, about 999 integers and one more which is duplicate of any one existing. Which is the algorithm to find that duplicate entry. The array is not in the sorted order regards Sandeep

61. Algorithm for checking the content of 2 dimensionial arrays? (Tic Tac Toe.)    forums.oracle.com

Put in debugging statements to see where it's going wrong. Either that or use a debugger. Trying to debug your own code by pure visual inspection seldom works, and debugging others' code by visual inspection is even less likely to be successful. Pourquoi est-ce que les noms sont en Francais, mais les commentes sont en Anglais?

62. Need help with an array checking algorithm    forums.oracle.com

The board contains values from 0 to 3 (corresponding to 4 different colours). For example ( correct winning states of the board looks as follows:) Notice that it's not necessary to have the same number of values for each number (0-3) i.e. you could have five threes, four twos, four ones, 3 zeros etc

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.