Posts

Showing posts from June, 2019

[Data Structure] XOR LinkedList

An XOR linked list is a type of double-linked list that uses bitwise XOR operation to store address of the previous and next address in one space (thus, reducing storage space). In the traditional double-linked list, each node has to store a prev and next address field.  A  B  C  D ..  n->n->n .. ..  p<-p<-p .. An XOR linked list combines the same information into 1 address field via bitwise XOR (denoted by ⊕) of the prev and next address. A    B      C      D      E ..  p⊕n  p⊕n  p⊕n    .. Getting the next address space When traversing from left to right, suppose the cursor is at C, the address of previous item B can be XORed with the value of linked field of C (B⊕D) to get the address for D.  ie. addr(D) = link(C) ⊕ addr(B) where      link(C) = addr(B) ⊕ addr(D) so      addr(D) = addr(B) ⊕ addr(D) ⊕ addr(B) since     X⊕X = 0     => addr(D) = 0 ⊕ addr(D) since      X⊕0 = X     => addr(D) = addr(D) The XOR operation can

[Python] zip(*[iter(s)]*n)

zip(*[iter(s)]*n) 1. A better syntax for explanation is that: zip(*[iter(s)]*n) is same as zip(*([iter(s)] * n)) 2. iter() is an iterator over a sequence (in this case, s). 3. [iter(s)] * n <==> [iter(s), iter(s), ... <n times>] : creates an array of iterators 4. zip() method takes a input parameter in form of zip(*args), meaning it can take zip(x), zip(x,x), zip(x,x,x) and so forth. 5. Combining this, we are just doing: zip(iter(s), iter(s), <repeated n times>) Resources:  https://stackoverflow.com/questions/2233204/how-does-zipitersn-work-in-python