Sail E0 Webinar

MCQs

Total Questions : 10
Question 1. If row-major order is used, how is the following matrix stored in memory?a b cd e fg h i
  1.    ihgfedcba
  2.    abcdefghi
  3.    cfibehadg
  4.    adgbehcfi
 Discuss Question
Answer: Option B. -> abcdefghi


It starts with the first element and continues in the same row until the end of row is reached and then proceeds with the next row. C follows row-major order.


Question 2. What is a sorted array?
  1.    Arrays sorted in numerical order
  2.    Arrays sorted in alphabetical order
  3.    Elements of the array are placed at equally spaced addresses in the memory
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned


The array can be sorted in any way, numerical, alphabetical or any other way but the elements are placed at equally spaced addresses.


Question 3. Choose the appropriate code that counts the number of non-zero(non-null) elements in the sparse array.
  1.    public int count(){        int count = 0;        for (List cur = this.next; (cur != null); cur = cur.next)        {            count++;        }        return count;}
  2.    public int count(){        int count = 0;        for (List cur = this; (cur != null); cur = cur.next)        {            count++;        }        return count;}
  3.    public int count(){        int count = 1;        for (List cur = this.next; (cur != null); cur = cur.next)        {            count++;        }        return count;}
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> public int count(){        int count = 0;        for (List cur = this.next; (cur != null); cur = cur.next)        {            count++;        }        return count;}


A simple 'for loop' to count the non-null elements.


Question 4. Which of the following performs the fetch operation?
  1.    public Object fetch(int index){        List cur = this.next;        Object val = null;        while (cur != null && cur.index != index)        {            cur = cur.next;        }        if (cur != null)        {            val = cur.val;        } else        {            val = null;        }        return val;}
  2.    public Object fetch(int index){        List cur = this;        Object val = null;        while (cur != null && cur.index != index)        {            cur = cur.next;        }        if (cur != null)        {            val = cur.val;        } else        {            val = null;        }        return val;}
  3.    public Object fetch(int index){        List cur = this;        Object val = null;        while (cur != null && cur.index != index)        {            cur = cur.index;        }        if (cur != null)        {            val = cur.val;        } else        {            val = null;        }        return val;}
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> public Object fetch(int index){        List cur = this;        Object val = null;        while (cur != null && cur.index != index)        {            cur = cur.next;        }        if (cur != null)        {            val = cur.val;        } else        {            val = null;        }        return val;}


You travers through the array until the end is reached or the index is found and return the element at that index, null otherwise.


Question 5. To search for an element in a sorted array, which searching technique can be used?
  1.    Linear Search
  2.    Jump Search
  3.    Binary Search
  4.    Fibonacci Search
 Discuss Question
Answer: Option C. -> Binary Search


Since the array is sorted, binary search is preferred as its time complexity is O(logn).


Question 6. Identify the disadvantages of bit array.
  1.    Without compression, they might become sparse
  2.    Accessing individual bits is expensive
  3.    Compressing bit array to byte/word array, the machine also has to support byte/word addressing
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned


Without compression, they become sparse in both time and space, also if random access is more common than sequential access, then they have to be compressed to byte/word array.


Question 7. Which of the following is an advantage of bit array?
  1.    Exploit bit level parallelism
  2.    Maximal use of data cache
  3.    Can be stored and manipulated in the register set for long periods of time
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned


Because bit arrays are compact, they outperform many other data structures.


Question 8. Which of the following is the correct syntax to declare an ArrayList in Java?
  1.    ArrayList al = new ArrayList();
  2.    ArrayList al = new ArrayList[];
  3.    ArrayList al() = new ArrayList();
  4.    ArrayList al[] = new ArrayList[];
 Discuss Question
Answer: Option A. -> ArrayList al = new ArrayList();


This is a non-generic way of creating an ArrayList.


Question 9. What does the following piece of code do?for(int i = 0; i < row; i++){      for(int j = 0; j < column; j++)    {        if(i == j)            sum = sum + (array[i][j]);    }}System.out.println(sum);
  1.    Normal of a matrix
  2.    Trace of a matrix
  3.    Square of a matrix
  4.    Transpose of a matrix
 Discuss Question
Answer: Option B. -> Trace of a matrix


trace of a matrix is the sum of the principal diagonal elements.


Question 10. In what type of dynamic array do you divide the array into two parts?
  1.    Hashed Array Tree
  2.    Geometric Array
  3.    Bounded-size dynamic array
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Bounded-size dynamic array


The first part stores the items of the dynamic array and the second part is reserved for new allocations.


Latest Videos

Latest Test Papers