## Array merging and sorting complexity calculation

I have one exercise from my algorithm text book and I am not really sure about the solution. I need to explain why this solution: function array_merge_sorted(array \$foo, array \$bar) { \$baz = array_merge(\$foo, \$bar); \$baz = array_unique(\$baz); ...
more »

2017-10-04 16:10 (1) Answers

## which is optimal a bigger block cache size or a smaller one?

Given a cache size with constant capacity and associativity, for a given code to determine average of array elements, would a cache with higher block size be preferred? ...
more »

2017-10-03 15:10 (2) Answers

## Extracting k largest elements

If I have n integers, is it possible to list the k largest elements out of the n values in O(k+logn) time? The closest I've gotten is constructing a max heap and extracting the maximum k times, which takes O(klogn) time. Also thinking about using ino...
more »

2017-10-02 18:10 (3) Answers

## Triple Nested For Loop with specific output (java)

I need to write some java using 3 "for" loops that outputs 122333444455555 22333444455555 333444455555 444455555 55555 The code I have so far: public static void problemFour() { for(int i = 5; i >= 1; i--) { for(int a = 1; a ...
more »

2017-10-02 07:10 (6) Answers

## Java: Find String with the highest value

I need to accept a string as input, split it into an array of individual words ( split on " ") and return the highest scoring word as a string. Each letter of a word scores points according to it's position in the alphabet: a = 1, b = 2, c = 3 etc. I...
more »

2017-10-02 05:10 (5) Answers

## Find constant subarrays in large numpy array

I have a numpy float array like v = np.array([1.0,1.0,2.0,2.0,2.0,2.0,...]) I would need to identify all the constant segments in the array like [{value:1.0,location:0,duration:2},..] Efficiency is the main metric ...
more »

2017-09-30 13:09 (3) Answers

## Ruby: Averaging values of Array of Arrays while Grouping according to Date

How to average values of the second element of an array of arrays; instead of adding them : [ [ '01-01-2001', 4 ], [ '01-01-2001', 5 ], [ '01-01-2001', 6 ], [ '01-02-2001', 7] ] to [ ['01-01-2001', 5], [ '01-02-2001', 7] ] ? ...
more »

2017-09-30 02:09 (1) Answers

## Java: Extract the smallest element in a 2D array, and sort the array

I'm trying to extract the smallest element from my Array by calling the function extractMin(A), with A being the array that i want to extract from public int extractMin(int[][] A) { if(A[0][0] != 1000) { int min = A[0][0]; A[0][0...
more »

2017-09-29 23:09 (0) Answers

## Algorithms: Hybrid MergeSort and InsertionSort Execution Time

Good day SO community, I am a CS student currently performing an experiment combining MergeSort and InsertionSort. It is understood that for a certain threshold, S, InsertionSort will have a quicker execution time than MergeSort. Hence, by merging b...
more »

2017-09-29 22:09 (1) Answers

## Codility PermMissingElem

My solution scored only 40% correctness on Codility. What am I doing wrong? Here is the test result (https://codility.com/demo/results/trainingU7KSSG-YNX/) Problem: A zero-indexed array A consisting of N different integers is given. The array con...
more »

2017-09-29 21:09 (2) Answers

## Define an algorithm which gets a number and a list and returns a scalar based on number's distance to average of the list

Let's suppose that we have got a list which appends an integer in each iteration which is between 15, 32(let's call the integer rand). I want to design an algorithm which assigns a reward around 1 (between 1.25 and 0.75) to each rand. the rule for as...
more »

2017-09-29 04:09 (1) Answers

## sorting k sorted lists by their max element

If I had k sorted singly linked lists and sorted them (mergesort) by each list's largest element (last in the list), what would the big O (running time / time complexity) be? Assuming list 1 ~ k has different size: n_1 ~ n_k. I was thinking O(k * log...
more »

2017-09-27 12:09 (1) Answers

## Running time of a modified merge sort compared to merge sort?

From wikipedia, https://en.wikipedia.org/wiki/Merge_algorithm#Application In the diagram, let's say we consider the middle row of numbers (would help if someone can post the picture here). What would the running time of the algorithm be if I modifie...
more »

2017-09-27 02:09 (1) Answers

## Algorithms - Count all pairs of equal numbers in a sorted array in O(n)?

A question that has me speculating is the following: Let's say we have a sorted array with the numbers {1,1,1,1,2,2,4,4,4}. Now, given that we can clearly see that we have six pairs on 1's, one pair of 2's and three pairs of 4's (10 pairs). How wou...
more »

2017-09-26 14:09 (4) Answers

## search a line in preprocessed big text file

I have a data file which contains 100,000+ lines, each line just contains two fields, key and value split by comma, and all the keys are unique. I want to query value by key from this file. Loading it to a map is out of question as that consumes too ...
more »

2017-09-26 13:09 (3) Answers

## Is there a library that allows me to perform operations on very large lists that can not be put into memory?

Representative list (or set) operations include insert, delete, update, and append, as well as sorting, intersection, union, concatenation, and filtering. Is there a library, an application or a system that allows me to store very large lists using ...
more »

2017-09-26 09:09 (0) Answers

## Algorithm for many images and their color palettes

For a project I'm looking for an algorithm to convert a lot of images to paletted images, which can share same palettes. The short story Given: A list of images (RGB), which already have the final colors which should be used. Result: A list...
more »

2017-09-25 18:09 (1) Answers

## Can anybody tell me why I am getting segmentation fault in this code

I am testing it for various distributions and I am getting segmentation fault when reversed(descending) sorted array is given as input. Sometimes it works well even for reversed sorted array and sometimes I am getting segmentation fault error particu...
more »

2017-09-25 08:09 (2) Answers

## How does the runtime of an algorithm and the input size tell you the time complexity of the algorithm?

I did an experiment calculating the mean runtime for sorting algorithms merge sort and quick sort for arrays of size n, and I'm not sure how to prove merge sort and quicksort are O(log2(n)) from the results. Results are here: n mergeSort: ...
more »

2017-09-25 03:09 (2) Answers

## Efficient way to find a pair with minimum difference in an array

I'm trying to solve a problem that requires me to find a pair with minimum difference in an array. For example, if the array is 6,7,1,3,9 The output is (6,7) with difference of 1 which is minimum. The fastest solution I can come up with is...
more »

2017-09-24 09:09 (3) Answers

## Number of times all the numbers in an array are divisible by 2

I am trying to get the count of number of times all the integers in an array is divisible by 2 considering only one integer in each step. For example, initially if I have the array : [2,4,2] and count = 0 Step 1 [1,4,2] , count=1 Step 2 ...
more »

2017-09-24 07:09 (2) Answers

## Display JavaScript Math Result

I am having trouble displaying a math function, there is nothing stated wrong in the console, so I do not know where I am going wrong. the output does not display the correct answer here... Desired outcome: enter number in each input, and javascript...
more »

2017-09-22 22:09 (4) Answers

## How to match and highlight all terms in any order from an array of strings?

I'm aware that there are similar questions asked and answered. Please take the time to understand the specifics before voting to close this as a duplicate though. The requirements are: Find strings from an array (from here on called options) t...
more »

2017-09-22 14:09 (3) Answers

## Conditional Null Object: Comparison method violates its general contract

Scenario I got an Object which has a startDate and an endDate. If both are not null the timeDiff will be set, calculating the time difference between these two dates in Long. Use Case All Objects with a timeDiff should be first, rest last. Compar...
more »

2017-09-22 13:09 (2) Answers

## Can I use categorical and numeric data in decisiontreeregressor(), big rmse?

To train my data I have used data which are in input categorical (years and month) and numerical data (not continu). My output is numerical and not continu too. I tried multiple regression, my train (is 1) probably overfit and my test is constant (a...
more »

2017-09-22 09:09 (0) Answers

## C# dynamic algorithm

I have to think of implement a dynamic algorithm of Offer Service in C#, which is generic to configuration. For Example, sales manager promotes an offer "Buy One Get One 50% off" Offer, we have to implement this offer without deploying the system. We...
more »

2017-09-22 02:09 (0) Answers

## Xor algorithm with no special characters using VBA

For a project I am developing I need to use some kind of encryption algorithm to encrypt some sensitive data, where each user has a unique hex key. Basically I have to encrypt a string and write it to a file to import to a Access database (we are n...
more »

2017-09-21 23:09 (0) Answers

## find a subset of predictions which maximize the number of correct majority decision

Assuming I have a multi-class sequence prediction problem, with the correct answer: gold = [1,2,1,0,2,2] There are N models which gives different predictions: pred1 = [1,2,2,0,2,2] pred2 = [2,2,1,1,1,1] pred3 = [1,2,1,0,2,1] pred4 = [1,1,0,2,1,2]...
more »

2017-09-21 13:09 (1) Answers

## What is algorithm to find K for finding medians in two sorted array in leetcode

The solution implementing find medians in two sorted array is awesome. However, I am still very confused about code to calculate K var aMid = aLength * k / (aLength + bLength) var bMid = k - aMid - 1 I guess this is the key part of this algorithm ...
more »

2017-09-21 06:09 (1) Answers

## String - first and last name in alphabetical with capital letter

I need to arrange the names accordingly in alphabetical order. I managed to get the desired output. However, when I type the name with first cap, eg: Peter, the output is different. EG input: Peter Paul John Mary EG output: First word = John, Last...
more »

2017-09-19 18:09 (4) Answers

## Print contents of array, when half way through insertion sort

I have written a simple insertion sort algorithm, it is working well. What I would like is if the program printed the contents of the array when it is half sorted. I can print the contents of the array just fine, but I cannot figure out how to tell w...
more »

2017-09-19 11:09 (1) Answers

## Optimization of a recursive function

Optimization of a recursive function Hello everybody, I’m doing a npuzzle solver and I have a mistake… When heuristic Manhattan is off I check all ways with the default order (top, bottom, left, right). When Manhattan is on I chose the smallest...
more »

2017-09-19 09:09 (0) Answers

## Haskell: Sort an almost-sorted array

I've been learning Haskell in my spare time working through LYAH. Would like to improve upon my Haskell (/ Functional programming) skills by solving some problems from the imperative world. One of the problems from EPI is to print an "almost sorted a...
more »

2017-09-18 22:09 (1) Answers

## Alternately mix DATA in MS EXCEL

I have one csv file which contains 10.000 rows. The 2.000 rows have the value "EXPL_1". The 3.000 rows have the value "EXPL_2". The 2.500 rows have the value "EXPL_3". The 1.500 rows have the value "EXPL_4". The 2.000 rows have the value "EXPL_5". I...
more »

2017-09-18 13:09 (4) Answers

## Time Complexity Improvement

I have been trying the coding challenges on Codility.com This is one of the questions that i tried: A non-empty zero-indexed array A consisting of N integers is given. A pair of integers (P, Q), such that 0 ≤ P < Q < N, is called a slic...
more »

2017-09-18 12:09 (1) Answers