how to write delay code in c?
Ans
To perform an efficient delay you need to use a non standard function provided by the operating system for example sleep(...) in Linux or Sleep(...) in Windows.
There is no standard way of efficiently delaying without using processor cycles.
Sunday, May 2, 2010
Detect merged linked list
Given the pointers to 2 linked list, how will we find out if they are merged? i.e. at some point they point to the same address.
Ans
Pick one of the lists and traverse it from head to tail. For each node encountered, compare it to the head pointer of the other list. If you find a match then the second list is embedded within the first list.
If you don't find a match, then repeat the procedure by traversing the second list.
Ans
Pick one of the lists and traverse it from head to tail. For each node encountered, compare it to the head pointer of the other list. If you find a match then the second list is embedded within the first list.
If you don't find a match, then repeat the procedure by traversing the second list.
Linked list
How does one find a loop in a singly linked list in O(n) time using constant memory? you cannot modify the list in any way (and constant memory means the amount of memory required for the solution cannot be a function of n)
Ans
One way to detect a loop is to iterate over the list with 2 pointers at the same time where one is iterating at double speed. If the 2 pointers are ever equal after they iterate once and before they both reach an end, there's a loop.
Ans
One way to detect a loop is to iterate over the list with 2 pointers at the same time where one is iterating at double speed. If the 2 pointers are ever equal after they iterate once and before they both reach an end, there's a loop.
Subscribe to:
Posts (Atom)