Tagged Questions

The tag has no wiki summary.

learn more… | top users | synonyms

-2
votes
0answers
35 views

How to change every 2nd and every 3rd element in an array? [on hold]

Here is my dilemma, I have this code: var fibs = [1, 2]; for (i = 0; i < (window.innerWidth / 50); i++) { if (fibs.length < 15) { var n = fibs[i] + fibs[i + 1]; ...
-2
votes
0answers
32 views

C Programming Array Copying [closed]

I have the code as: mid = 3; for(i=0;i<9;i++){ if(i == 9-mid) num[i] = mid; else num[i] = 0; printf("%d", num[i]); } which gives the result of "000000300". What ...
0
votes
1answer
77 views

Big O notation allocate array of N element

In Big O notation, allocate an array of N element is defined by O(1) or O(n) ? For example in C#, if I allocate an array like this : int[] a = new int[10] When I display this array, I have : ...
0
votes
0answers
13 views

Returning the contents of a byte Array Function C# [migrated]

I'm trying to get better at coding and more specifically, getting in to the habit of using functions to do things rather than have everything in "Main". I can't seem to find an answer which I can get ...
0
votes
1answer
23 views

String splits to create arrays

Creating an array of strings for configuration or verification purposes can get long and ugly in code. For example: arrayOfStrings = ['one','two','three','four'] Often to reduce the characters and ...
0
votes
2answers
49 views

memory management of multi-dimensional array

could you please show me an example how to compute the location of an element in a multi-dimensional array. It is illustrated in Robert Sebesta's book Concept of Programming Languages that location ...
1
vote
1answer
62 views

How to do “image shifting” faster?

I have a grayscale matrix (implemented as a simple array) to be shown on a display: line 1: | a | b | c | line 2: | d | e | f | a-f are grayscale values. This pattern has to be shifted by a ...
1
vote
2answers
611 views

2D linked list vs. multidimensional array/vector

I hope that programmers is the correct stack exchange for this, as it is quite a concept based question. I'm working on a data structure in C++ that is a represents data in 3D space. The x-y plane is ...
36
votes
2answers
4k views

How do I move away from the “for-loop” school of thought?

This is a rather conceptual question, but I was hoping I could get some good advice on this. A lot of the programming I do is with (NumPy) arrays; I often have to match items in two or more arrays ...
-2
votes
2answers
141 views

Estimation of space is required to store 275305224 of 5x5 MagicSquares? [closed]

Here are some examples of 5x5 Magic Squares found by the Magic Square Generator by Marcel Roos: Magic squares 5x5 Sum must be: 65 Solution: 1 1 2 13 24 25 3 23 17 6 16 20 21 11 8 ...
0
votes
3answers
174 views

Why is the complexity of fetching a value from an array be O(1)?

How come the complexity of fetching a value from an array by it's index is O(1)? I thought the algorithm has to go through all the indexes, find the correct index, and then know what value to return. ...
1
vote
2answers
236 views

Why a hashtable? Why not just a non-hashed associative array?

I've been learning about using a hashtable to efficiently check for items in a list without looping through the whole thing, but there's one thing that I don't get: Why hashed keys? It seems like: ...
0
votes
1answer
138 views

Why is first column of list called 0th in so many languages? [duplicate]

If you want first element of list or array you reference it as 0 in many languages (like C or Clojure). Is there are some really good reasons why the programming languages was design this way? In ...
1
vote
1answer
75 views

What is the best approach to storing a multi-dimensional array with unknown bounds?

I'm trying to store content scraped from several lyric and chord websites into separate variables into either a multi-dimensional array, or into separate string arrays, but I've been stuck trying some ...
0
votes
1answer
87 views

Design Pattern : Static Array/List in Class Object

I'm a CS alumni, but we didn't learn much by the way of OOP, or Design Patterns. I've heard the phrase C with iostreams and thought it fitting. Anyway that's besides the point. I am just curious about ...
4
votes
4answers
458 views

Why can't C arrays have 0 length?

The C11 standard says the arrays, both sized and variable length "shall have a value greater than zero." What is the justification for not allowing a length of 0? Especially for variable length ...
1
vote
2answers
376 views

A vector of pointers to different derived classes of the same base class

I am writing a game in C++ which has different enemy types. I have defined a base Enemy class and I also have derived classes enemy1, enemy2 etc. Now for updating these enemies in each iteration of ...
1
vote
5answers
165 views

What defines the dimensionality of an array?

I know that when we speak about an array having 1, 2, or 4 dimensions, we mean arrays like this: 1: [0] 2: [0,0] 3: [0,0,0] 4: [0,0,0,0] ... Is the first 'axis' of an array the only thing that ...
29
votes
11answers
7k views

How does the “Fourth Dimension” work with arrays?

Abstract: So, as I understand it (although I have a very limited understanding), there are three dimensions that we (usually) work with physically: The 1st would be represented by a line. The 2nd ...
2
votes
1answer
139 views

Improving the running time of Breadth First Search and Adjacency List creation

We are given an array of integers where all elements are between 0-9. have to start from the 1st position and reach end in minimum no of moves such that we can from an index i move 1 position back and ...
3
votes
2answers
269 views

Data structure for grid with negative indeces

Sorry if this is an insultingly obvious concept, but it's something I haven't done before and I've been unable to find any material discussing the best way to approach it. I'm wondering what's the ...
1
vote
2answers
172 views

How to construct a cubie representation of a rubik's cube, given an array

Just to get this out of the way, I have seen this, and it is not what I'm looking for. So, let's say you are programming a Rubik's Cube. (I know, very unoriginal, but bored programmers have to do ...
5
votes
4answers
591 views

Why do arrays in Java not override equals()?

I was working with a HashSet the other day, which has this written in the spec: [add()] adds the specified element e to this set if this set contains no element e2 such that (e==null ? e2==null : ...
2
votes
1answer
239 views

Why does Java support brackets behind variables and even behind method signatures? [closed]

Java allows this: class X{ int i,j[]; // j is an array, i is not } and even worse, it allows this: class X{ int foo(String bar)[][][] // foo actually returns int[][][] { return null; } ...
0
votes
0answers
54 views

Search substring using suffix array (and LCP)

I'm searching for a best way to improve suffix array run time using LCP. My text (about 2 500 000 chars) seems like: 0ricco0eric0america0polo0.... My thoughs: SA=suffixArray char=firstChar(input) s ...
5
votes
1answer
164 views

At ping, why do we have to do array copying instead of passing on the source array that the client sent to us?

So I have been googling about this OpenSSL heart-bleed thing and somehow sees that it is caused by the heartbeat extension which requires client to ping the server to show its aliveness and it all ...
2
votes
1answer
119 views

Accessing a private array when I have an extension method

I'm trying to make a number of data classes for my C#/XNA game, which would essentially be a wrapper around T[,]: public interface IGrid<T> where T : struct { Point Size { get; } T ...
0
votes
1answer
1k views

Is a PHP array an example of a dynamic data structure?

I did my homework, and it says that dynamic data structures are "data structures that change in size as a program needs it to by allocating and de-allocating memory from the heap". So I was ...
0
votes
1answer
110 views

If a variable containing a function gave the function's return instead of a reference to the function, what would an array of functions return? [closed]

I'm creating a prototype scripting language similar to something like Javascript. In my language, every single reference to a variable is actually a function call (a getter function), whether it has ...
1
vote
3answers
322 views

Choice between 1-dimensional and 2-dimensional array

I'm implementing the Chessboard class to represent the chessboard. I've to implement the transformations (reflections and rotations) on the chess board possible. The possible transformations includes ...
0
votes
3answers
170 views

Sorting an array when values are decreased by each swap [closed]

Recently in an interview I come across a question: We have an unsorted array, we need to sort it with minimum number of swap. We have in sort a 'tax' of 1 is deducted from the number we are ...
-1
votes
1answer
129 views

Fortran 90 - How to create a coordinate system

So I need to code a simple program, and I need to define 2D coordinates? Is there any coordinate system I can use in Fortran? I was told it might have to be all in arrays? And if so, can anybody ...
0
votes
2answers
332 views

Quick algorithm to find matches between two arrays

I'm faced with the following problem: I have an array which is produced by the parsing of a yaml file which contains patterns in the following structure. "Programming books" Title: a ...
2
votes
3answers
468 views

How do you read this line of code?

Forgive me for my poor English, me and my friend were doing school homework, suddenly he asked me to read this line of code ptr = &array[1][1][1] (ptr is a pointer to an integer). He said ...
5
votes
2answers
8k views

Should I use a list or an array?

I'm working on a windows form to calculate UPC for item numbers. I successfully create one that will handle one item number/UPC at a time, now I want to expand and do it for multiple item ...
0
votes
1answer
78 views

What is a cross-platform way to expose an Array[][] over a webservice? Any JSON nuances to be aware of?

I need to expose an Array[][] to many different clients (iPhone, Android, PC, Unix, etc), and need to make it available over HTTP/s This brings me to JSON, and makes me wonder how do all the other ...
0
votes
2answers
354 views

PHP SplFixedArray How To Deal With billions of indexes?

I've built a flatfile db system that will work like mini-noSQL system and it split db to smaller files, and I did a SplFixedArray wrapper for it with a method for searching usage built on preg_grep. ...
1
vote
3answers
897 views

Arrays vs Objects in view template

I am wondering, in view templates, what would contribute to me choosing between using arrays or objects for getting things printed out in arrays {{$user->zip_code}} vs {{$user['zip_code']}} I'm ...
1
vote
4answers
244 views

Is it considered bad practice to access a returned array by a key straight away?

I couldn't think of a good way to word the title, sorry. But what I mean is, is it considered bad practice to do: print get_array()[2] over: output=get_array() print output[2] (where get_array() ...
-1
votes
3answers
867 views

Find all lines segments intersections

I have a collection of lines segments, represented by an array. Ex: [3,7,13,6,9] is 4 line segments: [(3,7)(7,13)] , [(7,13)(13,6)] , [(13,6)(6,9)] , ([6,9)(9,3)] I want to find all the lines ...
-1
votes
5answers
1k views

Reverse subarray of an array with O(1)

I have an idea how to implement sub array reverse with O(1), not including precalculation such as reading the input. I will have many reverse operations, and I can't use the trivial solution of O(N). ...
3
votes
2answers
169 views

What would be the optimal way to solve a problem like this?

I have a problem where I have to change all the Xs in a 2D array into 0s, and I have to calculate the minimum steps (where a single step consists of changing an entire row or column) required to do ...
2
votes
3answers
245 views

What language has integrated “list insertion” as part of code *syntax*?

Many programming languages permit natural manipulation of strings, and some languages permit the manipulations of lists too. More often then not (always?), these operations are done as procedure ...
2
votes
6answers
385 views

Settle an Argument: String vs. Array?

True or False: A string is the same thing as an array. I had an interview the other day and the above question was asked. I said false, but the interviewer said it was actually true. I explained to ...
0
votes
1answer
528 views

Use ruby's array sort() method, or add items in correct place with a binary lookup?

If I am loading a whole load of items (un-ordered words from a file or something) would it be more efficient to load them all to a Ruby array, and then use the built in sort! method or to do a binary ...
0
votes
1answer
327 views

Sort rectangles in a grid based on a comparison of the center point of each

If I have a grid of rectangles and I move one of the rectangles, say above and to the left of another rectangle, how would I resort the rectangles? Note the rectangles are in an array, so each ...
3
votes
2answers
775 views

CA1819: Properties should not return arrays. Does this happen only with arrays? If yes, why?

I have a question about CA1819 msdn performance warning. The rule is: Arrays returned by properties are not write-protected, even if the property is read-only. To keep the array tamper-proof, the ...
2
votes
3answers
1k views

Specific reasons to create own array class over using std::array?

What specific conditions or requirements should you create your own array over using std::array? Here is my background: I'm developing a small simple library that a small group of people will use ...
2
votes
3answers
740 views

Best way to choose random element from weighted list

I want to create a simple game. Every so often, a power up should appear. Right now the different kinds of power ups are stored in an array. However, not every power up should appear equally often: ...
1
vote
4answers
200 views

Efficient way of evaluating an array of strings then add to an array in Ruby

I am looking for an efficient way of evaluating an array of strings against a series of rules and then adding them to another array. For example I have an array of strings: something a 1234 #gohere ...