Category "data-structures"

Fastest way to read a CSV file java

I´ve been trying to read several csv files (arround 20 MB) using openCSV, but so far it has been slow. Im trying to read 4 csv files which I´m loadi

Reasons for using a Bag in Java

I am currently studying about Algorithms & Data Structures and while I was reading over the Book of Algorithms 4th edition, I discovered the Bag data-struct

Understanding the Big O for squaring elements in an array

I was working on a problem where you have to square the numbers in a sorted array on leetcode. Here is the original problem Given an array of integers A sor

Random access of a linked list element

In an article about linked list, it is said that accessing a random element is not allowed and to access a certain node we need to traverse it from the head nod

How to approach this Dynamic Programming Meal Plan Problem?

I came across this problem in a practice interview. I don't want a direct answer, just some help with the intuition of the problem, both your brute force thinki

How to generate the worst case for disjoint set with only path compression?

A disjoint set with only path compression implemented is like this: // In cpp. int Find(int x) { return f[x] == x ? x : f[x] = Find(f[x]); } int Union(int a, i

Amazon interview: Min stack

I recently had my Amazon interview for SDE. I was asked to design a stack which does push, pop and min in O(1). I got the logic and implemented the push of the

An undirected graph having n edges, then find out no. of vertices that graph have?

An undirected graph having 'n' number of edges, then find out number of vertices that graph have?‏‏‎

Finding the shortest path with only passing specific edge less or equal to one time in Graph

Given a undirected graph that it has ordinary edges and specific edges, our goal is to find the sum of the shortest path's weight between two vertices(start ve

How to skip an item in nested map based on When()

I want iterate over items's data and create a a new list of SomeData based on item.type however when type is UNKNOWN I need skip that element and not add to lis

Fastes way to read a tsv file and store it in a map (C++)

I'm working on a project with 6 huge mapping tsv files. In most cases they look like this: First: ID which is a unique String which starts with a char and goes

export file to xlsx format in java

I am getting 500k records per request from the Database then mapping the data to a list of POJO classes then writing the records to an excel sheet (I have the r

How to do pre-order and post-order traversal of THREADED binary search tree?

Okay, so in-order traversal of threaded binary tree by using threads goes something like this: Start at leftmost node and print it Follow thread to right and

Infected Fish can eat another fish having size less that its own. Minimum number of operation required

An evil scientist has developed an injection that induces insatiable hunger in a fish. On giving this injection, a fish of size x can eat another fish of smalle

My check for whether a graph is a Binary Tree always returns false

I have this question that is medium level and couldn't even think on how to solve this problem, my solution could be overkill as I have no idea on how to traver

malloc(): memory corruption (fast)

I just started to learn data structure and getting an error when executing malloc(): memory corruption (fast) what can be the issue and how to resolve it? I h

What is the purpose of a Bloomier filter?

This question is about the Bloomier filter, which is not the same as a standard Bloom filter. I'm learning about the Bloomier filter and I don't see the advanta

How can I declare a structure in C++ without defining it?

I have been following a tutorial at cplusplus.com/doc/tutorial. Near the end of the Functions page, it discussed prototyping a function. Later on, I read about

How to check if a struct is NULL in C or C++

i have the following structure typedef struct { char data1[10]; char data2[10]; AnotherStruct stData; }MyData; for some reason the imple

HashMap should be unsorted but still sorts according to key

According to these: http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html Difference between HashMap, LinkedHashMap and TreeMap java beginner : How k