Seg fault on binary search tree - big sorting

Trying to do this Big Sorting problem on Hackerrank. I know there are simpler ways to write the algorithm, but I am trying to brush up on my C knowledge, and as such wanted to challenge myself and write a Binary Search Tree for the problem. The bina...
more »

2017-09-16 20:09 (2) Answers

Rearranging an array of integers

I need to implement the following in both pseudocode and java. Input: an array of integers Output: Rearrange the array to have the following: suppose the first element in the original array has the value x In the new array, suppose that x is in p...
more »

2017-09-15 23:09 (3) Answers

Cut and Stack the Array

I have an array of int as input. The array will always be a length of 2^n. I want to cut the array in half and stack it. Repeat cutting and stacking until there is only one stack. For example: int[] array = {1,2,3,4,5,6,7,8} if we cut the array in ...
more »

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

Algorithm for nesting nesting sets

I have a large collection of sets, some of which are subsets of each others, like: [{1, 2, 3, 4}, {1, 2}, {1, 5}, {1, 2, 3, 4, 5}, {2, 6}] I'd like to take this collection and output a DAG of partial order of the subset relations {1, 2, 3, 4, 5} ...
more »

2017-09-13 05:09 (0) Answers

Sort array using two thirds algorithm

I came across an uncommon sorting algorithm. The algorithm sorts the first 2/3rd of an array then next 2/3rd of an array and again sorts the first 2/3rd of an array recursively. fun sort3(a: int list): int list = case a of nil => nil | [x...
more »

2017-09-12 00:09 (0) Answers

How to sort by best match?

I have a query where I want results to match as close to the conditions as possible. For example If I have a condition "a" = 500, then the returned results should be sorted such that I'll get 500, 499, 501, 498, 502 and so on..expanding from the pro...
more »

2017-09-11 16:09 (2) Answers

(merge sort) is log from n log n on base 2?

I've learned in class that merge sort is O(n · log(n)), but I'm not clear on whether it's O(n · log2(n)) or O(n · log10(n)). I've read on Stack Overflow (at Big O notation Log Base 2 or Log Base 10) that "it does not ...
more »

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

Big-O and Omega Notations

I was reading this question Big-O notation's definition. But I have less than 50 reputation to comment, so I hope someone help me. My question is about this sentence: There are many algorithms for which there is no single function g such tha...
more »

2017-09-09 12:09 (2) Answers

Haskell - how to avoid messing pure with IO

I am implementing some algorithm on haskell. This algorithm requires generating some data. I have a function of an algorithm which takes generation function as a parameter. For example, algorithm is just multiplying input data by n: algo :: a ->...
more »

2017-09-06 17:09 (2) Answers

Fibonacci Sequence using Cache

I am trying to make use of a cache to improve the performance of my Fibonacci method. However, it is still taking a lot of time to compute even fibonacci(40). import java.util.Scanner; public class FibWithCache { public static void main(String ...
more »

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

recursion in my quicksort

I'm currently trying to implement quicksort on an array in javascript. I have the overall layout but for some reason the recursion isn't working. It seems to have worked for the 2nd iteration of the code but after that, it seems to just mess up. Not ...
more »

2017-09-06 05:09 (2) Answers

Find a day of week for given first day in month

How could be calculated a day of the week if we know the day number of the first day in month? Lets say we have 1..7 days in a week I want to get number of the 4th day in the month if the 1st = 5 (Friday) then result should be 1 (Monday). 1st - 5 F...
more »

2017-09-05 23:09 (1) Answers

Random numbers external sort

I need to write a program that generates N random numbers and write them to binary file in descending order. It should be done without using any of sorting algorithms that use main memory. This is what I've done so far: #include <iostream> #i...
more »

2017-09-05 17:09 (3) Answers

std::list sort algorithm runtime

I have a list of elements that is almost in the correct order and the elements are just off by a relatively small amount of places compared to their correct position (e.g. no element that is supposed to be in the front of the list is in the end). &l...
more »

2017-09-04 16:09 (4) Answers

When will the LRU algorithm be miss 100%?

I know these two ways to make LRU algorithm miss 100%. Cyclic accesses to a data-set that is marginally larger than the cache size. Arbitrary bursts of accesses to an infrequently accessed data-set that pollutes the cache by replaceing the mor...
more »

2017-09-03 16:09 (1) Answers

Why this is a bad bubble sort algorithm?

I started studying Data Structures and algorithms, and tried to implement Bubble sort: def BubbleSort(list): for a in range(len(list)): for b in range(len(list)):# I could start this loop from 1 if list[a]< list[b]: # to avoi...
more »

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

Would it be efficient to sort with indexes

So I was thinking of a new sorting algorithm that might be efficient but I am not too sure about that. 1) Imagine we have an array a of only positive numbers. 2) We go through the array and find the biggest number n. 3) We create a new array ...
more »

2017-09-02 19:09 (2) Answers

Get subgraph of shortest path between n nodes

I have an unweighted graph and I want to get a subgraph that has just the nodes and edges that contain the shortest paths between n known nodes. In this case 3 nodes (11, 29, & 13 are the names). Question How can I get a subgraph of shortest p...
more »

2017-09-01 15:09 (0) Answers