Questions tagged [data-structures]
11674 questions
1
votes
1
answer
17
Views
Fast way of concatenating complex data using vertcat with custom rows
I need to concatenate few bigger matrices, but in specific manner - for example to concatenate only 1 row from X matrices.
There is a good solution of storing the data in a structure, so then there is no need of preparing long list of things that needs to be concatenated.
For example, we will have a...
1
votes
1
answer
41
Views
Create a Tree/Trie from a word
I need some help to create a javascript algorithm that builds a tree out of a word. The nodes of the tree are the letters of the word that are always in alphabetical order. Ex. 'balance' should be this object:
const tree = {
b: {
l: {
n: {}
},
n: {}
},
a: {
l: {
n: {
}
},
n: {
},
c: {
e: {
}
},
e: {...
1
votes
2
answer
22
Views
r: partially reshaping to wide table but keep key column
I would like to convert my current data frame into a wide table by spreading out Lag but also keep the variable agent. The number in most of the cells of the wide table is sales.
library(reshape2)
set.seed(123)
day = rep(seq(as.Date('2019/01/01'), as.Date('2019/01/04'), by='day'), each = 5)
agent =...
1
votes
2
answer
10.3k
Views
JSON List of Tags/Values
I am working on a project that requires an object to have multiple values. For instance, a list of 'things' all with a name but each thing also has another category, 'Tags' with could include things like round, circle, ball, sport, etc. all words describing what the 'thing' is. I am trying to define...
-1
votes
0
answer
4
Views
My DFS graph methods won't go from int to String
I wrote a StringfromInt method to change my ints to Airports. When I implemented the method into those methods with the ints everything worked out great! But when I implemented the same method into my DFS graph methods the output doesn't look all that good.
public void printPaths(int s, int d)
{...
1
votes
2
answer
531
Views
How to create a map of character and dynamic ArrayList in Java
I want to create a hashmap defined as HashMap.
What I am trying to do is to read a set of strings which I am reading into a list.
From this list I want to generate this hashmap.
So if strings are something like this
Andy,Aman,Rocky,Ravi,Nick etc.
Map should be like
A->[Andy,Aman]
R->[Rocky,Ravi]
N->...
1
votes
2
answer
200
Views
How to find out all missing time slot(s) on a day
Is there any algorithms to find out all missing time slots on a day.
Given that there are four time slots which are selected.
e.g. Expected input: 08:00-1259, 13:45-17:15, 14:15-19:00, 20:00-23:33
I would like to find out all missing time slots based on the four time slots being selected with below...
1
votes
1
answer
68
Views
Firebase Database - Share Data When UID Unknown?
In Firebase Database; If user_a has data they can access and they want to share this data with user_b, what is the best practice and database structure for securely sharing this data between specific users?
Important: user_a doesn't have any information about user_b account, e.g. uid.
Detailed Examp...
1
votes
3
answer
36
Views
how can I remove objects by attribute within a Linked List?
How could I remove an object inside a Linkedlist. I have a class account with studentId and studentName. I enter the objects inside the list, but when I try to remove I do not know how to do it. Because every time you remove an element from the middle of the list it gets organized, meaning the index...
1
votes
3
answer
77
Views
Name of a Data Structure
Here is the problem description:
I have an object that represents a unit of work (Uploading a large amount of data to a server). The objects should be processed (Uploaded) in a FIFO sequence (Queue) one at a time. Once an object is done being processed it needs to signal to the next object in line t...
1
votes
3
answer
92
Views
Any python package to speed up for loop computation?
I have two lists L and C, both sorted from smallest to largest. L contains positive integers, C contains both positive integers and positive fractional numbers (e.g. 0.01,0.05,..,100). Length of C is fixed at 6000+, length of L is variable (between 2 and 3000).
The goal is: given some constant M, fi...
1
votes
3
answer
61
Views
Find no of possible formations of explosive mines in a 2D matrix where some cells contain info about even/odd mines are adjacent to them
I am trying to make game involving 2D grid where given some hints a player can avoid cells containing explosive mines. I have come upon a particular scenario where given certain hints, i want to know how many formations of mines are possible.
Let there be a 2D matrix. Each cell may be empty or may c...
1
votes
1
answer
43
Views
Is there a difference between a linked list implemented using Box<T> and &'a T?
I'm struggling trying to understand the difference between these two implementations of a linked list. This first version is the one presented in the Rust book using a Box:
enum List {
Cons(i32, Box),
Nil,
}
This is the other implementation I was thinking of:
enum List
1
votes
5
answer
982
Views
Reading dynamic size strings from binary file
Say the structure for the file I want to read looks like this:
typedef struct {
char length;
char* text;
} name;
typedef struct {
long n_names;
name* names;
} file;
In the file there is first the number of names, followed by the list of names with dynamic lengths. So I need to allocate memory for th...
1
votes
3
answer
1.1k
Views
Ruby Data Structure - Queue with Maximum
I'm looking for a Ruby data structure with the following characteristics and am hoping to not have to roll my own:
First-in-first-out (i.e. a queue)
Allows specifying a max length
When the queue reaches capacity, the new item is pushed in and the oldest item is discarded.
I thought SizedQueue might...
1
votes
0
answer
265
Views
Priority Queue that uses a comparator and has decrease key operation
So I have a problem where I have a set of objects with two fields. I need to be able to get the min object of the set at a fast time time (using a custom comparator). The problem is, when I get the min object set, it changes the fields of some objects in my original set. Thus, the ordering of the se...
1
votes
0
answer
145
Views
Both methods have same erasure, yet overrides the other
I'm trying to implement a Queue but my method 'enqueue(E e)' is giving me an error saying that the method clashes with the method in the Queue interface but neither override the other. What is going on?
Here is the Queue Interface
public interface Queue {
/**
* Returns the number of elements in the...
1
votes
1
answer
1.8k
Views
HashSets and HashTables in Python
Is there any HashSet implementation in Python? I know HashTable can be represented using dictionaries, but how do we represent HashSet implementation.
I am NOT looking for a data structure with the same methods as HashSets but rather someone with a CONSTANT lookup time, or the order of O(1);
Also,...
1
votes
2
answer
83
Views
How to dynamically insert strings in my linked list?
My C program should read an input file and save it line for line in a linked list, then printing it. But when it's inserting the next line in the list, all elements in the list become the new element.
Input:
abc
def
ghi
Output:
ghi
ghi
ghi
I'm not sure but my guess is that it's not correctly a...
1
votes
1
answer
18
Views
Designing data structure which can decrease range in lgn
I was asked in an exercise to design a data structure which can handle the following methods in logarithmic time complexity (lgn):
Insert(x): Inserts x to the data structure
Find(x): Finds if x exists in the data structre
Decrease(x, y): Adds negative value y (y
1
votes
0
answer
35
Views
AVL tree insert case need a clarify
I read several online document about implementing AVL tree using balance factor(Not using a height data field in Node structure), when insert into the tree, there is one case I could not figure out.
The document is from here(also from here has similar function) , the balance factor is defined as hei...
1
votes
0
answer
43
Views
How to calculate set intersection of items between large number of users in a NoSQL database?
I am facing an efficiency problem trying to calculate set intersection of items between different users. Let's say that a user, called Bob, owns different items he would like to trade with other items other users own. Bob has an inventory and a wishlist. Now if Bob wants to obtain an item, say item...
1
votes
0
answer
51
Views
Finding subsets of a set of points that are all a maximum distance from each other?
I have a csv file with the following format:
thing1_id, thing2_id, similarity
The similarity is between 50 and 100. I've filtered out all pairs with similarity less than 50, but I do have the full set where the lowest is around 25. There are duplicate comparisons at the moment, i.e. thing1-thing2 is...
1
votes
0
answer
85
Views
I am getting a Bus Error 10 while implementing a Queue
Can Someone tell me why am I facing a Bus Error 10 in the following code.
The code below implements a Queue using circular linked list.
I am inserting 3 and 5 into the list and later remove thrice from front. I have handled corner cases too.
Thanks,
Priyam Dhanuka
#include
using namespace std;
clas...
1
votes
0
answer
235
Views
Is there a hash tree designed for complex data structures?
I have a JSON object with private data. It has the following (complex!) structure:
{
name: 'JB',
age: 35,
children:
[ {
name: 'Alice',
age: '5',
favColor: 'pink'
},
{
name: 'Bob',
age: '8',
favColor: 'blue'
},
{
name: 'Charlie',
age: '9',
favColor: 'green'
},
]
}
I want to create a hash tree tha...
1
votes
1
answer
76
Views
how to get values as per mixed attribute column set for products in sql
I have been struggling to get the desired output from the mysql db. First Please take a look at my table structure
EDIT: HERE IS MY SCHEMA
http://rextester.com/edit/NNCZ7986
Now when i run the below mentioned query, i get the results as below
Select a.prodid,a.product,b.catid,b.category,d.attvalue,...
1
votes
0
answer
37
Views
Can Merkle tree tell if more than one copy of the object exist in it?
With Merkle root hash, and Merkle path, one can verify if a given object (i.e a transaction) exist in a Merkle tree. But is it possible to tell there is no other duplication of the object in the tree.
For example, if I have the Merkle root of a list of transactions and the Merkle path of one transac...
0
votes
1
answer
28
Views
Manipulating pointer to array of pointers
Trying to write a C snippet to store and retrieve an array of structure pointers. I have copied my snippet bellow.
What I am trying to do here-
method Xos_get_cb_info_from_handle() should return the pointer to
the base address of the structure localclient.exit_cb. Which seem to
work.
After getting t...
1
votes
1
answer
224
Views
Circle Packing in R - Data structure
I try to replicate this circle packing example in R: Visualizing hierarchical data with circle packing in ggplot2? on my own data, but I bumped into a problem that I could not comprehend.
The data is:
Religion
1
votes
2
answer
75
Views
Create Class of Lists in Python
I have to extract patient information from a bunch of XML files for further data analysis.
I have multiple Patients that can have multiple Diseases . For each Diseases there may or may not have been a Treatment or several. Each Treatment may or may not have TreatmentDetails. The TreatmentDetails are...
1
votes
1
answer
38
Views
How to get links from website, not seen in view source
I am still beginner, I searched in Google but I didnt found what I want,
I have a website http://www.example.com/index.php
On the main page, there is selectio form:
e.g. one selects first country in first field, the the city in the second field then click the button to show the data.
I didnt find th...
1
votes
1
answer
102
Views
Choose the right data structure for my algorithm in java
Today i need to choose the most efficent data structure for my needs in java.
Basically i have an algorithm that have a set of .
First multiple thread create some of this set, than they get merged,
sorted by the Integer and removed eventual duplicate Object in the
result set.
Than for each element...
1
votes
0
answer
39
Views
How to organise components of a no framework project?
SHORT VERION: Where is the common place to store the controllers for dependencies in PHP?
LONG VERSION: I need to create a project at a high quality, coming from a framework background my knowledge on directory structure is a bit rusty and I would like some help.
Current Directory Structure: https:/...
1
votes
1
answer
41
Views
Why would I need stacks and queues for Depth First Search?
I'm working on a project from the Berkeley AI curriculum, and they require me to use stacks, queues, and priority queues in my Depth First Graph Search implementation. I stored my fringe in a priority queue and my already visited states in a set. What am I supposed to use stacks and queues for in th...
1
votes
1
answer
27
Views
If a string is used as a key in a hashtable , how does it provide O(1) time access to the contents corresponding to that key?
Since we need to traverse the string itself , how can a hashtable provide O(1) access ?
1
votes
1
answer
482
Views
How to structure Shopify data into a Firestore collection that can be queried efficiently
The Background
In an attempt to build some back-end services for my e-commerce (Shopify based) site I have set up a Firestore trigger that writes order details with every new order created which is updated by a web hook POST function provided by Shopify - (orders/Create webhook).
My current cloud fu...
1
votes
0
answer
37
Views
Is it possible to use recursion on a Stack to obtain the same functionality of a Dictionary
I'm working on a programming assignment which requires measuring the nested depth of HTML tags. This is an easy task for a dictionary however we are meant to be using Stacks and ArrayLists for learning purposes. I'm wondering if it would be possible to implement a stack with the same functionality o...
1
votes
1
answer
82
Views
Swap Nodes in Pairs
I am currently brushing up and reviewing my datastructures as I prepare for job interviews. I am currently working on this problem where I have to swap every 2 nodes in a Linked List. My code is as follows:
public ListNode swapPairs(ListNode head) {
ListNode dummy = new ListNode(0);
dummy.next =...
1
votes
2
answer
88
Views
String class istream issues
I am having trouble getting my string class working. My istream function seems to read the data in, and I confirmed that the += was adding the characters, but after the first character, what is added is garbage. I have tried everything I can think of to get it working. Can someone please provide...
1
votes
2
answer
52
Views
Linked List - How a single object is storing so many addresses one after other?
I learn about data structures and Linked Lists and I don't understand something. How can a single object store so many addresses and datas. When I learned about object I saw that you need to create new objects if you want to store many datas for a single variable, but now at Linked List, the newNode...