The array-algorithms tag has no wiki summary.
1
vote
4answers
43 views
Difference between shuffling algorithms
Let's say we're to write a method to produce a shuffled deck of cards. Now to make it very simple, disregard the suits and so we have 52 cards.
One algorithm would be:
Populate an array of 52 ...
0
votes
1answer
30 views
Need to find lowest differences between first line of an array and the rest ones
Well, I've been given a number of pairs of elements (s,h), where s sends an h element on the s-th row of a 2d array.It is not necessary that each line has the same amount of elements, only known that ...
-1
votes
1answer
123 views
implementing Brute Force in c++
I have a problem that deals with optimization of a game that includes 2 players.
So we have an undirected connected graph with a number of edges and some vertices.
Each player has to remove edges and ...
-4
votes
1answer
39 views
Minimizing the partition [closed]
U have been given an array A which have n elements
1<=n<=100000
each A[i] can have the maximum value of w .
1<=w<=100000
Partition A into k subsets such that each subset sum should ...
-1
votes
2answers
122 views
Algorithm for finding a sum within an array? [closed]
Say you have some array with elements that you know are all positive, and smaller than a number N.
Can someone give me a general, high-level description of an algorithm to find out whether there is ...
2
votes
2answers
86 views
Associative array lookup cost
Consider two lookup functions:
simple={1,3,5}
function isX(id)
for _,v in ipairs(simple) do
if v==id then return true end
end
return false
end
assoc={[1]=true,[3]=true,[5]=true}
...
0
votes
1answer
163 views
Trouble with my algorithm to solve a boggle board
so I'm relatively new to Java (I'm taking AP java at my school currently) and I am trying to develop a recursive algorithm to solve an n*n board and I feel I am very close but not quite there yet.
I ...
1
vote
1answer
210 views
How can I bubble sort this?
In this program I just wanted to bubble sort the ArrayList words. So far I used the Collections.sort and it has placed all the lines in the text file alphabetically. However, I want to implement a ...
0
votes
1answer
73 views
Meaning of S[3i]S[3i + 1]S[3i + 2] [closed]
I have trouble understanding the following:
We have the String ABRACADABRA. We divide this into groups as example:
S is divided into the group:
S0 = <S[3i]S[3i + 1]S[3i + 2] for i = ...
2
votes
1answer
314 views
Longest Contiguous Subarray with Average Greater than or Equal to k
Consider an array of N integers. Find the longest contiguous subarray so that the average of its elements is greater (or equal) than a given number k.
The obvious answer has O(n^2) complexity. Can we ...
1
vote
1answer
102 views
sublists of a list with possitive sum
I'm trying to find the sublist of a list (with at least one positive integer) with the following 2 properties
1. the sum of it's elements is positive
2. it has the maximum length of all the other sub ...
4
votes
2answers
111 views
Algorithm to find non-dominated pairs
Given are pairs of integers (a1,b1),...,(an,bn). Pair i is "dominated" by pair j if ai < aj and bi < bj. What is an algorithm to quickly determine the list of pairs that are not dominated by any ...
9
votes
2answers
1k views
Given an array [a1b2c3d4] convert to [abcd1234] [closed]
Constraints :
O(1) space
O(n) Time
It is not a homework question just a interesting question I came across.
Here are some solutions I could think of but nothing that does it in given ...
0
votes
2answers
107 views
Convert a row and column sorted 2-D array to a sorted 1-D array
Given an 2-D Array of n*n elements:
all rows are sorted
all columns are sorted
For example:
1 5 7
2 6 8
3 9 10
convert it to a 1-D sorted array. Is there a solution better than O(nlog(n)).
2
votes
4answers
338 views
How to find the permutation of a sort in Java
I want to sort an array and find the index of each element in the sorted order.
So for instance if I run this on the array:
[3,2,4]
I'd get:
[1,0,2]
Is there an easy way to do this in Java?