Escolar Documentos
Profissional Documentos
Cultura Documentos
LINKED LISTS
Q. Why merge sort preferred for LL while Quick sort preferred for arrays?
Ans. This is due to diff. in allocation of arrays and LL. Unlike arrays, in LL we can insert items in
middle in O(1) extra space and O(1) time. Therefore, merge operation can be implemented
without extra space for LL.
We can do random access in arrays. Eg: Let us say address of A[0} be x, then to access A[i} we
can directly access memory at (x+ i*4) . But unlike arrays, we cannot do random access in LL
and quick sort requires lot of random access. Therefore, overhead increases for quick sort.
Whereas merge sort accesses data sequentially & need of random access is low.
Important Questions:
CSI-DTU 2015
Given a sorted DLL & two numbers c & k. Decrease the data of node with data k by c and
insert new node formed at its correct position such that list remains sorted.
Search in sorted LL (better than O(n) use skip list method)
Add 2 numbers represented by LL
Reverse a DLL
Just swap next & prev pointers for all nodes in a DLL.