All Flashcards
What is an array traversal?
Visiting each element in an array in a specific order.
What is the mode of an array?
The element that appears most frequently in the array.
What is meant by 'shifting' an array?
Moving elements in the array to the left or right, potentially wrapping around.
What is the mean of an array?
The sum of all elements in the array divided by the number of elements.
What does it mean to reverse an array?
To rearrange the elements of the array in the opposite order.
Define 'frequency' in the context of array elements.
The number of times a specific element appears in the array.
Define 'consecutive sequences' in an array.
Subsets of elements that are adjacent to each other in the array.
What is the purpose of the 'duplicates' algorithm?
To determine if any element appears more than once in the array.
What is the role of the 'isEven' algorithm?
To check if all elements in the array are even numbers.
What is the 'sum' of an array?
The result of adding all the elements in the array together.
What does the following code output?
java
int[] arr = {1, 2, 3, 4, 5};
System.out.println(maximum(arr));
5
What does the following code output?
java
int[] arr = {5, 4, 3, 2, 1};
System.out.println(minimum(arr));
1
What does the following code output?
java
int[] arr = {1, 2, 3, 4, 5};
System.out.println(sum(arr));
15
What does the following code output?
java
int[] arr = {1, 2, 3, 4, 5};
System.out.println(mean(arr));
3.0
What does the following code output?
java
int[] arr = {1, 2, 2, 3, 3, 3};
System.out.println(mode(arr));
3
What does the following code output?
java
int[] arr = {2, 4, 6, 8, 10};
System.out.println(isEven(arr));
true
What does the following code output?
java
int[] arr = {1, 3, 5, 7, 9};
System.out.println(isEven(arr));
false
What does the following code output?
java
int[] arr = {1, 2, 3, 2, 1};
System.out.println(duplicates(arr));
true
What does the following code output?
java
int[] arr = {1, 2, 3, 4, 5};
System.out.println(duplicates(arr));
false
What does the following code output?
java
int[] arr = {2, 4, 6, 8, 10};
System.out.println(evenFrequency(arr));
5
Why is initializing maxValue and minValue to array[0] important when finding the minimum and maximum?
Avoids incorrect results when the array contains only positive or only negative numbers.
Why is array traversal fundamental to many array algorithms?
It allows you to access and process each element, enabling calculations, comparisons, and modifications.
Explain the importance of checking array bounds in array algorithms.
Prevents ArrayIndexOutOfBoundsException errors by ensuring you don't access invalid array indices.
Why is it important to consider edge cases when developing array algorithms?
Edge cases, like empty arrays or arrays with only one element, can expose flaws in the algorithm's logic.
How does the choice of data structure impact algorithm efficiency?
Different data structures have different strengths, affecting the time and space complexity of algorithms.
What is the time complexity of finding the minimum element in an unsorted array?
O(n), as you need to potentially check every element in the array.
Why is understanding array indexing crucial for array manipulation?
Correct indexing is essential for accessing and modifying specific elements within the array.
Explain the concept of 'in-place' array manipulation.
Modifying the array directly without using additional memory for a new array.
What is the purpose of nested loops in array algorithms?
To compare or combine elements within the array, often used for finding duplicates or sequences.
What is the significance of the 'length' property of an array?
It provides the number of elements in the array, which is essential for controlling loop iterations and preventing errors.