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

Is it correct using stack in my implementation?

#include <iostream> / File: int-stack.h / #include <cstdlib> using namespace std; const int BUFFER SIZE = 100; class int stack { private: int data[BUFFER SIZE]; // Use an array to store data int top_index; // Start from 0; -1 when empty p...
more »

2017-05-20 10:05 (1) Answers

No output on binary tree traversal in C

I am a rookie programmer and I have a project which implies using binary trees. All I have to do is to insert a node, delete a node and add two methods of tree traversal. The issue is I can't get my code to work. I decided to add few helper functions...
more »

2017-05-13 10:05 (1) Answers

How to add a node in BST?

I have tried the following algorithm by using recursion but the nodes are not getting appended to the tree. Please tell me what's wrong. void search_add(struct node *t) { if(t==NULL) { t = newNode(temp->key); return; ...
more »

2017-05-12 20:05 (2) Answers

What's wrong with my LRUCache code

I try to solution a question in LeetCode,it's ask to implement a LRUCache. And when I submit my code, the System told me the result is Wrong Answer. Because the TestCase is too long ,I can't find the problem in my code.And when I choice "Run code" to...
more »

2017-05-11 11:05 (1) Answers