Self Studies

Programming and Data Structures Test 3

Result Self Studies

Programming and Data Structures Test 3
  • Score

    -

    out of -
  • Rank

    -

    out of -
TIME Taken - -
Self Studies

SHARING IS CARING

If our Website helped you a little, then kindly spread our voice using Social Networks. Spread our word to your readers, friends, teachers, students & all those close ones who deserve to know what you know now.

Self Studies Self Studies
Weekly Quiz Competition
  • Question 1
    1 / -0

    Consider the below-given queue

    REAR

    102

    78

    21

    95

    16

    15

    17

    FRONT

    How many dequeue operations needed to delete the smallest element from the queue?
    Solution

    Deletion takes place at the FRONT of the queue.

    15 is the smallest element in the given queue.

    1st deque operation:

    REAR

    102

    78

    21

    95

    16

    15

    FRONT

     

    17 is deleted

    2nd deque operation:

    REAR

    102

    78

    21

    95

    16

    FRONT

     

    15 is deleted

    Therefore, the number of deque operation needed to delete 15 is 2.
  • Question 2
    1 / -0

    The following sequence of operations is performed on a stack:

    PUSH(50), PUSH(60), PUSH(70), POP, POP, PUSH(80), PUSH(90), PUSH(100), PUSH(110), POP, PUSH(120) PUSH(130), POP, POP, PUSH(140), POP

    The sequence of values popped out is:
    Solution

    PUSH: 50, 60, 70

    50

    60

    70

    POP: 70 and POP: 60

    50

     

     

     

    PUSH: 80, 90, 100,110

    50

    80

    90

    100

    110

    POP: 110

    50

    80

    90

    100

     

    PUSH: 120, 130

    50

    80

    90

    100

    120

    130

    POP: 130 and POP 120

    50

    80

    90

    100

     

    PUSH: 140

    50

    80

    90

    100

    140

    POP: 140

    50

    80

    90

    100

  • Question 3
    1 / -0

    Which is the postfix of the below given expression:

    P + Q – R * (S + T) / V
    Solution

    P + Q – R * (S + T) / V

    P + Q – R * ST+ / V     //bracket has highest precedence

    P + Q – RST+* / V    //associativity of * and / is left to right with same precedence

    P + Q – RST+*V/   

    PQ+RST+*V/    //associativity of + and – is left to right with same precedence

    PQ+RST+*V/–  

    Therefore answer 3 is correct.

  • Question 4
    1 / -0

    Consider a C function given below:

    void gateCS2021(struct ListNode* head){

    int result = 0;
    while(head) {
    result = 2*result + head->val;
    head = head->next;
    }
    printf("%d", result)

    }

    Input Linked list:  1 → 0 → 1 → 1 → 0 → 0 →1 →1 →0 → 1.

    What is the value printed by gateCS2021()?

    Solution

    1 → 0 → 1 → 1 → 0 → 0 →1 →1 →0 → 1

    While iteration:

    result = 2*0 + 1 = 1

    result = 2*1 + 0  = 2

    result = 2*2 + 1  = 5

    result = 2*5 + 1  = 11

    result = 2*11 + 0  = 22

    result = 2*22 + 0  = 44

    result = 2*44 + 1  = 89

    result = 2*89 + 1  = 179

    result = 2*189 + 0  = 358

    result = 2*378 + 1  = 717

    Important Point:

    The above code will give decimal equivalent of binary representation.

  • Question 5
    1 / -0

    A program attempts to generate as many permutations as possible of the integer 1, 2, 3, 4, 5 by pushing in the same order onto a stack, but it may pop off the top character at any time. Which of the following numbers can be generated using this program?

    I. 5 4 3 2 1

    II. 3 2 1 4 5

    III. 1 2 3 4 5
    Solution

    Push: 1 2 3 4 5

    5

    4

    3

    2

    1

    Pop: 5 4 3 2 1

    Sequence generated: 5 4 3 2 1

    ∴ I can be generated

    Push: 1 2 3

     

     

    3

    2

    1

    Pop: 3 2 1

    Push: 4

     

     

     

     

    4

     

    Pop: 4

    Push: 5

     

     

     

     

    5

     

    Pop: 5

    Sequence generated: 3 2 1 4 5

    ∴ II can be generated

    Push 1: Pop 1, Push 2: Pop 2, Push 3: Pop 3, Push 4: Pop 4, Push 5: Pop 5,

    Sequence generated: 1 2 3 4 5

    ∴ III can be generated

    Therefore I, II and III can be generated.
  • Question 6
    1 / -0

    If a queue is implemented using two stacks. In enqueue operation, all the elements are pushed from the first stack to the second stack. In dequeue operation pop an element from 1st stack.

    What is the time complexity of enqueue and dequeue operation?
    Solution

    Enqueue:

    While 1st  stack is not empty, push everything from 1st to 2nd stack.

    Push an element to 1st stack.

    Push everything back to 1st stack.

    Here time complexity will be O(n)

    Dequeue:

    while 1st stack is not empty then Pop an item from stack1 and return it

    Here time complexity will be O(1)
  • Question 7
    1 / -0

    What does head returns in the the below given function?

    struct ListNode* Decrease_List(struct ListNode* head){
    struct ListNode *p = head;
    if(p == NULL)
    return head;
    while(p->next != NULL)
    {
    if(p->val == p->next->val)
    p->next = p->next->next;
    else
    p = p->next;  
    }
    return head;
    }
    }

    Definition for a singly-linked list is given below
     struct ListNode {
     int val;
     struct ListNode *next;
     };

    Solution

    The given linked list function will delete all duplicates such that each element appear only once in a sorted list

    Example:

    Input

    2 → 3 → 3 → 3 → 4 → 5→ 5 →6

    Output:

    2 → 3 → 4 → 56

  • Question 8
    1 / -0

    What is the result by evaluating the given postfix expression:

    80 10 – 48 12 / * 6 + 7 6 +  –

    In the above expression * is multiplication operator, / is division operator, + is addition operator and – is subtraction operator
    Solution

    80 10 – 48 12 / * 6 + 5 9 + -

    Push: 80 and 10

     

    10

    80

     

    Pop: 10 and 80 

    Perform subtraction: 80 – 10 = 70

    Push: 70

    Also push 48 and 12

    12

    48

    70

     

    Pop: 12 and 48

    Perform division: 48 ÷ 12 = 4

    Push 4

     

    4

    70

     

    Pop: 4 and 70

    Perform multiplication: 70 × 4 = 280

    Push: 280

    Also push: 6

     

    6

    280

     

    Pop: 6 and 280

    Perform addition: 280 + 6 = 286

    Push: 286

    Also push: 7 and 6

    6

    7

    286

    Pop: 9 and 5

    Perform Addition: 7 + 6 = 13

    Push: 1

     

    13

    286

     

    Pop: 14 and 286

    Perform subtraction: 286 - 13 = 273

    Push: 273 onto the stack

     

     

    273

     

    The answer of the following expression is 273.
Self Studies
User
Question Analysis
  • Correct -

  • Wrong -

  • Skipped -

My Perfomance
  • Score

    -

    out of -
  • Rank

    -

    out of -
Re-Attempt Weekly Quiz Competition
Selfstudy
Selfstudy
Self Studies Get latest Exam Updates
& Study Material Alerts!
No, Thanks
Self Studies
Click on Allow to receive notifications
Allow Notification
Self Studies
Self Studies Self Studies
To enable notifications follow this 2 steps:
  • First Click on Secure Icon Self Studies
  • Second click on the toggle icon
Allow Notification
Get latest Exam Updates & FREE Study Material Alerts!
Self Studies ×
Open Now