# Questions tagged [arrays]

A sequential random-access data structure whose size can typically not be changed after creation.

340 questions
30 views

### How to reduce number of move operations in an array?

Say I have an array of numbers, e.g. [0, 1, 2, 3, 4, 5] and I want to end up with an array, e.g. [2, 1, 4, 0, 5, 3]. At my ...
20 views

### What is the answer to this arrays question? [on hold]

!((x > y) && (y <= 0)) is equivalent to which of the following expressions? !(x > y) && !(y <= 0) (x <= y) || (y > 0) (x < y) || (y > 0)
21 views

### What is the answer to this problem? [on hold]

Suppose the following array is declared: int[ ] grades = {88, 92, 95, 83}; What are the values in grades after the following code executes? int temp = grades[0]; grades[0] = grades[1]; grades[1] = ...
23 views

### General algorithm to move a selected set of elements of an array to a new position in the same array [closed]

I have an array. I have to move 1 or more items (selected by the user), to a target user-given index in the same array. The selected items should be in the same relative order after the operation is ...
36 views

### How to compare an element with other elements within an array efficiently for a condition

I need to compare each index with one another and associated array value as well. For example, ...
9 views

### PhoneBookDirectory array in java, explained in detail in picture below [closed]

The PhonebookEntry class exists and is working fine, so write the code as if you had it already.
17 views

### 2D arrays in java [closed]

Forgive me if this is a stupid question, but I am a beginner in java and our teacher doesn explain it too well. I understand how to create a checkerboard in java. This is the code I am using. ...
858 views

### Given an array of integers and a value k, find the length of the longest subarray with max-gap no more than k

I'm struggling with this problem: you are given an array $A$ of $n$ integers and a number $k \in \mathbb{N} : k \neq 0$. The problem asks to find an algorithm that runs in $\Theta(n)$ that returns the ...
34 views

### Is there any way to find the nodes in the each subtree of each node having distance equal to height of the subtree?

We are given a tree of N nodes from 1 to N where node 1 is the root of the tree. For each node i from 1 to N, you have to find the numbers of nodes which are in the subtree of i and are at distance ...
16 views

### Why finding the difference between the adjacent elements of the array to find the maximum difference?

I want to understand a tricky method to find the maximum difference between two elements such that larger element appears after the smaller number. I found easy solution keeping track of the minimum ...
41 views

### The time complexity of finding the kth smallest number using buckets

I've implemented kth smallest number using buckets representing the current nibble value of each element in the array where ...
42 views

### Job scheduling approximation

In the course notes for Stanford MS&E-319: https://web.stanford.edu/class/msande319/lec1.pdf Lemma 5 is given as: The approximation factor of the modified greedy [scheduling] algorithm is 4/3....
74 views

### Partition array into k subsets

We are given an array and a number K. Partition array into K subsets such that let MaxSum be the maximum sum of among subsets. We have to minimize summation =$$\sum_{i=1}^{k}MaxSum-sum(i)$$ Is ...
137 views

### Sort 2D arrays so that cost of reaching new position as described at each iteration is minimized

Problem is as following: We are 8 trumpet players in an orchestra. There are for example 4 parts so there are always two players on the same part. Now, there are not always the same two players ...
39 views

### Using bit arrays to solve crossword puzzles

I have read Crossword Puzzles and Constraint Satisfaction by Connor, Duchi and Lo and I am trying to implement this variation of crossword solving algorithm. I can't understand the bit array data ...
461 views

### Find a point shared by maximum segments

Given: $N$ segments (arrays) of ordered integers, integers could be from $-K$ to $K$. Example: ...
96 views

51 views

### Applying minimax tree to this array [closed]

Please tell me how I should apply minimax algorithm to the array $$15, 12, 14, 16, 11, 13$$ and make a tree?(I understand how minimax algorithm works but I can't apply it to an array)
2k views

### How to measure “sortedness”

I'm wondering if there is a standard way of measuring the "sortedness" of an array? Would an array which has the median number of possible inversions be considered maximally unsorted? By that I mean ...
84 views

### How to find efficiently the minimum modification to avoid close consecutive numbers?

I have an array of sorted numbers: arr = [-0.1, 0.0, 0.5, 0.8, 1.2] I want the difference (dist below) between consecutive ...
36 views

### Find the minimum N such that the sum of beauty of all numbers from 1 to N is at least X

The beauty of a number is defined as follows :- ...
98 views

### FInding the combination with the least number of elements from and array of integers, given an integer sum

I'm doing and assignment where the problem is to find the combination with the least number of elements form an array of integers, given an integer sum. I have solved this using a gready algorithm ...
26 views

### Recurrence Relation for Column Major Form of multidimensional array

A two dimensional array is stored in column major form in memory if the elements are stored in the following sequence A[0][0] A[1][0] A[2][0]...A[n_1-1][0] ... A[0][1] A[1][1] ... A[n_1-1][1] .... A[...
55 views

### Find a subsequence with fastest time for specific distance

I have two arrays. ...
64 views

### What does the “0 ≤ K < N-1” expression means?

Given the following statement: "A nonempty array A consisting of N integers is given. Any integer K, such that 0 ≤ K < N-1, splits array A into two non-empty parts" What does the 0 ≤ K < ...
72 views

### Is it possible to solve this problem in less than n^2 time without using additional space?

Here's the problem: Given an array array containing integers, maximize array[i] + array [j] + |i - j| where i and j both range ...
40 views

### Find four sets where each element from those four appears in at least two of those four sets

I have a list of sorted arrays ("sets") of integers $A_1..A_n$ where each element is unique w.r.t. the other elements in the same array: $A_i = \{x_{i,1}..x_{i,c_i}\}$ $x_{i,p} < x_{i,p+1}$ $A_i$ ...
22 views

### Generate Evenly Distributed Pattern Based on Weights

I have an array of items $A = \{A_i\}, i \in I$ with integer weights $W_i, i \in I$. I need to build a function $f: I \rightarrow A$, that produces evenly distributed patterns of array elements ...
135 views

### Array subset division with equal sums

Today I stumbled upon a problem which looked like the partition problem but certainly is different. Given array of positive integers, guaranteed to not be divisible into two continious subsets of ...
89 views

### Find the smallest element greater than current element

my question is that given a list of integers (lets say A), for each element A[i], find the smallest element A[j] which could satisfy A[i] < A[j] and i < j. Return -1 if there is no such element. ...
19 views

### How to count stores in cache analysis of matrix multiplication

I'm trying to understand cache misses/iter and came across this that I couldn't understand or reason out. For ijk iteration, my slides say that there are 2 loads and 0 stores. ...