Infosys Pseudo Code

Questions 1: Predict the output of the given pseudo code if the value of n is 35 :

Read n
i=0
While n%10!=0
n=n+3
i++
end while
n=n+i
write n

  • Options
  • a : 50.0
  • b : 53.0
  • c : 55.0
  • d : 45.0
  • Answer: c

    Questions 2: What will be the output of the given pseudo code if n = 10 ?

    Read n
    Initialize i to 5
    while i < n do
    increase sum by i
    increment i
    end while
    Write sum

  • Options
  • a : 25.0
  • b : 35.0
  • c : 55.0
  • d : 45.0
  • Answer: b

    Questions 3: Predict the output of the given pseudo code if the value of number is 6:

    Read number
    k = 2
    i = 2
    while i<=number
    k = k * i
    i = i +1
    end while
    write k

  • Options
  • a : 1700.0
  • b : 1560.0
  • c : 1440.0
  • d : 1340.0
  • Answer: c) 1440.0

    Questions 4: What will be the number of " * " printed by the given pseudo code when input is 25?

    Write "Please enter a number"
    Read input
    Repeat while input > 0
    if( input > 0 and input <=10 )
    Write *
    else if ( input >10 and input <=20 )
    Write **
    else if ( input >20 and input< = 30 )
    Write ***
    input --
    end if
    end while

  • Options
  • a : 55.0
  • b : 45.0
  • c : 25.0
  • d : 35.0
  • Answer: b

    Questions 5: You have written the pseudo code given alongside for performing binary search in an array of elements sorted in ascending order. Which step to be followed in A to execute binary search successfully?

    1.Compare x with the middle element.
    2.If x matches with the middle element, we return the mid index.
    3.A
    4.Else ( x is smaller ) recur for the left half

  • Options
  • a : Else if x is greater than the mid element, then x can only lie in left half subarray after the mid element. So we recur for left
  • b : Else if x is greater than the mid element, then x can only lie in right half subarray after the mid element. So we recur for right
  • c : Else if x is less than the mid element, then x can only lie in right half subarray after the mid element. So we recur for right
  • d : None of the given options
  • Answer: b

    Questions 6: You have a vehicle class, a car class, and a person class, you have to implement the functionalities of a bird, dog, cat, bus, auto and 2 specialized car classes for hybrid and electric vehicles.
    Which of these options is the most efficient way to do so?

    1.Make a new class for all the required methods and implement all methods separately.
    2.Inherit the car class into the specialized car and then implement the extra methods.
    3.Make a new class Big vehicles and then inherit properties from it to make the bus classes.
    4.Inherit the person class to bird, dog, cat, and then override the methods that are not required.
    5.Make new class animals and use this to make the dogs, cats and birds class.
    6.Make a new three wheeled vehicle inherited from vehicle class for auto.
    7.Inherit vehicle class for auto.

  • Options
  • a : 2,5,7
  • b : 2,5,6
  • c : 3,4,6
  • d : 1
  • Answer: a

    Questions 7: Class A contains two methods, namely “me” and “see”. Class B inherits Class A and overrides the “see” method. Class C also inherits methods from Class A and overrides the “see” method. Class B and class C are both inherited by class D using the concept of multiple inheritances.

    In the given scenario, identify the problem generated by the behaviour of the “see” method?

  • Options
  • a : Dexterity problem
  • b : Cohesion Problem
  • c : Diamond Problem
  • d : Coherence Problem
  • Answer: c

    Questions 8: Consider the given problem statement:
    Problem statement :
    Find the closest pair of points in an array of distinct points
    Assume that you have solve this problem by comparing all pairs of points. What will be the complexity of this approach?

  • Options
  • a : O(N)
  • b : O(N^2)
  • c : O( N log N )
  • d : Cannot be determined
  • Answer: b

    Questions 9: You are using the pseduo algorithm given alongside to sort an array using insertion sort.
    Which of the following can be used in place of X to complete the algorithm?

    1.Declare static void insertionSortRecursive(int arr[], int n) function.
    2.if ( n < = 1 ) then return add more elements to array message.
    3.Sort first n-1 elements.
    4.Insert last element at its correct position in sorted array
    int last = arr[n-1];
    int j= n-2;
    5.Move elements of arr[X], that are greater than key, to one position ahead of their current position.

  • Options
  • a : i
  • b : i-1
  • c : j
  • d : j-1
  • Answer: c

    Questions 10: Given alongside are two pseudo-class definitions in an Object Oriented Programming Language
    Which of the following statements is true regarding the return type of Dog's seekFood() function?

    public class Animal{
        protected Food seekFood(){
         return new Food();
        }
    }
            
    public class Dog extends Animal{
        protected Food seekFood(){
         return new DogFood();
        }
    }
        

  • Options
  • a : This code is an example of the use of virtual return type
  • b : This code is an example of the use of contravariant returntype.
  • c : This code is an example of the use of abstract return type
  • d : This code is an example of the use of covariant return type
  • Answer: c


    More Questions will be uploaded soon.....