Home > Software engineering >  Data structures and algorithms
Data structures and algorithms

Time:09-15

In leading the singly linked list of nodes integer set, complete the following algorithm and time complexity analysis:
(1) design A algorithm for two sets A and B difference set operations, namely C=A - B. Space complexity of the algorithm to 0 (1). And release the singly linked lists don't need the nodes in the A and B,
(2) suppose the elements in the collection in terms of increasing design an efficient algorithm for two sets A and B difference set operations, namely C=A - B, space complexity of the algorithm to 0 (1), and release the singly linked lists don't need the nodes in the A and B,

CodePudding user response:

The first is the traverse A, then each element to B and traverse again find, find it from A lost inside,
The second is the two Pointers take the first element of A and B, respectively, and then which pointer refers to the numerical is compared to continue, until A refers to the equal, from A delete the corresponding elements inside, two Pointers, respectively, add 1 to continue,
  • Related