46 Questions
Which attribute is used as the only parameter in the concat constructor for the objects String, StringBuffer, and StringBuilder?
size
Where are the attributes String, StringBuffer, and StringBuilder initialized?
In constructors
What is the Java heap area and what does it store?
It is a dynamic memory area and stores objects instantiated by the JVM
Which type of arrays does a linear search work for?
Both sorted and unsorted arrays
What is the time complexity of a linear search?
$O(n)$
When an array is sorted, what type of search can we do?
Binary search
Which of the following best describes the time complexity for accessing array elements?
$O(1)$ time
What is the lower bound for array elements?
$0$
What is the length of a subarray $a[l:r]$, and how is it calculated?
$r-l+1$
What does it mean for an array to be sorted?
All elements are in ascending order
Which attribute is used as the only parameter in the concat constructor for the objects String, StringBuffer, and StringBuilder?
size
Where are the attributes String, StringBuffer, and StringBuilder initialized?
constructors
What is an array?
A sequence of indexed elements
What are the different types of arrays in Java?
Primitive and object arrays
What is an array in Java?
An object
Where does an array reside in Java?
Heap memory
What is an example of a primitive array?
int[] primes = {2, 3, 5, 7, 11};
What does the index 'prime' point to in the given code snippet?
Data storage
What attributes does the array 'primes' point to in the given code snippet?
Class tag, length, and stored values
What is the syntax for creating an object array in Java?
datatype namespace = new datatype[#ofobjectstobeinstansiated];
Which of the following best describes the time complexity for accessing array elements?
$O(1)$ time
What must you create if you need a different size array?
A new array
What is the upper bound for array elements?
$n-1$
What do Java primitive arrays contain?
Elements that are values of primitive data types
What can Java object arrays contain?
Objects of any class
What is the relationship of an array in ascending order?
Elements are in ascending order
What is the first step of inserting 35 at $ins:2$ of the array [10, 20, 30, 40, 50]?
Select $a[ins.right]$
What does it mean for an array to be sorted?
Elements are in ascending order
What is selected in the expression $a[del+1.right]$ during array deletion?
Elements to the right of $del+1$
What is the goal of array deletions?
To remove a specific value from an array or subarray
Which subarray is indicated by $a[del.right-1]$?
The subarray to the right of the site deletion
What is done to the subarray $a[del.right-1]$?
The index of the subarray is decreased by one
What happens to the elements of the subarray $a[del.right-1]$?
They are added back to the new array
For which type of arrays does a linear search work?
Unsorted and sorted arrays
What is the time complexity of a linear search?
$O(n)$
When an array is sorted, what type of search can we do?
Binary search
What is a binary search used to find?
Target value from a subarray
How is the subarray of a binary search represented?
$a[left:right]$
What is the equality of $a[left:right]$?
$left < right$
What is updated if the target is less than $a[m]$ in a binary search?
$r$ to $m-1$
Which sorting algorithm has the best-case time complexity of O(n) when the list is already sorted?
Bubble Sort
What is the space complexity of Selection Sort?
O(1)
Which sorting algorithm has the worst-case time complexity of O(n^2)?
Insertion Sort
Which of the following is the average-case time complexity of the insertion sort algorithm?
O(n^2)
What is the worst-case time complexity of the quick sort algorithm?
O(n^2)
What is the space complexity of the quick sort algorithm on average?
O(log n)
Study Notes
String, StringBuffer, and StringBuilder
- The attribute used as the only parameter in the concat constructor for the objects String, StringBuffer, and StringBuilder is the string to be concatenated.
- The attributes String, StringBuffer, and StringBuilder are initialized in the Java heap area.
Arrays
- Java arrays are containers that store a fixed number of values of the same type.
- Arrays can be of two types: primitive arrays and object arrays.
- Primitive arrays contain primitive data types, whereas object arrays contain objects.
- Arrays reside in the Java heap area.
- Example of a primitive array:
int[] primes = {2, 3, 5, 7};
Array Operations
- Linear search works for arrays of any type.
- The time complexity of a linear search is O(n).
- When an array is sorted, a binary search can be used.
- Binary search is used to find an element in a sorted array.
- The subarray of a binary search is represented as
a[left:right]
. - The equality of
a[left:right]
isright - left
.
Array Indexing
- The index of an array starts from 0.
- The lower bound for array elements is 0.
- The upper bound for array elements is the length of the array minus 1.
- The length of a subarray
a[l:r]
is calculated asr - l
.
Sorting and Searching
- A sorted array is an array where the elements are arranged in ascending or descending order.
- When an array is sorted, a binary search can be used.
- Binary search is used to find an element in a sorted array.
- The time complexity of a binary search is O(log n).
Sorting Algorithms
- The best-case time complexity of Selection Sort is O(n) when the list is already sorted.
- The space complexity of Selection Sort is O(1).
- The worst-case time complexity of Selection Sort is O(n^2).
- The average-case time complexity of Insertion Sort is O(n^2).
- The worst-case time complexity of Quick Sort is O(n^2).
- The average space complexity of Quick Sort is O(log n).
Test your knowledge on Complexity Analysis and the different attributes and types of String, StringBuffer, and StringBuilder objects. Explore the importance of the size parameter in the concat constructor and understand where the attributes of these objects are initialized.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free