[algogeeks] Re: Blocked/Unrolled linked list with no duplicates and sorted

2011-07-28 Thread banu
Anyone ?

On Jul 26, 10:27 pm, banu varun.nagp...@gmail.com wrote:
 Hi,
 Basically I am trying to create a blocked linked list(unrolled linked
 list) with following properties
 - Configurable number of elements in each node
 - No duplicate elements in the unrolled linked list
 - Linked list is sorted either during insertion or after creating the
 linked list
 - In place

 Assuming I need to create a sorted unrolled linked list with no
 duplicate elements with block size say 2

 Example: 10,2,4,2,5,7,9.11,11,5

 Final blocked linked list: (2,4)-(5,7)-(9,10)-(11,x) or in reverse
 order

 Note: x means unutilized location in the array wihtin the node. In
 case there are not enough elements to insert in a node, some memory
 allocated for a node is unutilized

 // Following is node structure
 #define ARRAY_SZ 2
 typedef struct node
 {
     struct node* next;
     long long int elements[ARRAY_SZ];
     long long int elemIndex;

 }NODE, *NODE_PTR;

 Can you suggest me a way to do this correctly and efficiently? It
 could be an pseudo text or C-code.

 Thanks
 Varun

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Blocked/Unrolled linked list with no duplicates and sorted

2011-07-27 Thread banu
Hi,
Basically I am trying to create a blocked linked list(unrolled linked
list) with following properties
- Configurable number of elements in each node
- No duplicate elements in the unrolled linked list
- Linked list is sorted either during insertion or after creating the
linked list
- In place

Assuming I need to create a sorted unrolled linked list with no
duplicate elements with block size say 2

Example: 10,2,4,2,5,7,9.11,11,5

Final blocked linked list: (2,4)-(5,7)-(9,10)-(11,x) or in reverse
order

Note: x means unutilized location in the array wihtin the node. In
case there are not enough elements to insert in a node, some memory
allocated for a node is unutilized

// Following is node structure
#define ARRAY_SZ 2
typedef struct node
{
struct node* next;
long long int elements[ARRAY_SZ];
long long int elemIndex;
}NODE, *NODE_PTR;

Can you suggest me a way to do this correctly and efficiently? It
could be an pseudo text or C-code.

Thanks
Varun

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: a google question

2010-04-30 Thread banu
Nice question:

1. |A| = |B| i.e I assume their cardinality is equal

2. A(n) = { a1, a2  a3, ...aN} such that a1=a2=a3...=aN
3. B(n) = { b1, b2  b3, ...bN} such that b1=b2=b3...=bN

4. S(n^2) = A x B = {(a1,b1), (a1,b2)(a1,bN),
  (a2,b1), (a2,b2)(a2,bN),
   
  (aN,b1), (aN,b2)(aN,bN)}
  I assume each pair is stored as a sum i.e ai + bi and also that I
have paired them in a way such that we find a pair  ai  bi  for some
i in 1..N and and a(i-1) = b(i-1)

A first observation is that in the worst case, the first 2N numbers in
S will contain the final result of N numbers.
i.e in  (a1,b1), (a1,b2)(a1,bN), (a2,b1), (a2,b2)(a2,bN)

In the best case first N numbers in S will contain the final N numbers
(already sorted in decreasing order)
i.e in  (a1,b1), (a1,b2)(a1,bN)

Now, if we consider again the worst case scenario, then we can first
divide 2N numbers in two groups of size N each and each of this group
is already sorted in decreasing order.
i.e  (a1,b1), (a1,b2)(a1,bN) and (a2,b1), (a2,b2)(a2,bN)

Now we can simply apply Merge Algorithm on these 2 already sorted
arrays of size N each in O(N) time, which solves the problem

I can be wrong only if the the results lie outside first 2N numbers,
which I hope is not the case(then I think its not possible to solve in
O(n) but in O(nlogn)).


On Apr 30, 2:05 pm, divya sweetdivya@gmail.com wrote:
 Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G, let's
 say they are decreasingly sorted), we define a set S = {(a,b) | a \in
 A
 and b \in B}. Obviously there are n^2 elements in S. The value of such
 a pair is defined as Val(a,b) = a + b. Now we want to get the n pairs
 from S with largest values. The tricky part is that we need an O(n)
 algorithm.

 --
 You received this message because you are subscribed to the Google Groups 
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to 
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group 
 athttp://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: a google question

2010-04-30 Thread banu
Nice question:

1. |A| = |B| i.e I assume their cardinality is equal

2. A(n) = { a1, a2  a3, ...aN} such that a1=a2=a3...=aN
3. B(n) = { b1, b2  b3, ...bN} such that b1=b2=b3...=bN

4. S(n^2) = A x B = {(a1,b1), (a1,b2)(a1,bN),
  (a2,b1), (a2,b2)(a2,bN),
   
  (aN,b1), (aN,b2)(aN,bN)}

  assuming we have added in a way such that we find a pair  ai  bi,
for some i in 1..N such that a(i-1) = b(i-1)

A first observation is that in the worst case, the first 2N numbers in
S will contain the final result of N numbers.
i.e in  (a1,b1), (a1,b2)(a1,bN), (a2,b1), (a2,b2)(a2,bN)

In the best case first N numbers in S will contain the final N numbers
(already sorted in decreasing order)
i.e in  (a1,b1), (a1,b2)(a1,bN)

Now, if we consider again the worst case scenario, then we can first
divide 2N numbers in two groups of size N each and each of this group
is already sorted in decreasing order.
i.e  (a1,b1), (a1,b2)(a1,bN) and (a2,b1), (a2,b2)(a2,bN)

Now we can simply apply Merge Algorithm on these 2 already sorted
arrays of size N each in O(N) time, which solves the problem

I can be wrong only if the the results lie outside first 2N
numbers(which I hope is not the case).


On Apr 30, 2:05 pm, divya sweetdivya@gmail.com wrote:
 Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G, let's
 say they are decreasingly sorted), we define a set S = {(a,b) | a \in
 A
 and b \in B}. Obviously there are n^2 elements in S. The value of such
 a pair is defined as Val(a,b) = a + b. Now we want to get the n pairs
 from S with largest values. The tricky part is that we need an O(n)
 algorithm.

 --
 You received this message because you are subscribed to the Google Groups 
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to 
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group 
 athttp://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Alternative Dta Structures for Cache Inefficient Linked Lists

2010-02-17 Thread banu
Hi,
I had been thinking about this problem from quite sometime. Linked
lists are good dynamic data structures and solve the main problems
associated with arrays(static memory allocation)

On the other hand, one of the biggest disadvantages of linked lists is
that their cache utilization is extremely poor. This results mainly
from poor spatial locality because nodes of linked list are allocated
in non-sequential memory locations. So when one accesses a node of
linked list, a single cache line(fixed bunch of bytes) is fetched, and
as the other nodes are present far in memory, the cache line most of
the time will not contain other nodes. So every time a new node is
accessed, the previous cache line has to be flushed and replaced by
new cache line containing new node. This means on every access of node
we pay the cost of reading data from main memory(which is very
expensive) and bringing it into cache

Main problem is that the poor cache utilization can sometimes result
very bad extremely performance especially if the program is memory
intensive (uses lot of heap memory)

My question is that are their any other data structures which provide
the benefits of linked lists (using dynamic memory allocation) but are
as efficient as arrays in context of cache utilization?

Thanks
Varun

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.