# 13 Lecture

## Array Manipulation

Array Manipulation involves performing operations on arrays, such as adding or removing elements, sorting, searching, or modifying the values of existing elements. These operations can be implemented using various algorithms and techniques, incl

## Important Mcq's Midterm & Finalterm Prepration Past papers included

1. Which of the following is not an operation in array manipulation? A) Addition B) Multiplication C) Sorting D) Searching Answer: B) Multiplication

2. Which function is used to calculate the length of an array in C++? A) length() B) size() C) lengthof() D) sizeof() Answer: D) sizeof()

3. Which function is used to sort an array in C++? A) sort() B) merge() C) swap() D) copy() Answer: A) sort()

4. Which of the following is a disadvantage of arrays? A) They can be resized easily B) They can only store elements of the same data type C) They are not index-based D) They are inefficient for searching and sorting Answer: B) They can only store elements of the same data type

5. What is the complexity of linear search algorithm? A) O(log n) B) O(n) C) O(n log n) D) O(1) Answer: B) O(n)

6. Which operator is used to access an element of an array in C++? A) () B) {} C) [] D) / Answer: C) []

7. Which algorithm is used for sorting in the STL library of C++? A) Bubble Sort B) Insertion Sort C) Selection Sort D) Quick Sort Answer: D) Quick Sort

8. What is the maximum number of dimensions that an array can have in C++? A) 1 B) 2 C) 3 D) There is no limit Answer: D) There is no limit

9. Which function is used to delete an element from an array in C++? A) remove() B) delete() C) erase() D) pop() Answer: C) erase()

10. What is the time complexity of binary search algorithm? A) O(log n) B) O(n) C) O(n log n) D) O(1) Answer: A) O(log n)

## Subjective Short Notes Midterm & Finalterm Prepration Past papers included

1. What is array manipulation? Answer: Array manipulation is the process of performing operations on arrays, such as adding or removing elements, sorting, searching, or modifying the values of existing elements.

2. How do you declare an array in C++? Answer: To declare an array in C++, we use the following syntax: `data_type array_name[size];`

3. What is the difference between an array and a linked list? Answer: An array is a collection of elements of the same data type, while a linked list is a collection of elements that are linked together by pointers.

4. What is the difference between linear search and binary search? Answer: Linear search checks each element of an array in sequence until the target element is found, while binary search divides the array into halves and checks the middle element to determine which half to search next.

5. How do you add an element to an array in C++? Answer: To add an element to an array in C++, we can use the `push_back()` function in the vector class, or we can create a new array with a larger size and copy the elements from the original array into it.

6. What is the syntax for accessing an element of an array in C++? Answer: The syntax for accessing an element of an array in C++ is `array_name[index]`.

7. What is the time complexity of bubble sort? Answer: The time complexity of bubble sort is O(n^2).

8. What is the difference between sorting and searching? Answer: Sorting is the process of arranging elements in a particular order, while searching is the process of finding a specific element in an array.

9. How do you delete an element from an array in C++? Answer: To delete an element from an array in C++, we can use the `erase()` function or create a new array with a smaller size and copy the remaining elements into it.

10. What is the advantage of using arrays over linked lists? Answer: Arrays have a simpler implementation and faster access times for random access of elements, while linked lists are more flexible for dynamic insertion and deletion of elements.

Array manipulation refers to the process of performing various operations on arrays, which are a collection of similar data types. The operations can include adding or removing elements, sorting, searching, or modifying the values of existing elements. Arrays are commonly used in programming languages to store and access large amounts of data. One of the most basic operations on an array is adding or removing elements. To add elements to an array, we can use the `push_back()` function in the vector class, or we can create a new array with a larger size and copy the elements from the original array into it. To remove elements, we can use the `erase()` function or create a new array with a smaller size and copy the remaining elements into it. Sorting is another important operation on arrays. There are various algorithms for sorting arrays, such as bubble sort, selection sort, insertion sort, and quicksort. These algorithms have different time complexities and are suitable for different types of arrays. Searching is the process of finding a specific element in an array. Linear search checks each element of an array in sequence until the target element is found, while binary search divides the array into halves and checks the middle element to determine which half to search next. Binary search is faster than linear search, but it requires the array to be sorted. Modifying the values of existing elements in an array is also a common operation. We can access an element of an array using its index and modify its value using the assignment operator. In conclusion, array manipulation is an important aspect of programming and involves a variety of operations that are used to manipulate and process data stored in arrays. Understanding these operations and their associated algorithms is essential for efficient and effective programming.