Tagged Questions
3
votes
2answers
111 views
Optimizing unboxed array operations in Haskell
Consider this simplified code which successively permutes array elements:
import Data.Word
import Data.Bits
import Data.Array.Unboxed
import Data.Array.Base
import Data.Array.ST
test3 :: UArray Int ...
1
vote
1answer
144 views
first non-repeated character in a string in c
Write an efficient function to find the first non-repeated character in a string. For example, the first non-repeated character in "total" is 'o' and the first non-repeated character in "teeter" is ...
0
votes
3answers
108 views
Given an 2D array which is row and column wise sorted. What is the efficient way to search for an element?
For example, given a 2D array (a matrix)
{{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}}
What are the solutions to find a number? say 6.
Here's the code I tried using Binary search method -
(code ...
4
votes
2answers
101 views
Counting letters program. Notation and optimisation help
I am writing a program in C running on UNIX which counts the number of each letters in a input text file. For a file like this:
The cat sat on the green mat
The output would be like this:
The ...
1
vote
1answer
116 views
C arrays and loops optimization
I am writing a program for learning purposes that takes an input of a file structured similarly to:
13,22,13,14,31,22, 3, 1,12,10
11, 4,23, 7, 5, 1, 9,33,11,10
40,19,17,23, 2,43,35,21, 4,34
...
4
votes
1answer
136 views
Optimizing Python / Numpy Code
So I'm implementing a version of the mean shift image processing algorithm for color segmentation in python/numpy.
I've written a pure numpy version of the actual mean shifting per pixel (which I ...
3
votes
1answer
129 views
C# Array Mutator Methods to mimic JavaScript Array Mutator Methods
Between .NET's built-in collection libraries and LINQ extension methods, I never have to use arrays. An unfortunate consequence of this is that I am probably less competent in working with this very ...
4
votes
2answers
2k views
Reading a line from a text file and splitting its contents
I have this kind of file structure
MALE:FooBar:32
FEMALE:BarFoo:23
Where I would want to identify the gender and age of person, <Gender>:<Name>:<age>
try{
BufferedReader in = ...
1
vote
3answers
290 views
Optimize Array.indexOf
How can I optimize checking a value in recursion before operating on it? I'm using Array.indexOf (this is Javascript)
var nums = [], lengths = [];
function findNumLength(n) {
//preliminary check ...
1
vote
2answers
720 views
Javascript querystring to object conversion
The below code converts the window.location.search querystring into a JavaScript object. In particular, if a key occurs more than once the resulting value in the object will be an array. Please feel ...
4
votes
1answer
246 views
Merging two array of classes
I have this function that should merge two array of classes when id of array1 is equal to id of array2.
For simplicity I converted one array into an ArrayList so I can remove the occurrence merged ...
1
vote
1answer
90 views
Remove identical array items [closed]
I have the following piece of code...
public function setEmailAddresses() {
$this->matches = array();
$this->matchRegex = '/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/';
...
3
votes
2answers
937 views
Optimizing a Deal Or No Deal-style game in Java
could this code be more Efficient?
The Game Class
import java.util.List;
import java.util.Arrays;
import java.util.Collections;
public class Game {
private Case[] cases = new Case[26];
...
2
votes
1answer
347 views
Can anyone check my code?
Can anyone check this code of mine I want to improve it . give me suggestion or tips and tricks to make this code of mine more efficient
Here's my code, I want you guys to give me advices and tips ...