Page 34 - Data Structures Interactive Book
P. 34
3.7 Exercise
Essay Questions
1. Write a program to declare and initialize an array of integers, then print all elements.
2. Implement a function to insert an element at a given position in an array.
3. Write a program to delete an element from an array and shift the remaining elements.
4. Implement linear search and binary search on an array and compare their performance.
Multiple Choice Questions (MCQ)
Q1. What is the main characteristic of arrays in C++?
a) Elements are stored in random memory locations
b) Elements are stored in contiguous memory locations
c) Elements can be of different data types
d) Arrays can grow dynamically without limits
Q2. What is the time complexity of accessing an element in an array by index?
a) ( ) b) ( ) c) ( ) d) ( )
Q3. Which of the following is TRUE about array insertion?
a) Inserting at the end always requires shifting elements
b) Inserting at the beginning requires shifting all elements to the right
c) Inserting at a random position does not affect other elements
d) Arrays automatically resize when inserting new elements
Q4. What is the worst-case time complexity of linear search in an array?
a) ( ) b) ( ) c) ( ) d) ( )
Q5. What is the best-case time complexity of binary search in a sorted array?
a) ( ) b) ( ) c) ( ) d) ( )
Q6. Which of the following correctly declares a two-dimensional array in C++?
a) int arr[3][3]; b) int arr(3,3); c) array<int,3,3> arr; d) int arr{3}{3};
34

