Well I just began learning data structures and i have problems getting the right value for cociente, everytime i run it, cociente is printed as 1 but that is no the value i want to assign it, this is the code where i print: printf("\nEl valor del cociente es: %d",(polinomio_->polinomio->cociente));....

I am trying to understand how these data structures actually are visualized. It is said that TreeMap puts the entries in natural order [of keys] and LinkedHashMap puts entries in the order in which they are inserted. My question is, does the iteration over each of these data structures mean...

I have a long sequence of order amounts, 1000, 3000, 50000, 1000000, etc. I want to find out all orders whose amount is more than 100000. Simplest solution can be iterate through full list and compare and put matched on into another list which will give you all whose amount...

I need to load a text file of information into Java. The Text file looks like this "reproduce": { "VB": 7 }, "drill": { "VB": 8, "NN": 16 }, "subgross": { "JJ": 2 }, "campsites": { "NNS-HL": 1, "NNS": 1 }, "streamed": { "VBN": 1, "VBD": 2 } It is...

I was going through a circular queue post, and it mentioned about re-buffering problem in other queue datastructures. In a standard queue data structure re-buffering problem occurs for each dequeue operation. This problem can be solved by joining the front and rear ends of a queue to make the queue...

Suppose there is a point cloud having 50 000 points in the x-y-z 3D space. For every point in this cloud, what algorithms or data strictures should be implemented to find k neighbours of a given point which are within a distance of [R,r]? Naive way is to go through...

I have dictionary and I need get duplicate values. For example: Dictionary<int, List<string>> dictionary = new Dictionary<int, List<string>>(); List<string> list1 = new List<string> { "John", "Smith" }; List<string> list2 = new List<string> { "John", "Smith" }; List<string> list3 = new List<string> { "Mike", "Johnson" }; dictionary.Add(1, list1); dictionary.Add(2, list2); dictionary.Add(3,...

I plan to make a class that represents a strict partially ordered set, and I assume the most natural way to model its interface is as a binary relation. This gives functions like: bool test(elementA, elementB); //return true if elementA < elementB void set(elementA, elementB); //declare that elementA < elementB...

I'm currently writing a Macro for Excel. First I want to read my variable settings from row 20 from my sheet "Filter" into my variable "test": ' Define Last Column with a value LastCol = Sheets("Filter").Cells(20, Sheets("Filter").Columns.Count).End(xlToLeft).Column Col_Letter = Split(Cells(1, LastCol).Address(True, False), "$")(0) ' Read Data into variable test =...

Checking in java and googling online for hashtable code examples it seems that the resizing of the table is done by doubling it. But most textbooks say that the best size for the table is a prime number. So my question is: Is the approach of doubling because: It is...

I need to create a structure in MATLAB which is like this: under the main struct there are 3 sub-structures: Left, Right, Center. Under Left and Right there are 18 sub-structures each (A,B,C,D,E,...), and under Center there are 5 sub-structures. Under each of the 18 and 5 sub-structures I have...

I know how to insert integers into binary search tree Smaller to the left Larger to the right But that formula would be applicable only if Data/Key is integer. So i want to know how do i insert strings into BST I have searched the google but couldn't find any...

13,5,2,9,8 and 1 are inserted into data structure in that order. An item is deleted using only a basic data structure operation. If the deleted item is 1, the data structure cannot be ? a. Priority queue b. Stack c. Queue d. Search tree Thanks in advance !...

This is likely a simple concept for those who have worked with VB/VS for a while. I am plotting XY-style data on a scatter plot. Each set of data (Scan) has three columns of double precision data points: Potential, Current, and Time, not necessarily in that order. Each set contains...

As you know, different vendor may have different name of data field. Although the name is difference, the data struct is almost the same. For example, struct s1 { int s1Price, int s1Volume }; struct s2 { int s2Price, int s2Volume }; Like stock market data, the data would sent...

What are the uses of heaps? Whatever a heap can do can also be done by a self-balancing binary search tree like an AVL tree. The most common use of heap is to find the minimum (or maximum) element in O(1) time (which is always the root). This functionality can...

I had a question about whether or not Java has its own data structure for what I am looking for. It is something like a combination of an array, linked list and a tree. If it is not in Java, but exists already as a concept in computer science/other languages,...

A linear data structure traverses the data elements sequentially, in which only one data element can directly be reached. Ex: Arrays, Linked Lists. But in doubly linked list we can reach two data elements using previous pointer and next pointer. So can we say that doubly linked list is a...

I'm trying to write an implementation of bubble sort to sort a linked list, but at the moment it's causing my program to crash. Here's how the structures are defined: typedef struct shopping_cart cart; struct shopping_cart{ char *item_name; int quantity; cart *next; }; And here's my code: void sort(cart *head){...

This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers I have a homework about implementing queues in java. I have written a code, but there is an error and I don't know how to fix it. Can...

I have the following problem: You are given N counters, initially set to 0, and you have two possible operations on them: increase(X) − counter X is increased by 1, max counter − all counters are set to the maximum value of any counter. A non-empty zero-indexed array A of...

I'm new to php and I have learnt that to create a structure, I can take help of array as: $MyStructure = array ( 'id' => '12345', 'name' => 'myName'); I also know, to write into a file, I can use: file_put_contents($fileName, $myTextToSave, FILE_APPEND); But, this function stores it in...

Say my list is the following: ['cat','elephant'] How can I efficiently convert my list into an array of boolean elements, where each index represents whether a given animal (of 10^n animals) is present in my list? That is, if cat is present index x is true and if elephant is...

Suppose an initially empty stack S has performed a total of 25 push operations, 12 top operations, and 10 pop operations, 3 of which returned null to indicate an empty stack. What is the current size of S? I'm thinking that S.size =7 because 10 pop operations have 3 out...

I've written a program for class which takes in data from a URL, parses it for key phrases and then writes to a text file the phrase, line number, and column number. Currently I am doing this as a single operation where the URL is fed to a BufferedReader for...

I'm building a text editor using doubly linked lists. These are my structs: #define N 4 typedef struct node { char data[N]; int size; struct node* next; struct node* prev; }node; typedef struct text { struct node* head; struct node* tail; int count; int size; }text; This is the piece...

Lately I've been writing a lot of code in C and I've noticed, that the thing that takes most time in my programs is resizing dynamic data structures. Let's say we have an array with characters and I want to append some characters to the end of this array. I...

I have a very huge dictionary that is serialized in the hard disk. I don't have enough memory to load it completely in memory. I need to read only a particular range of the dictionary (say 100th - 200th element in the dictionary). Is it possible to load only these...

Is it possible to create a function that takes a list of elements of any imaginable type and returns an operator that can act as a comparator for ordering the elements? In other words, template typename<T> ??? getComparator ( T a ) { // ... } where I put ???...

I am newbie to Python. Here is my Code that implements binary search to find the guessed number .I cant figure it out correctly how to make my code work. Any help would be appreciated. Thanks. print"Please think of a number between 0 and 100!" guessed=False while not guessed: lo=0...

I have several JavaScript arrays, each containing a list of pointers to objects. When an object meets a certain condition, its pointer must be removed from its current containing array and placed into a different array. My current (naive) solution is to splice out the exiting array elements and concatenate...

I am trying to impliment Queue using linked list but it goes stops unexpectidly. could not find why? #include <iostream> #include <string> using namespace std; Class Node for creating a node. class Node { public: int data; Node *next; }; Queue Class containing operations for Queue. class Queue{ private: Node*...

I created a singly linked list: #include <iostream> using namespace std; struct Node{ int data; Node *next; }; bool isEmpty(Node *head){ if (head == NULL){ return true; } else{ return false; } } void append(Node *head, Node *last, int data){ Node *newNode = new Node; newNode->data = data; newNode->next =...

Given a number N find the biggest possible number X that can be created from the given number digits. Example: N=231 then X will be 321. The restrictions are time complexity O(1) and space complexity O(1). I think this has to be done with counting sort. ...

I created a LinkedList class with a function delete to remove a certain node from the list if found, however it's not working: public class LinkedList { public Node head; <...> public void delete(string n) { Node x = search(n); //returns the node to delete or null if not found...

I am trying to figure out the solution for the above given problem. I came up with a solution, but I am not sure if that will work successfully. public Node LinkedListOfNodes(Node root, Map<Integer, LinkedList<Node>> mapOfLinkedList, int level) { if(root == null) { return null; } final LinkedList<Node> linkedListOfNodes =...

I'm using a structure for my DES Algorithm: typedef struct { int size; int capacity; unsigned char *block; }Blocks64; I already did a lot of things to it, so i have some information on the unsigned char. I'm in a function that i call it iterations, and i need to...

int myStrCmp (const char *s1, const char *s2) { const unsigned char *p1 = (const unsigned char *)s1; const unsigned char *p2 = (const unsigned char *)s2; while (*p1 != '\0') { if (*p2 == '\0') return 1; if (*p2 > *p1) return -1; if (*p1 > *p2) return 1;...

I want to know which algorithm is used by the following Applications or WebSite for String Pattern Matching, I have already search by title but nothing found, i want to learn and understand the real time implementation of String Pattern Matching algorithm used by various Applications. 1.Notepad 2.Adobe Reader...

I want to get the maximum width of a Binary tree. In this method using Pre-order traversal width can be calculated. But I can't understand it properly. Please explain how the function getMaxWidthRecur() works. // A utility function that returns maximum value in arr[] of size n int getMax(int arr[],...

Mind the following code: -- A n-dimensional axis aligned bounding box. data AABB v a = AABB { aabbMin :: !(v a), aabbMax :: !(v a) } deriving (Show) -- `v` is a container, representing the number of dimensions. Ex: -- type Box2DFloat = AABB V2 Float -- type Box4DFloat...

In our business scenarios, we have a job queue, one producer process and several consumer processes.The producer only put new jobs into the queue when all consumers has no job running. The consumer may die or stuck. If that consumer not working any more, the producer should consider this dead...

Following basic principles what would be the preferred way to structure a program and its data that can variate but is used to accomplish the same "standard" task? It should easily be extendable to include more providers. For example: require 'mechanize' require 'open-uri' class AccountFetcher @@providers = {} @@providers['provider_a'] =...

I am looking for a data structure to represent hierarchy class system in Java. For example, I have three class, University,Major,Student, and their relationship looks like below. Is there a efficient data structure that I can query with a path-like expression? For example, if the expression is CMU/cs/jake，then I get...

I need to store key-value pairs inside key-value pairs and so on as required by the data. I tried to achieve this using Hash-Map in java but it didn't work as I expected it to. Since, my data has multiple name->value pairs, but the Hash-Map keeps overwriting the name key's...

In chapter 14.2, page 620, in "Big Java" (International 4th edition), by Cay Horstmann, it is shown how to implement a linked list. The add method of the listIterator looks like this: public void add(Object element) { if(position == null) { addFirst(element); position = first; } else { Node newNode...

In an exam I see a question: Which one of the following is true? For a binary search, the best-case occurs when the target item is in the beginning of the search list. For a binary search, the best-case occurs when the target is at the end of the search...

I wish to have a 2-D data structure to store SAT formulas. What I want is similar to 2-D arrays. But I wish to do dynamic memory allocation. I was thinking in terms of array of vectors of the following form :- typedef vector<int> intVector; intVector *clause; clause = new...

I'm learning about hash tables and quadratic probing in particular. I've read that if the load factor is <= 0.5 and the table's size is prime, quadratic probing will always find an empty slot and no key will be accessed multiple times. It then goes on to say that, in...

i have to implement the data structure 'Linear Hashing' for my algorithms course, but i ran into some problems. I have implemented the add-function straight forward. I have to use the following hashfunction: h(x) = x mod 2^d My testvalues are: 24200, 16448, 16432, 4044, 24546, 10556, 29009, 25270, 32579,...

Given a B-tree such that in every node there are at most t keys and n nodes, I know that I can search the tree in O(t*h) where h is the height of the tree. Is there a way to that in O(log(t)*h)?

Redis Cluster supports sorted sets. How is the replication login implemented if used with a replication factor > 1? Is the master node forwarding all actions applied against the sorted set to the replica nodes or is there some other mechanism (e.g. copying the whole set over the wire everytime...

I'm making a function that returns the derivative of a function that is represented as a tree like / + \ * ^ / \ / \ x 5 3.14 x with nodes of the form typedef struct node { char * fx; // function struct node * gx; //...

I'm trying to understand closures, but literally every definition of a closure that I can find uses the same cryptic and vague phrase: "closes over". What's a closure? "Oh, it's a function that closes over another function." But nowhere can I find a definition of what "closes over" means. Can...

This Question is part of ongoing Competition , I have solved the 75% of this Question Data Set but the 25% is giving me TLE. I am asking why it's is giving TLE an i am sure my complexity is O(n*n)Question: String S consisting of N lowercase English alphabets. We...

Write four O(1)-time procedures to insert elements into and delete elements from both ends of a deque constructed from an array. In my implementation I have maintained 4 pointers front1,rear1,front2,rear2. Do you have any other algorithm with less pointers and O(1) complexity ? Please explain....

I have an existing database with a table that I need to alter. Due to some recent changes requested, I need to take two columns out of a table and put the data from those two columns into an existing column in the table. Thankfully, they are all Varchar type...

I want to build several hashes using the same keys and for the keys to have the same order when I print them. So, in the example below, the keys of $hash1 and $hash2 should always have the same order, but there should be no need to keep that order...

I have a very simple problem: I need to check if a large (150k) list of strings contains a certain string. Order does not matter, and I only need to check if the list contains a string. What is the most efficient data structure to use?

I'm looking for a solution to read and write data from a file. The data is a list of video playback applications on the system containing there paths, name and a list of compatible video formats. The XML data structure looks like this. <player> <name>WMP</name> <path>C:\Program Files (x86)\Windows Media Player\wmplayer.exe</path>...

I'm trying to create an array of arrays of a special type in Julia. For example, I want to create a list that saves lists (arrays) of integer values. I need to know how to: Initialize an (empty) list for the arrays Use append!/push! to add an array of a...

I have a messy block of code like result = (node*)malloc(sizeof(node)); result->fx = (char*)malloc(sizeof(char) * 2); result->fx[0]='x'; result->fx[1]='\0'; result->gx = NULL; result->op = NULL; result->hx = NULL; where I initialize an element of type typedef struct node { char * fx; // function struct node * gx; // left-hand side...

I've am trying to read a large text file and output the distinct words in it along with it's count. I've tried a couple of attempts so far, and this is by far the fastest solution I have come up with. private static readonly char[] separators = { ' '...

Question :- removal of an edge from a given tree T will result in the formation of two separate trees, T1 and T2. Each vertex of the tree T is assigned a positive integer. Your task is to remove an edge, such that the Tree_diff of the resultant trees is...

I want to know the difference in performance between adding element in a TreeSet one by one versus adding elements in ArrayList and then transferring to TreesSet by .addAll() method. I know TreeSet uses Red–black tree as its data structure. Just want to know the basic internal workings of this...

For those not familiar with Disjoint-set data structure. https://en.wikipedia.org/wiki/Disjoint-set_data_structure I'm trying to find the no. of groups of friends from the given sets of friends and their relationships. Of course, there is no doubt that this could easily be implemented using BFS/DFS. But I choose to use disjoint set, I...

Recently, my questions were marked duplicate, like this , even if they weren't. So, let me start with following and then I'll explain my question. Why this question is not a duplicate? I'm not asking how to create a binary tree when inorder & preorder traversal are given. I'm asking...

template <class T> class Node { public: T data; Node<T>* prev; Node<T>* next; // default constructor (parameterized) template <class T> Node(T value) { data = value; prev = NULL; next = NULL; } }; template <class T> T CircularLinkedList<T>::RemoveAt(int p){ Node<T>* temp = head; if (head == NULL){ return 0;...

I am learning C++ and I appreciate your support by answering my question to help me to understand fundamental concepts. I am sure I need to learn many stuff, but I need a some advice to help me to find the right way. The problem I have is explained in...

I looked at this code: >>> _end = '_end_' >>> >>> def make_trie(*words): ... root = dict() ... for word in words: ... current_dict = root ... for letter in word: ... current_dict = current_dict.setdefault(letter, {}) ... current_dict = current_dict.setdefault(_end, _end) ... return root ... >>> make_trie('foo', 'bar', 'baz', 'barz')...

I have a homework about implementing lists in java. I have written a code, and a method about displaying the elements, but when I run it, it says there is an error in this method. can you please help me fix this? here is my code: public class Lista {...

What's the best way to iterate over the below two maps together? I want to compare two maps values which are strings and have to get the keys and values. HashMap<String, String> map1; HashMap<String, String> map2; ...

The following Python Red Black tree implementation takes ~2s to execute the test function, which doesn't make much sense since the tree height is 14 in the case as the test printed out. So.. I assume I did something stupid in the code. Could you please offer some tips to...

I am working in Matlab. I have defined: a(1).x=1; a(1).y=2; a(1).z.w=3; a(2).x=4; a(2).y=5; a(2).z.w=6; I am now trying to add the fields in the two structures a(1) and a(2) such that I get: c.x = 5; c.y = 7; c.z.w = 9; Any idea how I can do this in...

What is happening here? I'm getting Must use 'struct' tag to refer to type 'node' on the gx and hx lines of typedef struct node { char * fx; // function node * gx; // left-hand side char * op; // operator node * hx; // right-hand side } node;...

This is a code to push 0 and 1 and pop 1 and 0 again. However, it pops 2 and 2. I can't seem to figure out why. #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include "stackADT.h" int main (void) { STACK* stack; int data; stack = createStack (); int i;...

I wanted to learn about Data Structures so I decided to create them using Python. I first created a Singly Linked List (which consists of two classes: the actual List and the Node). A List consists of Nodes (or can be empty). Each node had a "next" value. When I...

How to implement two stack in one array A[1..n] in such a way that neither stack overflows unless total no. of elements in both stack together is n. PUSH and POP should run in O(1) time ? What's wrong with this algo ? //A[1...n], top1 is pointer pointing to top...

I'm struggling with following problem: Write function which for given binary tree returns a root of minimal height which is not BST or NIL when tree is BST. I know how to check if tree is BST but don't know how to rewrite it. I would be grateful for an...

I've implemented a red-black tree and then inserted 1,2,3,4,5,6,7,8,9,10 in it. But it seems that my tree is not balanced because the pre-order traverse looks like this: 4,2,1,3,6,5,8,7,9,10 and the in-order traverse: 1,2,3,4,5,6,7,8,9,10. And that means the root is 4 and the tree is not balanced! Here is my code....

According to above picture DFS should be: 0 1 3 5 4 2 but it's returning 0 1 3 5 2 (This is happening only for one case. What I am doing wrong here?) code: import java.util.Stack; public class DFSDetectCycleSelf { static int arr[][] = { { 0, 1,...

I have a simple code for finding the nth fibonacci series number. public class Recursion { static int num; public static int fib(int n){ num++; System.out.println(num); if(n<=1){ return n; } else{ return fib(n-2)+fib(n-1); } } public static void main(String...strings){ System.out.println(fib(100)); System.out.println("number of repetitions is "+num); } } I have done...

I need to use a data structure which can maintain the insertion order, do not store any duplicates and I can easily remove first element from it efficiently. public static LinkedHashSet<String> getData(TypeEnum flowType) { LinkedHashSet<String> listOfPaths = new LinkedHashSet<String>(); String prefix = flowType.equals(TypeEnum.PARTIAL) ? TypeEnum.PARTIAL.value() : TypeEnum.UNPARTIAL.value(); listOfPaths.add(prefix + LOCAL_PATH);...

I have a class that inherits the dict object. my_subclassed_dict = SubclassedDictionary({ "id": {"value1": 144 "value2": "steve", "more" {"id": 114} }, "attributes": "random" }) On initialization of SubclassedDictionary, I would like paths generated which match a certain condition. Hypothetically, if I was to make this condition, 'index all numbers above...

Let's assume we have a Data-Structure which consists of nested Data-Types, is there a way of printing the data-types like: Dict()<List()<Dict()>> Example Data-Structure with Values: complexDataStructure = {"FirstDict":[{"AnotherDict":[[1,2,3],[1,2,3] ]} , {"OneMoreDict":[[1,2,3],[1,2,3] ]} ]} >>> output Dict()<List()<Dict()>> You can see the nested Structure with its Values, I would like to print...

Consider this example of binary search tree. n =10 ;and if base = 2 then log n = log2(10) = 3.321928. I am assuming it means 3.321 steps(accesses) will be required at max to search for an element. Also I assume that BST is balanced binary tree. Now to access...

I have this function to calculate the shortest path using Dijkstra but the code is giving some errors in some test cases.i could bot find out the logical error in the code.Any help will be appreciated. int minDistance(int *dist, bool *includ,int no_of_vertices); int* shortestDist(int** graph, int src, int no_of_vertices) {...

I drew a picture to describe the data-structure I am looking for. What is the most efficient C++ way of declaring such a data-structure, where: The size is fixed in the first dimension and dynamic in the second. In the second dimension, it dynamically increases in size on insertion...

I am trying to find the maximum element in a binary tree.I have two classes and an inner class.Now when I call the findmax method in my first class from second class(i.e TreeMap) I need to pass root of the tree as an argument.I have inserted the elements in the...

I try my best to look up solutions to problems before asking on here, but I've hit a bit of a brick wall. While there is one for Java, it didn't help me enough to understand where I went wrong with my implementation. So without further ado, here's some background,...

When an element is inserted in a queue, REAR = REAR + 1. When an element is deleted from the queue, FRONT = FRONT + 1 when queues are implemented using arrays. Now, initially, both FRONT = REAR = -1 indicating the queue is empty. When the first element is...

I have a 3D array in R constructed as (although the names don’t seem to show up): v.arr <- array(1:18, c(2,3,3), dimnames = c("A", "B", "X", "Y","Z","P","Q","R")) and it shows up like this when printed to the screen: , , 1 [,1] [,2] [,3] [1,] 1 3 5 [2,] 2...

Given a BST, and a node in BST, make that node, as new root of the tree. But still maintain the tree as BST after making this node as root. I tried as follows: Take given node as root, if its on left of original root then make original root...

I am struggling to write a program in C. I want to disintegrate a number (only if it can be disintegrated) into a smaller numbers which can only be fibonacci numbers. For example : If I have a number n = 20 then my output should be 1,1,2,3,5,8 so when...

Looked around at several other questions and answers, but I can't seem to figure out how to apply it to my situation. Here is my setup: typdef struct sensor { const unsigned char pin; //otherVariables }Sensor; Sensor *left = new Sensor(); void initStruct() { left->pin = 1; //illegal initialization }...

I am trying to learn Scala and functional programming ideology by rewriting basic exercises. Currently I have trouble with naive approach for generating primes "trial division". The trouble described below is that I could not rewrite well-known algorithm in functional style preserving efficiency, because I have no suitable immutable data...

I'm new to python. I need a datastructure to contain a tuple of two elements: date and file path. I need to be able to change their values from time to time, hence I'm not sure a tuple is a good idea as it is immutable, and every time I...

I am given an array of numbers and allowed to preprocess them . There are 3 types of queries : Insert(x) which inserts an element "x" into the array. Delete(x) which deletes an element "x" from the array (assume x is present in the array) Find(x) which returns if "x"...

I have a TreeSet in JAVA which orders a custom datatype called 'Node'. However, the TreeSet does not order itself properly. A link to my complete implementation is at the bottom. Let me explain my probelm in detail first Here have a custome datatype 'Node'. It has 2 parameters as...

I have a map as shown below in which there is a key and values is of type List: Map<String, List<String> newdatamap = new HashMap<>(); map.put ("RtyName", Arrays.asList("wpn", "wpfnb", "dgeft", "xbthy")); map.put ("rtyRate", Arrays.asList("dd", "ww", "trrty", "httyure")) I'd like to add another map over the previous map, such that there...