# data-structures

## How to calculate range of any datatype while casting it

For example, a question in my paper came like this
in java: byte’s range is -128 to 127
byte x = (int) 300;
what will be the value of x?
How can I calculate this thing on paper?

## LRU with arrays – R&D

Why LRU uses linked list ? Can’t we use array to store items, so item with most frequently used will be stored at front of array & least at last of array.
The only reason i can think of not to use array – is that when removing/updating…

## I am struck at the question in c++, maximum size of L shape formed in a binary matrix?

test cases
[[True, False, True, False, False, False, False, False], [True, True, True, False, False, False, False, False], [True, True, True, False, False, False, False, True], [False, True, True, True, True, True, True, False], [False, Tr…

## If the elements of the list point to same memory address, how are the two list not referring to the same object?

I initialize two lists as follows:
>>> a = [1]
>>> b = [1]

Then I find the memory location of the elements at index 0 for both the lists:
>>> id(a[0])
93961440619840
>>> id(b[0])
93961440619840

## What is the time complexity of passing a Vector of size n to another function by passing by value and passing by reference?

void fun(vector<int>vec)
{
some code
}
int main()
{
int n = 5;
vector<int>avec(n);
fun(avec);
}

What is the time complexity of passing a Vector of size n to another function by passing by value and passing by refer…

## Internal data structure of tuples and lists [closed]

How does the internal structure of a list differ from that of tuples ?
There are similar questions on stackoverflow but none answer the question to my satisfaction.
I read this and this which say that lists store reference to the objects t…

## I want to represent by figures of different shapes a tree in my javfx window

I have a tree where I save files, the root is the selected folder and its children are the folders within it, what I need is that based on the space of the child nodes of the root, frames are made that occupy the entire window based on to …

## Custom print() of DynamicArray in Kotlin prints unexpected result

I have a simple scenario where I have Kotlin class DynamicArray.kt:
class DynamicArray(size: Int) {

private var numArray: IntArray
private var count: Int = 0

init {
if (size <= 0)
throw IllegalArgumentE…

## parallel resistors in graph node representation of electric circuits python

So I have this objects: Resistor, Voltage Source, Node and Graph. My main goal is to represent some graph from an electric circuit and I have this problem: when I add the weight for the parallel nodes from Node2 to NodeRef clearly R2 resis…

## How allocation of memory for `list` works in Python? Why size of list is 4 Bytes more than combined sum of objects?

Input
import sys

a=[1,2,3]

print(id(a))
print(id(a[0]))
print(id(a[1]))
print(id(a[2]))

print("=================")

print(sys.getsizeof(a))
print(sys.getsizeof(a[0]))
print(sys.getsizeof(a[1]))
print(sys.getsizeof(a[2]))

Outp…

## Best way to create gigantic list of constants?

I want to have a huge dropdown list, for example a user can select/search their favorite species in the entire world. There are 8.7 million species. Let’s say I bring this number down to 500k or 1 million. Should I use enum? An enum genera…

## 2 smallest subarrays with greater than or equal to required sum

I am struggling with the problem mentioned. I am fairly new to algorithms and such problem solving. My college professor gave me few problems to practice and it is one of them. I have tried following approach :-

Sort array in increasing o…

## Can Anyone explain why is this testcase not working

The problem is Given Two Binary Trees, write a function that returns true if one is mirror of other, else returns false.
Now I wrote this solution
int areMirror(Node* a, Node* b) {
Node* t1 = a;
Node* t2 = b;
queue<Node*>q1;
queue&lt…

## How to combine data arrays by multi longitude and latitude in one dataset in python

I made for loop of my data array of each long/lat point and I appended all result in one list as below :
out_list=[]
for i in ds.longitude.values:
for j in ds.latitude.values:
point = arr.sel(longitude=i,latitude=j)

## How do you create this tree data structure one item at a time?

Here is the way this data structure / algorithm should work (each line is 1 step):
1. []
2. [1]
3. [1, 2]
4. [1, 2, 3]
5. [[1, 2, 3], [4]]
6. [[1, 2, 3], [4, 5]]
7. [[1, 2, 3], [4, 5, 6]]
8. [[1, 2, 3], [4, 5, 6], [7]]
9. [[1, 2, …

## Find k th index character of a binary string obtained after N iterations. In each iteration – ‘0’ becomes ’10’ and ‘1’ becomes ’01’

I am trying to identify a solution (preferably in JAVA) for the given scenario :
Input :

Binary String : e.g. "1001"
N – Number Of Iterations
K – String index position

After each iteration, all the 1s become "01" and …

## What shall I do to create a binary tree by taking depth as input in java?

In my case, I want to create a binary tree by taking the depth as the input.
For example, if I do tree.create(3), there will generate a binary tree when the depth of the deepest left is three, which means there will be 2^3 – 1 nodes in the…

## How to find the height of a binary search tree java

I have a BinarySearchTree made of Strings which I have my methods to find the height, insert etc. But I am having difficulty to implement it in the Main class, since my findHeight method requires a Node and I am trying to pass a String in …

## C – Graph – How to add root check for finding Articulation Points

so basically I implemented a code to find articulation points in a graph, I’m using Adjacency List to implement the Graph. Everything works, except for the starting point. It’s children is gonna have it’s low same as the root’s num so I ne…

## optimal BST and using height instead of depth

we know about optimal BST. k1<k2<…<kn and f(1),…,f(n).
I apply a change on that problem.
Input: keys[] = {10, 12}, freq[] = {34, 50}
There can be following two possible BSTs

10 12
\ …