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

create unique Id from List of longs

I am submitting a list of ids of type long from UI to download a file which will have only data for those ids. This file needs to be stored in cache when ever its created first time so that when another request with same list of Ids is submitted, it ...
more »

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

does caching reduce the running time in java?

For example, what I need to implement at the moment is called the Submission history. This requires me to use data-structure that takes better than O(n) for each of its methods, and someone told me to use HashMap<studentId, TreeMap<Date, stude...
more »

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

Restructuring an OOP datatype into Haskell types

Coming from an OOP background, Haskell's type system and the way data constructors and typeclasses interact is difficult to conceptualize. I can understand how each are used for simple examples, but some more complication examples of data structures ...
more »

2017-08-31 07:08 (2) Answers

Binary Tree implementation on C

I am trying to implement tree in C but the thing is whenever i try to traverse it, it only shows the first three nodes of the tree and the rest are lost. like, if i enter 100, 200, 300, 400, 500, 600, 700 then only 100 ,200, 300 will be in the output...
more »

2017-08-21 22:08 (1) Answers

Binary Tree: How Do Class Instances Link?

I am trying to understand binary trees, but doing so has brought me to confusion about how class instances interact, how does each instance link to another? My Implementation: class Node(object): def __init__(self, key): self.key= key ...
more »

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

Least Recently Used (LRU) Cache

I know that I can use various container classes in STL but it's an overkill and expensive for this purpose. We have over 1M+ users online and per user we need to maintain 8 unrelated 32-bit data items. The goal is to find if an item exists in the...
more »

2017-08-09 09:08 (6) Answers

Write a list demultiplexer

I'm trying to process the channels of an audio signal. I get the signal as list of frames where each frame has a sample for each channel. Now I would like to process the streams independently then merge them again. So I want type Sample = Double typ...
more »

2017-08-04 13:08 (1) Answers

Hack: Duplicates in java.util.TreeSet?

I have a simple class public class A { int val; public A(int val) {this.val = val;} } I store A instances in a java.util.TreeSet like: SortedSet<A> ss = new TreeSet<A>(new Comparator<A>() { @Override public int c...
more »

2017-07-22 16:07 (2) Answers

Hash-maps or search tree?

The problem is as follows: Given is a list of cities and their countries, population and geo-coordinates. You should read this data, save it and answer it in an endless loop of the following type: Request: a prefix (e.g., free). Answer: all states ...
more »

2017-06-25 15:06 (1) Answers