You are given a Linked list L, and another linked list, P, containing integers, sorted in ascending order. The operation print – lots (L,P) will print the elements in L that are in position specified by P. for instance, if P = 1, 3, 4, 6, the first, third, forth and sixth elements in L are printed. What is the running time of this routine?

Printlots (List L, List P)

    {

        int counter:

        position Lpos, Ppos ;

        Lpos = First (L);

        Ppos = First (P);

        Counter = 1;

        while (Lpos! = NULL && Ppos ! = NULL)

              {

                    if (Ppos → Element = = counter ++)

                        {

                          printf (“%d”, Lpos→ Element)                       

                          Ppos = next (Ppos, P);

                        }

              Lpos = Next (Lpos, L);

                        }

              }

1
O(L)
2
O(L+P)
3
O(LP)
4
None

Sponsored

hivanix.in

Visit

This quiz is brought to you by hivanix.in

🌐 Web App Development

Quick Navigation