LogIn
I don't have account.
Question 1
What is the time complexity to access an element in an array by index?
1
O(n log n)
2
O(n)
3
O(log n)
4
O(1)
Question 2
What is the worst-case time complexity of searching for an element in an unsorted array?
1
O(1)
2
O(n log n)
3
O(log n)
4
O(n)
Question 3
Which of the following is an advantage of using an array over a linked list?
1
Easier insertion and deletion
2
Dynamic size
3
Faster access time
4
Uses less memory for large datasets
Question 4
What is the time complexity of inserting an element at the beginning of an array?
1
O(n)
2
O(1)
3
O(log n)
4
O( n log n)
Question 5
Which of the following operations is the most efficient in a circular array?
1
Searching for an element
2
Inserting at the end
3
Deleting from the front
4
Reversing the array
Question 6
In which case is a dynamic array preferred over a static array?
1
When memory usage is fixed
2
When searching is the primary operation
3
When frequent insertions and deletions are needed
4
When the array contains only unique elements
Question 7
Which data structure is best suited for implementing a stack using an array?
1
Binary Tree
2
Linked List
3
Circular Queue
4
Dynamic Array
Question 8
What is the correct way to declare an array of 10 integers in C++?
1
int arr = new int[10];
2
array int arr[10];
3
int arr(10);
4
int arr[10];
Question 9
Which of the following correctly declares an array in C++?
1
array{10};
2
int array;
3
int array[10];
4
array array[10];
Question 10
What will be the output of the following C++ code?
#include <stdio.h>
#include<iostream>
using namespace std;

int main ()
{
    int array[] = {0, 12, 4, 6, 10, 5, 3, 5};
    int n, result = 0;
    for (n = 0; n < 8; n++)
    {
        result += array[n];
    }
    cout << result;
    return 0;
}
1
40
2
27
3
43
4
45
Question 11
What will be the output of the following C++ code?
#include <stdio.h>
#include<iostream>
using namespace std;

int main ()
{
    int arr[] = {0, 12, 4, 6, 10, 5, 3, 5};
    int n, result = 0;
    for (n = 0; n < 8; n++)
    {
        result += arr[n%4];
    }
    cout << result;
    return 0;
}
1
45
2
43
3
27
4
44
Question 12
What will be the output of the following C++ code?
#include <stdio.h>
#include<iostream>
using namespace std;

int main ()
{
    int arr[] = {0, 12, 4, 6, 10, 5, 3, 5};
    int result = 0;
    for (int n = 0; n < 8; n++)
    {
        result += (arr[n%4] > 1);
    }
    cout << result;
    return 0;
}
1
6
2
8
3
12
4
44
Question 13
What will be the output of the following C++ code?
#include <stdio.h>
#include<iostream>
using namespace std;

int main ()
{
    int arr[] = {0, 12, 4, 6, 10, 5, 3, 5};
    int result = 0;
    for (int n = 0; n < 8; n++)
    {
        result += (arr[n%4] >> 1);
    }
    cout << result;
    return 0;
}
1
44
2
22
3
8
4
6
5
12
Question 14
What will be the output of the following LINQ query?
var numbers = new List<int> { 2, 3, 4, 5 };
var result = numbers.Where(n => n % 2 == 0);
Console.WriteLine(result.Count());
1
4
2
3
3
2
4
1
Question 15
What will be the output of the following code? python Copy Edit
a = [1, 2, 3, 4]
print(a[-1])
1
4
2
2
3
1
4
3
Question 16
Which method is used to remove the last element from a list?
1
delete()
2
pop()
3
remove()
4
discard()
Question 17
What will be the output of the following code?
def foo(x, y=[]):
    y.append(x)
    return y
print(foo(1))
print(foo(2))
1
[1, 2] [1, 2]
2
[1] [1, 2]
3
[2] [2]
4
[1] [2]
Question 18
What will be the output of the following code?
let a = [1, 2, 3];
let b = a;
b.push(4);
console.log(a);
1
ReferenceError
2
[1, 2, 3]
3
[1, 2, 3, 4]
4
TypeError
Question 19
Which of the following sorting algorithms works best on a nearly sorted array?
1
Bubble Sort
2
Selection Sort
3
Quick Sort
4
Insertion Sort
Question 20
What is the time complexity of merging two sorted arrays of sizes m and n?
1
O(m + n)
2
O(m * n)
3
O(log(m + n))
4
O(1)
Question 21
What is the space complexity of the merge sort algorithm for sorting an array?
1
O(n)
2
O(n log n)
3
O(1)
4
O(log n)
Question 22
In which case does the time complexity of Quick Sort become O(n²)?
1
When the array contains duplicate values
2
When the pivot is always the median
3
When the array is already sorted and the first or last element is chosen as the pivot
4
When the pivot is chosen randomly
Question 23
How do you find the largest element in an array efficiently?
1
Sort the array and return the last element
2
Use a binary search approach
3
Use recursion without extra space
4
Use a linear scan to find the maximum
Question 24
What is the time complexity of finding an element in a sorted array using binary search?
1
O(1)
2
O( n log n)
3
O(log n)
4
O(n)
Question 25
Which sorting algorithm works best for small datasets and is easy to implement?
1
Merge Sort
2
Bubble Sort
3
Insertion Sort
4
Quick Sort
Question 26
How can you efficiently find the missing number in an array of size n containing numbers from 1 to n+1?
1
Sort and search for the missing number
2
Use a linked list
3
Use a hash set to store elements
4
Calculate the sum and subtract from expected sum
Question 27
How do you efficiently check if an array contains a duplicate in O(n) time complexity?
1
Sort and check adjacent elements
2
Use a binary search
3
Use a hash set
4
Use a nested loop
Question 28
Which of the following is a disadvantage of linked lists over arrays?
1
More memory usage
2
No memory wastage
3
Dynamic size
4
Ease of insertion and deletion
Question 29
What is the time complexity of inserting an element at the head of a singly linked list?
1
O(1)
2
O(n)
3
O(n log n)
4
O(log n)
Question 30
In C++, which of the following correctly initializes a char array?
1
char arr[5] = "Hello";
2
char arr[] = "Hello";
3
char arr[] = {'H', 'e', 'l', 'l', 'o'};
4
Both 2 and 3