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
-2
votes
1answer
36 views
repetition detection in O(Log n) in sorted array
Given a sorted integer array A of size n, where n is a multiple of 4. Could someone help me how to find an algorithm that decides whether not there exists an element that repeats at least n/4 times in ...
0
votes
0answers
34 views
pythonic quicksort. call stack exceeded
This is my attempted implementation of quicksort in python
However, I notice that I have a max call stack exceeded error, likely because the length of my collection never goes down.
When printing, I ...
0
votes
2answers
39 views
Iterate javascript array and sum attributes
Consider an array that contains objects. Each object of the array is composed of both label and value attributes. I want to be able to compare each object of the array, and if the labels are the same, ...
0
votes
2answers
43 views
Enumerate all possibilities in array with descending values
I'm trying to write a recursive approach to enumerate all possible values of an array of arbitrary length whose elements can all descend to one. More formally, given an array A with the elements, A_1, ...
0
votes
1answer
89 views
C++ Best way to read BitMap “Right Way up” into 1D Vector
I am trying to read a BitMap "The Right Way Up" into a 1D Vector. Here is my first attempt. It is pretty clunky:
void BitMap::ReadBMP(const char* filename)
{
FILE* f = fopen(filename, "rb");
if(...
0
votes
2answers
37 views
Data Structures: If Heaps are trees, why are they implemented internally with Lists or arrays?
I'm giving myself a refresher course in data structures and algorithms (and learning new stuff -- I was an Information Systems major in college instead of Computer Science, so I didn't get a formal ...
0
votes
1answer
59 views
Peak finding algorithm - Why global maximum, what are the applications?
I came across the Peak Finding Algorithm from the MIT Intro to Algorithms class. I was wondering what are some of the practical applications of the algorithm, for both the 1D and 2D cases? Also, why ...
0
votes
1answer
62 views
Fastest way to eliminate consecutive duplicates from array in objective-C
Prepping for interview. Trying to work out a solution for the question "Fastest way to eliminate consecutive duplicates from array" using objective-C. I.e input =[1,2,2,1,2,3,3,4] output =[1,2,1,2,3,...
0
votes
3answers
71 views
What's the fastest way to remove duplicates from an array in Objective-C
Prepping for an interview. I am trying to practice by solving the following problem: Given an input array of NSNumbers where some of the numbers are duplicated, how can you create another array that ...
-4
votes
1answer
73 views
Algorithm to find all substrings from the given array of string
I need to find all sub-strings from the given array of strings and group them.
Additional condition:
If string S1 contains string S2, S1 contains S3, S2 contains S4 - all them should be in one group....
-2
votes
3answers
74 views
Best way to find all elements in a list that are present more than k times
I just came across a problem and I was wondering what would be the best way to solve this.
I have a List of Lists
L = [[1, 2, 3, 4, 5, 6, 7], [2, 4, 6, 8, 10, 12], [3, 6, 9, 12, 15], ....]
...
0
votes
1answer
26 views
Amortized Analysis [Dynamic Array]
Let x be the size of an empty array. If the array grows full, a new one will be created with a length k > x. The contents of the old array will be copied to the new one, and the new element will be ...
1
vote
2answers
36 views
Finding the distance between the two closest numbers in an array of n numbers. (Presorted Arrays)
The arrays are presorted making the algorithm θ(nlogn) [sorting+finding minimum distance], compared to bruteforce θ(n2). Both the codes does the same job but the first one shows time limit exceeded. I ...
-1
votes
1answer
67 views
Computing the union and intersection of two unsorted arrays in O(mlogn) time
Okay, so I need to devise the following algorithm (NO CODE NEEDED, just steps):
Given two sets A and B with length m and n respectively where the numbers in each set are distinct, unsorted, and m<...
0
votes
0answers
47 views
Water between building in three dimensions
The question is quite similar to this question :
Amazon: Water collected between towers
But I need to fix a problem similar to above with extra dimension.
There are towers with same base area, but ...
0
votes
1answer
41 views
Finding peak in 2D grid with traversal
We have a n-by-n grid such that the lower-left corner has coordinates (0,0) and the upper-right (n,n). The cells in the grid all have distinct values, and our goal is find a local peak, which is ...
-2
votes
1answer
42 views
How to implement a stack of integers in array in Java Collection Framework as a variable-size array?
The question is how to implement a stack of integers in an array in Java Collection Framework as a variable-size array?
2
votes
2answers
114 views
Finding continuous subsequence that minimizes the average of the rest of the array?
Suppose there's an integer array arr[0..n-1]. Find a subsequence sub[i..j] (i > 0 and j < n - 1) such that the rest of the array has the smallest average.
Example:
arr[5] = {5,1,7,8,2};
Remove ...
0
votes
1answer
16 views
Complexities of the following -insertion sort, selection sort ,merge sort , radix sort and explain which one is best sorting algorithm and why?
Complexities of the following -insertion sort, selection sort ,merge sort , radix sort and explain which one is best sorting algorithm and why?
2
votes
2answers
133 views
Why does mergesort have at most 6 n log n array accesses?
I'm watching the Coursera Princeton algorithms lecture on merge sort and I understand all of the analysis except for a merge being at most 6 n log n array accesses.
Why 6?
0
votes
3answers
53 views
Sort array of numbers (first number will be dynamically selected and remaining array should be sorted ascending)
int[] array = {1,1,0,1,2,2,0,0};
int firstNumber = 1;// dynamic can be 0 or 1 or 2
int numberOfOccurances = 0;
//Basic sort functionality
for(int i = 0 ; i< array.length; ++i)
{
if(array[i] ==...
1
vote
1answer
127 views
Dynamic Programming: Why can't we solve minimum no. of coins required to form a change with the concept of 0/1 knapsack?
Concept of 0/1Knapsack-
Fill a knapsack of W weight using given weights.Aim is to maximize the profit.
Ans-Problem can be solved by either taking a particular weight or not taking a particular weight,...
0
votes
2answers
51 views
Efficient Program to count values less then A[i] to the left of i
Can someone provide NlogN complexity efficient Program to count values less then A[i] to the left of i ,
I know how to do in n square.
If possible provide link.
1
vote
1answer
231 views
How to remove the last input element in an array?
For this program, I have a user input elements into a 5 space array using the private static void add() method. After adding these elements, the user is then able to use the private static void delete(...
0
votes
1answer
42 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
84 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
2k 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
90 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
72 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
116 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
80 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
88 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 i,...
0
votes
2answers
174 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
105 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
78 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 => DateTime....
-2
votes
1answer
100 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
98 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
173 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
157 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
136 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
60 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
42 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
4answers
95 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
88 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 ...
1
vote
5answers
567 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
87 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
766 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
130 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
184 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
283 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, ...