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
-4
votes
0answers
12 views
Algorithm to a match a number in the array with any other number in the array plus lenth(binary representation of that no) [on hold]
Let, a number n support a number (n+x), where x is the number of bits in the binary representation of n, like if n = 10, whose binary representation is 1010, i.e x=4; then it supports (10+4)=14. Now,...
0
votes
1answer
9 views
Recurrence iteration method solve
hi i have this recurrence: how to solve?
a) Solve the following recurrence using the iteration method and give an asymptotic running time:
T(0)=0 and T(n)=10 +T(n-1), for n ≥ 1
0
votes
3answers
36 views
A better way to search an object
Often times I'll find myself having to access a particular object from an object or array of objects that are indexed by arbitrary indices, but the object I need is one who's key matches a particular ...
1
vote
1answer
82 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
1answer
611 views
Trouble with my algorithm to solve a boggle board
so I'm relatively new to Java (I'm taking AP java at my school currently) and I am trying to develop a recursive algorithm to solve an n*n board and I feel I am very close but not quite there yet.
I ...
0
votes
0answers
32 views
Closed Point Algorithm [migrated]
User enters a nxn Matrix (with each position set either to 0 or to 1).
An 0 value at a position impiles absence of the point and a 1 value implies presence of the point.
Now the user enters a value (...
0
votes
0answers
53 views
wiggle sort, application of wiggle sort
Basic understanding about wiggle sort is that it arranges the number in increasing and decreasing order. as shown here.
nums[0] < nums[1] > nums[2] < nums[3].....
To achieve this, I have ...
1
vote
2answers
46 views
Can not get precise results for the hourglass algorithm
Here is the link for definition of the hourglass problem:
https://www.hackerrank.com/challenges/30-2d-arrays
I wrote the following program:
package day11;
import java.util.Scanner;
public class ...
0
votes
2answers
51 views
replacing elements of one array from others to minimize the sum of first array [closed]
We are given two arrays , A[] of size n and another array B[] , of size m , we can replace any number of elements in A[] , using elements of B[] , each element of B[] can be used only once to replace ...
1
vote
4answers
160 views
Programming test on algorithms? [closed]
I was given this question in a programming test for an IT company.
I will try my best to explain it.
The problem is as follows:
Given an Ant at origin (0,0) which moves only in clockwise direction( ...
0
votes
1answer
71 views
Randomized quicksort C#
I am trying to analyze the quick sort algorithm with a random pivot on C#. This is the code I am trying to use this portion of code:
//begeeben.wordpress.com/2012/08/22/randomized-quick-sort-in-c/ ...
-2
votes
3answers
296 views
Array Algorithms
I have one question to ask on Algorithms. I have been asked to write the algorithm on this: Not asking you to write the algo for me, but just let me know the efficient process what I need to do:
...
4
votes
7answers
3k views
Maximum element in array which is equal to product of two elements in array
We need to find the maximum element in an array which is also equal to product of two elements in the same array. For example [2,3,6,8] , here 6=2*3 so answer is 6.
My approach was to sort the array ...
1
vote
0answers
42 views
Synchronous operation On Node.js (Large data Computation)
EDIT
Changes made against the comments
I have Four Arrays.
commonOrdersList --length around 40k
storeA --length close to 100k
storeB --length around 110k
storeC --length close to 100k
of ...
0
votes
2answers
85 views
Convert integer to roman numerals - there must be a better way [closed]
I'm working through the intermediate algorithms in the FreeCodeCamp curriculum. One of them involves converting integers to roman numerals. My solution (presented below) works, however it is very much ...
0
votes
2answers
30 views
Insertion Sort - troubles reading MIT Intro to Algos
The MIT Intro to Algorithms describes insertion sort as:
I wrote this in Python as:
def sort(A):
for j in range(1, len(A)):
key = A[j];
i = j - 1;
# i > 0 should be i ...
0
votes
1answer
98 views
Designing an algorithm to sort n strings in O(dn)
How can I design an algorithm to sort n strings in O(dn) where d is the #of characters in a longest string?
1
vote
1answer
61 views
How can I improve the speed of this shortest path/shortcut(array graph DS) solution?
Given a maze as an array of arrays where 1 is a wall and 0 is a passable area:
Must include start node in distance, if you BFS this it will give you 21.
[0][0] is the start point.
|
[ V
[0,...
6
votes
3answers
1k 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 ...
3
votes
3answers
10k views
Sorting Coordinate Points c++
in an application I measure a lot of 2d coordinates (x,y) of a
pattern. This pattern consists of a set of points on grid with fixed
pitches in x and y direction. These coordinates all have a score for
...
-6
votes
1answer
70 views
Interivew: Sweet Candies [closed]
You have been provided the sweetness level of N candies placed in a row. The sweetness level of each candy is represented as an integer.
And yes, a candy can have negative sweetness level (it's bitter ...
-2
votes
1answer
54 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
38 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
45 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
71 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
159 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
53 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 ...
-2
votes
3answers
86 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
95 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 ...
13
votes
4answers
3k views
Given an array [a1b2c3d4] convert to [abcd1234]
Constraints :
O(1) space
O(n) Time
It is not a homework question just a interesting question I came across.
Here are some solutions I could think of but nothing that does it in given constraints.
...
1
vote
4answers
102 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]. ...
0
votes
1answer
47 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 ...
0
votes
3answers
82 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 ...
0
votes
1answer
73 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,...
-4
votes
1answer
97 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....
1
vote
2answers
54 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
182 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
60 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
61 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
2answers
178 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?
-2
votes
1answer
47 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?
0
votes
1answer
23 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?
1
vote
1answer
249 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 = ...
2
votes
1answer
132 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
2answers
57 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.
3
votes
3answers
2k views
datastructure behind browsing history
Im writing a QML file browser. Now, I want to implement a back and forward function. This function is similar to browser back and forward functionality. Example :
I start in "/home/text/folder1" and ...
1
vote
1answer
174 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,...
4
votes
3answers
2k views
calcuating the sum of nodes in a single verticle line of a binary tree
For a binary tree i want to get the sum of all nodes that fall in a single verticle line.I want the sum of nodes in each verticle node
A
/ \
B C
/ ...
0
votes
3answers
56 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
808 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(...