Array Algorithms are defined as functional algorithms where each step of the algorithm results in a function being applied to an array, producing an array result
0
votes
1answer
33 views
Check correctness of the algorithm for minimum number of jumps in an array
I have an algorithm that is based on a problem where you need to find the minimum number of jumps to reach the end of the array.This problem was asked in geeks for geeks and they do not have a linear ...
3
votes
2answers
66 views
Looking for a limited shuffle algorithm
I have a shuffling problem. There is lots of pages and discussions about shuffling a array of values completely, like a stack of cards.
What I need is a shuffle that will uniformly displace the ...
0
votes
5answers
621 views
Maximum of all possible subarrays of an array
How do I find/store maximum/minimum of all possible non-empty sub-arrays of an array of length n?
I generated the segment tree of the array and the for each possible sub array if did query into ...
3
votes
1answer
68 views
Finding out two such elements out of an unsorted array which have minimum difference without sorting the array
We have been given an array of integer :
45, 10, 56, 42, 95, 78.
We have to find the two elements which have the minimum difference.
I did that in linear time complexity but it works only on the ...
-4
votes
3answers
57 views
How to replace the elements of a range less than k with k?
How do I replace the elements in the range of an array greater than k by k when the number of queries are high?
Given that each query is given by the form l r k; where [l...r] is the range of the ...
-5
votes
2answers
88 views
Finding the largest subscript of an array in a unssorted and repetitive array
I have an unsorted & repetitive array like {1,1,2,2,3,3,5,5,4,4,4} , I would like to find the largest number in the array and its largest position .For example 5 is repaetd twice and i would like ...
1
vote
1answer
42 views
Given a list of vectors in R3 how many unique planes are generated?
While investigating packings of spheres I ran into this problem where I have a list of vectors and I want to know how many planes they generate. I'm generating these lists of vectors that point from ...
0
votes
1answer
70 views
Merge 2 sorted arrays in C
I'm writing code to merge 2 sorted arrays code is below
void main()
{
int a[]={7};
int b[] = {8};
int ret;
int *c;
merge(a,b,c,1,1);
}
void merge(int *a, int *b,int *sorted, int ...
0
votes
2answers
105 views
Find all number pairs in a given range
I have N numbers let say 20 30 15 30 30 40 15 20. Now I want to find how many numbers pairs are in a given range.(L and R given).
number pair= both numbers are same.
My approach:
Create a Map of ...
-7
votes
3answers
99 views
How do you make an algorithm that will return the number of elements in an array in C#? [closed]
I already have some code that I think is going in the right direction, but need help filling in the gap. Please be aware that I cannot use array.Length here and I actually have to make a algorithm ...
0
votes
0answers
57 views
How to use a Linear Search in this particular instance in C#?
I'm reading a text file of dates like this
string[] Date = System.IO.File.ReadAllLines("Date.txt");
I am then converting them like this
DateTime[] Dates = Array.ConvertAll(Date, s => ...
-2
votes
1answer
81 views
Largest number of a fixed length in a sequence of digits
I was solving an algorithmic problem one day that was like:
Given an array of digits, find the largest possible number of fixed length in it ? For ex- "43124911" . Find largest number of length 4?
...
1
vote
1answer
82 views
Can someone explain to me radix-sort?
I am trying to implement radix-sort in javascript. However, I do not know how to do radix-sort! I have this pseudocode (from Introduction to Algorithms):
RADIX-SORT(A, d)
for i = 1 to d
...
1
vote
1answer
85 views
Counting Sort Not Working
I am trying to implement the counting sort algorithm. Based on the psuedocode from Introduction to Algorithms (and if you don't know it it's just a book), I came up with this code:
var countingSort = ...
-1
votes
1answer
89 views
design a linear time algorithm to see if there exists a pair of indices i,j in a sorted array A which holds A[i] + A[j] = S ( target number ) [duplicate]
i actually tried to use a for loop with one pointer from begining and from end
this is my rough idea to increment the frwd pointer if sum value is less or to decrement the backward pointer if sum ...
2
votes
3answers
134 views
Finding all the indexes of some elements on a given list. Can it be done in less than O(n^2) without arrays in Haskell?
Given 2 lists of unique, orderable, non-contiguous elements, say:
['d', 'a', 'z', 'b']
I want to find their index in another list, say:
['a', 'b', 'z', 'd']
The result would be a list with their ...
0
votes
1answer
45 views
Consider a version of quicksort where the pivot is always chosen to be the first element of the relevant subarray
My question is: consider a version of quicksort where the pivot is always chosen to be the first element of the relevant subarray, and the algorithm sorts its input array from least to greatest. Is it ...
1
vote
1answer
38 views
Merging two small sequencies - algorithm
Prove that it is enough to make at most 5 comparisons in order to merge two sorted sequences of lengths 2 and 5.
1
vote
3answers
74 views
Shift last element of the list
I'm looking for the efficient way to shift last element of the list in python to it's appropriate position. for example if we have list = [1, 3, 4, 5, 6, 2] we should get list = [1, 2, 3, 4, 5, 6]. ...
1
vote
1answer
53 views
integers which have smallest absolute difference there can be one such pair or multiple such pair
sample input=
10 -20 -3916237 -357920 -3620601 7374819 -7330761 30 6246457 -6461594 266854
sample output =
-20 30
thanks in advance
i am beginner in programing
class Main {
public static ...
0
votes
5answers
228 views
How to calculate O(log n) in big O notation?
I know that O(log n) refers to an iterative reduction by a fixed ratio of the problem set N (in big O notation), but how do i actually calculate it to see how many iterations an algorithm with a log N ...
1
vote
1answer
66 views
Enumerate neighboring cells in a 'rhombus'-shape on a grid
I'm currently working on a project which features a grid with cells. Every cell has the ability to query its neighboring cells with a function that accepts a relative 'x' and 'y'-coordinate. This ...
0
votes
4answers
218 views
Sorting array algorithm - duplicate values
I have an Integers array size N with duplicates values and I don't know the range of the values.
I have n/logn Different values in this array, and all the rest are duplicates.
Is there a way to sort ...
-4
votes
2answers
129 views
canceling arrays by number of items that I am ready to lose
We are writing c# program that will help us to remove some of unnecessary data repeaters and already found some repeaters to remove with help of this Finding overlapping data in arrays. Now we are ...
10
votes
2answers
160 views
Finding overlapping data in arrays
We are writing a C# application that will help to remove unnecessary data repeaters. A repeater can only be removed in the case that all data it receives are received by other repeaters. What we need ...
-4
votes
1answer
200 views
Write an algorithm to find the most frequently occurred element in the array. Give Time complexity of algorithm
I'm woking on an assignment of 'Algorithm analysis' and i am stuck with this question i have to submit it tomorrow and i need help. Please answer if you can solve this.
Given an array A of n numbers, ...
-2
votes
1answer
123 views
Quick Sort using java
This program is showing errors on compilation,can someone suggest what's wrong?
The main class:
import java.util.Scanner;
public class Sortingpro {
public static void main(String[] args) {
...
0
votes
1answer
425 views
Merge sort using one array
My merge sort algorithm is given below...
As we know this algorithm needs extra memory. Is there any way to do sorting with only one array? (Sorting in a single array.)
My merge sort algorithm is:
...
0
votes
0answers
79 views
Improving quicksort to sort in linear time?
Can we sort unsorted array of real numbers in linear time?
This is what I am thinking :
Given an unsorted array of size n :
Find out the sqrt(n)^th element using selection algorithm (call it x): ...
0
votes
3answers
261 views
Runtime Error & Time Complexity Issues: Minimize the value |(A[0] + … + A[P-1]) - (A[P] + … + A[N-1])|
I recently tackled a coding problem. I came up with a solution to the following problem.
A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a ...
-2
votes
2answers
68 views
How to break a loop in Java where the input size is not previously specified?
I need to input n numbers, store them in a variable and make them available for later processing.
Constraints:
1. Any number of SPACES between successive inputs.
2. The count of inputs would be ...
0
votes
1answer
104 views
How to find median of m sorted arrays?
How to find the median of M sorted arrays of integers? Where the size of each array is bounded by N. Assume that each array contains sorted integer elements.
There are two variation of this question.
...
0
votes
3answers
587 views
How to find second max element in an array in one iteration?
I need the second maximum element in an unsorted array in one iteration.
eg: the array is 3 9 8 2 0 -4 87 45 3 2 1 0
The answer should be 45 , its very simple to find max element in one iteration , ...
-1
votes
2answers
144 views
Prime Number Calculations Help Java
I am a novice, please excuse my lack of organization.
Okay, so what I did was I made an array filled with all the prime numbers between 8 and 100. What I want to do now is make another array that ...
2
votes
3answers
108 views
Am I interpreting this pseudocode wrong?
I've got this pseudocode:
COMPARE-EXCHANGE(A,i,j)
if A[i] > A[j]
exchange A[i] with A[j]
INSERTION-SORT(A)
for j = 2 to A.length
for i = j-1 downto 1
...
0
votes
1answer
155 views
Is linear prefix average method better than quadratic prefix average method?
I've created a method (based on pseudocode I found online) to compute prefix averages for an array but I'm not sure I've satisfied the requirement.
The requirement is:
Given an array a[1…n] of ...
0
votes
1answer
32 views
using a set of vectors in a root searching algorithm
I am working with a time series in which a simple root searching algorithm is needed to calculate a root by iteration. In order to do this I use the package rootSolve. However, I am having some ...
0
votes
1answer
171 views
Modeling the card game War in Ruby and keep getting an infinite loop. Could someone help me understand what's going wrong in my control flow
I'm new to Ruby and only started a few weeks ago. I'm trying to create an algorithm that simulates how the game is played, but I'm getting stuck in an infinite loop. Something is wrong with my ...
0
votes
3answers
538 views
least frequent common number from a int array
I have to find least common number from an int array , I have written code but it is not working properly ,
Here is my logic,
1. sort the array
2. get min common counter updated
3. get if all are ...
2
votes
2answers
326 views
Find Possible addition combinations in array
What is the best way to approach this problem? I have no idea on how to start. This is not a homework problem, but rather practice for interviews.
'Using the JavaScript language, have the function ...
0
votes
0answers
84 views
ith order statistic with bandwidth constraint
Consider the following: Mary and Larry each have an array, M [1,..., n] and
L[1,..., n] respectively. All of the elements in M and L are distinct. Mary and
Larry are interested in finding the i th ...
2
votes
1answer
201 views
Updating a range and keeping track of the maximum value that occurs at every index [closed]
You are given an array, say A[], of N elements, initially all of them are equal to negative infinity.
Now you are asked to perform two types of queries(Total M queries):
Type 1. Given two ...
0
votes
2answers
298 views
Skill set matching algorithm
I was asked this in an interview.
I have been trying to find an elegant algorithm for this problem but haven't been able to do so.
Given a list of people(represented as numbers - id's) with their ...
1
vote
1answer
67 views
Container complexity
Hence I have a std::set<int> and std::list<int>.
I want to have my container sorted.
For set I will have complexity like O(nlogn) for n inserted elements.
For list I will have complexity ...
0
votes
0answers
36 views
Optimize / redesign this java code
folks.
I need help or advice on decision making about a a design pattern (or sort of such) to uuse:
Have an application, running on weblogic via EJBs. Part of application deals with the the very ...
1
vote
3answers
246 views
Divide and Conquer Recursion
I am just trying to understand how the recursion works in this example, and would appreciate it if somebody could break this down for me. I have the following algorithm which basically returns the ...
2
votes
4answers
3k views
Finding a maximum sum contiguous sub array
I am writing a code to find the maximum sum contiguous sub array in C. The logic seems fine according to me, but still the output is not correct. Please look into the code. The algorithm divides a ...
5
votes
2answers
704 views
Median of medians algorithm: why divide the array into blocks of size 5
In median-of-medians algorithm, we need to divide the array into chunks of size 5. I am wondering how did the inventors of the algorithms came up with the magic number '5' and not, may be, 7, or 9 or ...
-1
votes
3answers
175 views
Clustering: finding groups of close items within a large collection
I have an array of items (~5000 items, each item is an English word) and a distance function between pairs of items. I want to find groups of items within the array where all the items within a group ...
-1
votes
3answers
2k views
Finding Minimum Key and Predecessor in B-Tree
Explain how to find the minimum key stored in a B-tree and how to find the predecessor of a given key stored in a B-tree.