Redirected
961 views
3 votes
3 votes

A linked list of length at most n is maintained in circular array C[0:n-1], clockwise or anticlock wise; two variables head and last are used to point to first and last element of the list respectively, for instance if linked list is of size x and if it is maintained in clock wise manner and head =p, then last = (p+x)mod n, then the best way for
I: deleting kth element in the linked list
II: reversing the elements of linked list can be done in

  1.   O(1), O(1) time
  2.   O(1), O(n) time
  3.   O(n), O(1) time
  4.   O(n), O(n) time

2 Answers

1 votes
1 votes
the kth element can be found by k=(p+k)mod n delete it and keep the pointer of the prev to the next----it is done in O(1)

to reverse the elements the head and tail of the previous list are swapped and they are accessed in anti clockwise order this can be done in O(1) time as we know the position of head and tail
0 votes
0 votes
S1: deletion operation= going  to the kth element(O(1)) -> deleting that element(O(1)) ->shift the elements(O(n))   total=O(n)

shifting is necessary in the deletion step otherwise free space will be created in between linked list

S2: just interchange the pointers and traverse from hgher index to lower index   O(1)

Related questions

0 votes
0 votes
1 answer
1
Mrityudoot asked Feb 25
177 views
How can we find the highest element in a singly linked list in O(1)? We are free to use any extra space.
9 votes
9 votes
2 answers
4
GO Classes asked May 4, 2022
507 views
If $f(n) = O(g(n))$ and $f(n) = \Omega(g(n)),$ then it is always true that$f(n) = o(g(n)).$$f(n) = \theta(g(n)).$$f(n) = \omega(g(n)).$both A and B are always true.