Skip to content
Advertisement

Tag: data-structures

How to convert String to Json Object in java or groovy

I saved a json into the database as a string like this: “[_district:_1_2_5village, _name:_1_1_2id_inter, _gender:_1_3_5sex]” Now i want to convert it back to a Json Object so as to pick the key and value eg _district is the key and _1_2_5village is the value. Any help on how i can achieve this. Thanks I tried to convert the string back

Add 2 list of objects and remove duplicate(all but one field different) elements from the final list

I have a object class like I have 2 lists 1st one is like {d1,m1,active}, {d2,m2,active},{d3,m3,acticve} 2nd one {d2,m2,paused},{d4,m4,paused} i want my final list to be like {d1,m1,active},{d2,m2,paused},{d3,m3,active},{d4,m4,paused} My approach was to make a list of commonName{d2} then add both the list{d1,d2,d2,d3,d4} into a total list and then iterate through the total list and if the common deviceName(d2.contains(i.getName())) matches then

How to implement Breadth First Search and Depth First Search for a SimpleWeightedGraph in Java

I need to implement Breadth First Search and Depth First Search for a SimpleWeightedGraph which contains String Vertices in Java Code below is my SimpleWeightedGraph where i implemented the following: declared SimpleWeightedGraph created vertices added vertices to the graph created default weighted edges, added edges and set Weights got and printed the shortest path from vertex “a” to vertex “e”

How does parameters of a method get stored in stack during a recursive call?

I was doing a leetcode question https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii/ and I am confused on how parameters for a method get stored during a recursive call. If a node gets visited, I wanted to save it’s state that it was visited. When I send two variables, when the stack is getting unwinded the updated variable values are being lost. But if I send

Method to get all the branches of a tree

I have an object from this Class: And I would like to write the JAVA method: private List<List> extractNames(Person ancestor) which gives back all the names of each branch of the tree: Do you have an idea, how I could do it ? Answer Update: Removed the dependency to lombok The relevant algorithm part is in the method extractNamesAlternative in

Checking a tree to be a BST

Here is my attempt to check whether a tree is a BST or not: Code works fine as tested with multiple test cases. But I am not sure if this is a good, clean approach. Recursive method is big it seems. I am dealing with scenarios like null left node, null right node, node itself null, both child nodes null

Java – HashMap for booking system

I have been given an exercise to develop an appropriate data structure to implement a tennis court booking system. A hashmap is what is required for this and I was given a diagram as a visual representation of the data structure. From looking at the diagram, I am unclear on how the Key and Value should be defined in the

Advertisement