Questions tagged [data-structures]

A data structure is a way of organizing data in a fashion that allows particular properties of that data to be queried and/or updated efficiently.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
32 views

Union Find by shared prime factor

I have an input array nums of integers in range 1 to 10^5 and this task: Your task is to determine if for every pair of indices i and j in nums, where i < j, there exists a sequence of traversals ...
CJR's user avatar
  • 3,092
-2 votes
0 answers
21 views

Can a linked list be used for dictionary implementation in spell checkers? [closed]

Im making a comparison between different data structures so, Is it fundamentally impossible to utilize a linked list as the underlying data structure for implementing a dictionary for Spell checker ...
computer science's user avatar
-1 votes
0 answers
24 views

How to implement sequential and direct access file search methods in Java? [closed]

Questions about files search methods in Java. Does anyone have a class or classes that show file search methods, both sequential and direct access? I'm trying to look for information on this, but I ...
Alexx_554's user avatar
0 votes
1 answer
17 views

"Understanding the deletion process for a node with two child nodes in a binary search tree"

In the given code, there is a binary search tree implemented using the nodes and binary classes. The delete method in the binary class is used to delete a node from the tree. I would like to ...
pragateesh's user avatar
-1 votes
2 answers
49 views

Minimum Edge required to connect a unconnected directed graph

I am trying to write an algorithm that finds the minimum number of edges that are required to be added to connect all nodes from the starting vertices in a directed unconnected graph #include <...
BlueBerryPie's user avatar
-1 votes
2 answers
45 views

why is it not able to find symbol for the function [closed]

public static void main(String[] args) { char A ='a'; char B = 'b'; char C = 'c'; toh(3, A, B, C); } public static void toh(int n, char source, char helper, char destination) { if(...
gourav pal's user avatar
0 votes
2 answers
33 views

Is there a way to optimize searching for specific keys in a hash table with multiple keys

search hash table with multile keys i have a hash table with 3 keys: source-address,destination-address and application-id. whenever a packet received will make this tuple and serach in hash table it ...
PanduRanga's user avatar
0 votes
2 answers
36 views

What is the purpose of initializing a dummy node in a ListSet intersect function?

@Override public void intersect(Set<E> set) { Iterator<E> iteratorSet = set.iterator(); Iterator<E> thisIterator = this.iterator(); SetNode<E> head = new ...
Tobias Chisi's user avatar
0 votes
1 answer
26 views

Further optimization to the algo for interleaving string

I am trying to solve LeetCode problem 97. Interleaving String : Given three strings s1, s2 and s3, write a program that checks whether s3 is an interleaving of s1 and s2. Problem Note: S3 is said to ...
curiousengineer's user avatar
0 votes
0 answers
21 views

Issues with BFS implementation using queues in Python resulting in attribute errors

i am trying to implement a BFS that queues and dequeues graph nodes to lists. The implemtation is below: def BFS(self): t = SNQ.DSAQueue() q = SNQ.DSAQueue() # Set all vertices as ...
patrickc's user avatar
-1 votes
1 answer
16 views

minimum and maximum number of comparisons needed when deletion in Binary Min heap

You are given a binary min heap of height p Let the minimum and maximum number of comparisons we might have to do when doing a delete min respectively are u and v. Then What will be the value of v-u?
glam videos opera's user avatar
0 votes
1 answer
21 views

How to identify double rotations in a AVL Tree when each node stores the deepest subtree beneath it?

I am working on an AVL tree such that each Node holds the deepest sub-tree beneath it. Here is an example of the tree, where the representation is value: height. 0: 2 \ 1: 1 \ 2: 0 To check ...
M. Nicol's user avatar
0 votes
2 answers
45 views

What is the length of the longest substring containing only 1 after setting at most one char to 1? [duplicate]

What is the length of the longest substring containing only 1 after setting at most one char to 1? For example, given s="1101100111", the answer is 5 #include <iostream> #include <...
Bharath Potluri's user avatar
0 votes
1 answer
30 views

Exponentiation of an array raised to the power of another array?

Consider I have a data structure called VeryBig having size and array of int type which can accommodate huge numbers. I have an array base->arr having elements 9,8,7,6,5,4,3,2,1 and another array ...
Chatur's user avatar
  • 5
0 votes
1 answer
38 views

What algorithm can I use to locate bottleneck paths in an undirected graph?

Given an undirectional graph, how would you be able to efficiently find all of its "bottleneck" paths? A "bottleneck" path is defined as a path that if destroyed, causes the graph ...
Jonathan L's user avatar
1 vote
1 answer
27 views

Can Fenwick Tree and Segment Tree in C++ perform insertions and deletions in logarithmic time?

I apologize in advance for what may be a really dumb question. I've been reading about fenwick tree and segment tree a lot recently (specific implementation of segment tree is here: https://cp-...
JohnZ's user avatar
  • 61
0 votes
0 answers
28 views

How to preserve order for cards in a Kanban board in Google Cloud NDB?

I'm building a Kanban board and I want to preserve the order of cards that appear on my Kanban board. I have explored the possibility of storing the keys of the cards in an Array attribute in an NDB ...
hassansuhaib's user avatar
-1 votes
0 answers
19 views

Binary tree reconstruction works only on the first iteration of a while loop

The following code (written in c) is supposed to take in multiple lines containing the pre-order and in-order traversals of binary trees and reconstruct them, until the user simply presses enter ...
Matheus Reato's user avatar
-4 votes
2 answers
55 views

Hidden test cases are failing for the question maximum sum of the subarray that starts and ends with the same value element code written in java [closed]

Given an ArrayList arr of n positive elements. Find the maximum sum of the subarray that starts and ends with the same value element. Note: A single value subarray can be considered as the start and ...
Prabhas Dasari's user avatar
-2 votes
1 answer
40 views

how to deal with linkedlist?

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ...
dhhhhhhh's user avatar
0 votes
4 answers
60 views

Split array object to nested array for each separator

I am trying to split the below array { "Base/Brand/0101-color-brand-primary-red": "#fe414d", "Base/Brand/0106-color-brand-secondary-green": "#00e6c3", ...
Sanjeev Hegde's user avatar
-1 votes
0 answers
33 views

I'm a web developer, do I need to study algorithms and data structures? [closed]

I am a non-regular web developer with about 4 years of experience. It mainly uses Java and spring frameworks. I'm a web developer, and I want to get your opinion on whether I need to study algorithms ...
likeyellowand's user avatar
1 vote
1 answer
31 views

BFS(breadth first search) compiler output is not following as per my understanding

I have python code for Breadth first search (bfs): from collections import deque def bfs(graph, start): visited = set() queue = deque([start]) # print('queue',queue) while queue: ...
Shreeya Sharma's user avatar
0 votes
1 answer
38 views

How does a binary search tree object print every element using recursion in Python?

class Node: def __init__(self, value): self.value = value self.right = None self.left = None class BinaryTree: def __init__(self): self.root = None def ...
pragateesh's user avatar
0 votes
0 answers
12 views

xml rpc request model in java [closed]

I tried to send a request to xmlRpc based server by using the XmpRpcClient but I couldn't build the request body which is : <methodCall> <methodName>method-name</methodName> &...
Anas Altarazi's user avatar
0 votes
0 answers
24 views

Relevance of a secondary extra temporary variable when tring to delete a node from linked list

Confused with free(tmp) function I am trying to understand the working of deletion function of a node from a singly linked list Why can i replace these 2 lines tmp=q->link; q->link=tmp->...
Midhun Raj's user avatar
1 vote
0 answers
65 views

Single goroutine read and write a map with different channels in a select is thread safe?

I'm trying to implement a session manager for my web app. It consists in a single goroutine that manages the sessions in an in-memory map to avoid requests to the database. I did not implemented the ...
Nico's user avatar
  • 858
0 votes
1 answer
27 views

How to Build and test if a graph data structure is outputting the correct adjacency vertexes WITHOUT the use of lists or dictionaries

I'm trying to build a graph data structure in Python, only something basic - but I'm having trouble testing if each vertex recognizes other vertexes are adjacent or not. I know how to do this with the ...
GDTeam's user avatar
  • 1
1 vote
2 answers
56 views

Combining Polygons in a Graph

I am currently working on a small project that requires me to calculate the Union of 2 or more given rectangles. The catch here is that the after combining the rectangles into a polygon, the result ...
Tanay Upreti's user avatar
0 votes
0 answers
68 views

How is HashMap.containsKey() in Java able to run in constant time?

This is the documentation for HashMap.containsKey(). As you can see, it uses getNode(). I could be wrong, but it looks like the the hash map is still being iterated through, which would be linear time....
Brendan B's user avatar
-1 votes
1 answer
38 views

minimum time to travel between stations

I have implemented a Java program that aims to find the minimum time required to reach each station based on the given bus schedules using Breadth-First Search (BFS). However, the program consistently ...
TaHaBH7's user avatar
1 vote
1 answer
82 views

How can I fix the count_words() function to create a proper linked list of words with their appropriate counts?

Below is my C code, and my question is: why, in the count_words function, the printf for word and (*wclist)->word are the same for all but the first word added? The count_words function is reading ...
Chris's user avatar
  • 13
-1 votes
0 answers
28 views

How to make it possible for the user to enter an index in this queue in c++? [duplicate]

This code that I wrote represents queue in C++ without using STL, so it prompts the user to input numbers that are the data of the queue, and then it asks the user to input the index of N, this means ...
Uber Batko's user avatar
-1 votes
1 answer
32 views

what is the relation between the a[i-1] of code actually mean can some one explain?

*the question was to rearrange an array such that even positioned are greater than odd positioned(1 indexing), what is this arr[i-1] term actually means here a index or a value less than arr[i] such ...
Sushmita's user avatar
3 votes
1 answer
60 views

Generate subset of length upto k

I have written down code that is able to generate subsets of an exact length 'k' from an input of length>'k' I am unable to actually come up with code that generates all subset up-to length 'k' ...
curiousengineer's user avatar
-1 votes
2 answers
52 views

Find the list of starting indexes of occurring of a string in another string in O(N) time complexity

Given are two strings : str1 and str2. Find all the starting indexes of str1 in str2. Example: I/p = str1: abc, str2: abckdabcgfacabc O/p = [0, 5, 12] public static List<Integer> ...
bugdebug's user avatar
2 votes
2 answers
75 views

Any alternate way to implement the peek method?

I am learning data structures on my own and have been trying to implement them using Java. Currently I am attempting to implement a array based stack. In the peek method when the stack is empty I am ...
paneer_curry's user avatar
0 votes
0 answers
19 views

Understanding 'del' with sequences [duplicate]

I have written below code: dict1 = {7: 'Java', 4: 'JavaScript', 3: 'Python', 1:"C#"} dict2 = dict1 del dict1 print(dict2) My understanding is that both dict1 and dict2 are referring to ...
meallhour's user avatar
  • 13.6k
-1 votes
0 answers
39 views

Why does my solution to the Two Sum problem throw an error in the test window but run correctly in PyCharm? [closed]

The problem is of two sum ,and its as follows :-(ALL THE IMAGES ARE ATTACHED) Two sum problem for the test case sum=0 and array=[2 ,-3 ,3 ,3, -2] , my solution throws an error in the test window ...
Akash's user avatar
  • 1
1 vote
1 answer
28 views

Efficiently convert list of probabilities in a list of 0/1 by taking a % of highest probabilities without reindexing

Problem Given a huge array of probabilities and the percentages to take probabilities = [0.1, 0.4, 0.7, 0.2, 0.9, 0.5, 0.6] N_percentages = [20, 30, 40] # Percentage of the list size I want to ...
Bartek Lachowicz's user avatar
0 votes
0 answers
4 views

Data structure query for parallel study using lme4

Fairly new to R, I'm wondering whether I am setting my linear mixed model up correctly. My outcome DV is score, and my fixed effect is intervention (placebo + treatment) and time(pre + post). The ...
Botanic289's user avatar
0 votes
1 answer
24 views

BST recursion remove delete java code moving the whole subtree

My BST remove code seems to have problem when removing with 2 children node, it removes the whole subtree. I went through the whole logic over and over again but couldn't find any errors. Here is the ...
VIZ's user avatar
  • 1
0 votes
0 answers
31 views

UnionFind datastructure

I am attempting to solve the following questions - The Earliest Moment When Everyone Become Friends There are n people in a social group labeled from 0 to n - 1. You are given an array logs where ...
Spindoctor's user avatar
-1 votes
0 answers
78 views

Why O(n) solution works slower than O(nlogn)? [closed]

There is Leetcode challenge to find a largest rectangle in histogram (https://leetcode.com/problems/largest-rectangle-in-histogram/). It can be understood via the picture below (taken from leetcode ...
RomanGirin's user avatar
1 vote
1 answer
77 views

Efficient algorithm to find elements with frequency greater than k in multiple sorted sets

I have a collection of n sorted sets. I have to find all the elements with a frequency greater than a given threshold k. I am looking for an efficient algorithm or approach that can handle the case of ...
Vishal Jangid's user avatar
0 votes
0 answers
29 views

sorting k block array in best time

Suppose we have an array consisting of k blocks. Each block is unsorted, but we have the knowledge that every block is smaller than all the blocks on its right and larger than the blocks on its left. ...
nopnop's user avatar
  • 1
-1 votes
1 answer
26 views

Binary Search Tree with Reading File

I am a student studying data structures. Here's my BST code. During the execution of the main function, the output is 1 2 3 4 ...and 's' is not output, and is a core dumped. Why is that...? Here is ...
YJMoon's user avatar
  • 3
-1 votes
0 answers
28 views

Contains() function seems not working properly for Array [duplicate]

I tried to find a specific element in Array and I used Contain() function for it but it seems not working properly. for example- int [] arr = new int[]{1,2,3}; System.out.println(Arrays.asList(arr)....
Shubham's user avatar
1 vote
2 answers
117 views

What is the memory format when writing an array, where the name of the array is a pointer, And what is the mechanism in that? C/C++

!!The question is a little long, so I divided it into 4 parts, so that the reader would not be distracted!! I got a piece of information recently, that the name of the array in C/C++ is a pointer to ...
ibrahim عبد العزيز's user avatar
0 votes
0 answers
20 views

What does "Uncaught TypeError: Cannot read properties of undefined (reading 'weight') at l.start (d3.v3.min.js:4:22672) at GraphTesting:102:5" mean?

I have been trying to dynamically populate an undirected graph by making use of matrices. I am using ASP.NET Razor Pages and in the view, I am using JavaScript to plot the graph and in the PageModel I ...
Finsser's user avatar

1
2 3 4 5
665