## Understanding the Basic Operations of DHCP

I was studying about DHCP – and understood the Basic Operations of DHCP.

However how the client should behave when DHCP Ack contains different IP than in DHCP offer?

## Performance challenge: Box operations (HackerRank) (C, Python)

Recently I’ve been doing some challenges on HackerRank and came across this one. First, I tried with Python, and then C. Both of my codes failed due to timeout restrictions.

It would be very helpful, if someone can tell me what can be improved in (one of) my codes (performance-wise).

Thank you.

Challenge description: C code:

``````int minBox(int *box, int l, int r){
int min=box(l);
for(int i = l+1; i<=r; i++)
if(box(i) < min)
min = box(i);

return min;
}

int sumBox(int *box, int l, int r){
int sum=0;
for(int i = l; i<=r; i++)
sum += box(i);

return sum;
}

void operateOnBox(int *op, int *box){
switch(op(0)){
case 3:
printf("%dn", minBox(box, op(1), op(2)));
break;

case 4:
printf("%dn", sumBox(box, op(1), op(2)));
break;

case 1:
for(int i = op(1); i <= op(2); i++)
box(i) += op(3);

break;

case 2:
for(int i = op(1); i <= op(2); i++)
box(i) = (int) floor(box(i)/((float)op(3)));

break;
}
}

int main()
{

int n, q, *box;
scanf("%d %d", &n, &q);

box = (int*) malloc(sizeof(int) * n);
for(int i = 0; i<n; i++)
scanf("%d", box+i);

for(int i = 0; i<q; i++){
int op(4);
scanf("%d %d %d", op, op+1, op+2);

if(op(0) == 1 || op(0) == 2)
scanf("%d", op+3);

operateOnBox(op, box);

}

return 0;
}
``````

Python 3 code:

``````def operate(op, box):
if op(0) == 3:
print(min(box(op(1):op(2)+1)))
elif op(0) == 4:
print(sum(box(op(1):op(2)+1)))
elif op(0) == 1:
box(op(1):op(2)+1) = map(lambda x: x+op(3), box(op(1):op(2)+1))
elif op(0) == 2:
box(op(1):op(2)+1) = map(lambda x: math.floor(x/op(3)), box(op(1):op(2)+1))

if __name__ == '__main__':
nq = input().split()

n = int(nq(0))

q = int(nq(1))

box = list(map(int, input().rstrip().split()))

for i in range(q):
op = list(map(int, input().split()))
operate(op, box)
``````

## What is the suitable file structure for database if queries are select (relational algebra) operations only?

Searches related to A relation R(A, B, C, D) has to be accessed under the query σB=10(R). Out of the following possible ﬁle structures, which one should be chosen and why?
i. R is a heap ﬁle.
ii. R has a clustered hash index on B.
iii. R has an unclustered B+ tree index on (A, B).

## turing machines – Can an \$NDTM\$ simultaneously perform a set of operations on all strings of a given length?

Can an $$NDTM$$ perform a set of operations on all strings of a given length $$b$$, at the same time? Aka can it operate on all strings of a given length by doing something like: spawn $$2^b$$ branches then operate on each string of length b on each branch?

How could it do this tho if the branches can’t communicate? That’s what I’m having a hard time with. How does any given branch, if it doesn’t know what strings the other branches are running, know what string to run the operations on (so that all the strings are covered by $$2^b$$ branches)?

## object oriented design – Should I do database CRUD operations in classes instead of main.py?

This is an app design question. I’m new to OOP coming from writing functional monolithic scripts in Powershell as a windows server admin and need some help on best practices as I begin with OOP.

I am writing an app that does some statistical compilation and need to do some database CRUD with data collected from an online API.

I have a Main.py and one class file called Get_stats.py.
Main.py collects the records from the db that need to be updated, preps passwords, api-keys, etc…
Get_stats.py file gets the data using requests. I am currently doing CRUD in Main.py and
this all works, no issues on the python programming front.

After learning about classes, I want to make better use of them and at a crossroads which I’ve not found a clear answer for in this stack to date:

Should I do the CRUD operations in the class file instead? Are there good “best practice” reasons to do so for the long run? Or – should I keep CRUD in Main.py? (Background, the db is a mongodb instance in the cloud. I can create a connection to it in either file.)

Thank you!

## usability – Intuitive Boolean operations in filter for non tech users

Note: There are number of questions I found which are the pretty decade old and the solution too. I have gone through all of them and never found any of the solutions that are actually intuitive. Hence unless you don’t find the case, please don’t mark it as duplicate.

Context
Inside the filter, People have the options to filter (A OR B) AND C

A, B, C are filter sets for e.g A- Department, B- Merchant, and C- Category. In each of the filter sets, people can select a number of departments, merchants or categories as well.

I have come up with this solution.

Problems I faced here:
1. As we build, the interface is going to be complex.
2. People may not understand OR, AND
3. Or, may find it difficult to use things which are boolean in nature since the user base are non-technical.
4. How to better represent summery

In general, how can I simplify it? Here the combination is A and (B OR C) ## algorithms – Space and time complexy of operations on 32-bit array vs. binary array

Assume an array a of length $$n$$. I am wondering how to characterize the difference between time- and space complexity of 32-bit arrays of length $$n$$ and bit-arrays of length $$n$$.

Normally, you’d just state the array uses $$O(n)$$ space and algorithms run in $$O(n)$$, $$O(n^2)$$ and so on. But isn’t there some difference between the two arrays?

I have read something about the word-size but I can’t figure out how this fits into the picture..

PS.
In an actual implementation (e.g Python). There is no difference between the space used by:

``````a1 = (1, 402, 303)
a2 = (1,0,1)
``````

Right?

## algorithms – Make two lists equal by using only few operations

This question was in one of the online judges(Chinese) and the question was as follows

“Consider you are given two $$unequal$$ $$arrays$$ $$a$$ and $$b$$ of $$integers$$ and you need to make the two arrays equal by using following operations. Select a $$integer$$ (by integer i mean both positive and negative) $$x$$ and select a $$subset$$ of $$numbers$$ from $$array$$ $$a$$ and you can $$add$$ or $$multiply$$ each $$element$$ with $$x$$ and place back them in their previous positions in $$array$$ $$a$$ . Find minimum number of operations to make $$a=b$$

It was given that $$|a|<6$$ and $$|a|=|b|$$ .

Now when $$|a|=1$$ then $$answer$$ will be $$0$$ or $$1$$.(it is simple for $$|a|=1$$)

When $$|a|=2$$ then worst case answer is $$2$$ and when they are equal answer is $$0$$ and if elements have $$common$$ $$difference$$ or $$common$$ $$factors$$ then answer is $$1$$.

But i am stuck from case $$|a|>2$$ for $$|a|=3$$ the for answer being $$0$$,$$1$$ or $$3$$ i could find ,criteria for answer being $$2$$ i have no idea and for $$|a|>3$$ i have no idea how to proceed.

Could anybody give me a hint.( only a hint, i am solving it from $$3$$ days)

Example:

$$a=(3,4,5)$$ and $$b=(10,13,16)$$ then answer is $$2$$ .first multiply whole array with $$3$$ and then add $$1$$ to whole array

## scalability – Trying to understand NIC receive / send operations per second estimations for non-abstract system design

I am working through resources related to non-abstract large scale system design. I’m working through the google system design exercise in this video.

In the example solution presented, a calculation is made for the number of write requests a write server can pass through to an underlying storage subsystem. Essentially, the write service is receiving 4MB images from users and for each calling the storage system write operation in parallel. We assume that the storage subsystem has inifinite scaling. The write service hardware has a NIC capable of 1GB/s operation. We assume that the server has reasonable CPU and cache/memory to fully saturate the link up and down.

The example video tried to estimate the total number of write operations that a single server can achieve per second.

They state that:

• it takes 4ms to receive the file from the user (4MB / 1000 MB/s)
• it takes 4ms to send the file to the storage back end (4MB / 1000 MB/s)
• Therefore 8ms to ‘save’ the file.
• Therefore a single server instance
can process 125 writes / second.

But this feel a bit wrong to me. If the server hardware is a standard NIC connected to a standard switch, then the connection is full duplex? Therefore the bandwidth up and down is not shared, and therefore the write operations would be roughly 250 / second?

## weapons – Order of operations for Aurora property Lasers

Laser weapons cannot do damage to invisible creatures. The Aurora property negates invisibility for 1 minute on a hit. At the moment I am assuming that a) you can still make attacks against an invisible target with a laser and b) it will still apply non-damage effects (correct me if these are incorrect). This would mean that a laser with aurora (such as via a Mechanic’s prototype weapon) would still negate invisibility for future shots.

If I fire a laser weapon with the Aurora property, does the (lack of) damage occur before their invisibility is removed, or after?

Relevant rules text:

Laser weapons emit highly focused beams of light that deal fire damage. These beams can pass through glass and other transparent physical barriers, dealing damage to such barriers as they pass through. Barriers of energy or magical force block lasers. Invisible creatures don’t take damage from lasers, as the beams pass through them harmlessly. Fog, smoke, and other clouds provide both cover and concealment from laser attacks. Lasers can penetrate darkness, but they don’t provide any illumination.

When an aurora weapon strikes a target, the creature glows with a soft luminescence for 1 minute. This negates invisibility effects and makes it impossible for the target to gain concealment from or hide in areas of shadow or darkness.