a Flashcards
What are arrays in Java?
Arrays in Java are objects that store multiple values of the same type in sequential memory locations.
What is the structure of an array?
An ordered collection where each value has a numeric index starting from 0.
How do you declare an array in Java?
Created using syntax like int[] scores = new int[10];
How do you access individual elements in an array?
Individual elements accessed using square brackets (scores[2]).
What is the size of an array?
Fixed upon creation and stored in the length property.
What is bounds checking in Java arrays?
Java automatically throws exceptions for invalid indices.
How can you initialize an array?
Can use initializer lists like int[] units = {147, 323, 89};
What happens when an array is passed to methods?
Only the reference is passed (changes affect original).
What are object arrays in Java?
Can store object references (String[] words = new String[25]), but objects must be created separately.
What is the main advantage of arrays?
Organizing large amounts of related data under a single variable name with efficient indexed access.
What is an element in an array?
The actual value stored at a particular position in the array.
For example, in int[] scores = {79, 87, 94}, the elements are 79, 87, and 94.
What is the size of an array?
The total number of elements the array can hold.
For example, the array scores has a size of 3.
What is an index in an array?
The numeric position used to access a specific element.
For example, in the scores array, valid indices are 0, 1, and 2.
What is a singly linked list?
Each node has two fields: info (data) and link/next (address of next node).
What is the head in a linked list?
First node’s address is stored in a variable called head or list.
What operations can be performed on a singly linked list?
Operations include initialization, insertion, deletion, and traversal.
How is insertion done in a linked list?
Requires finding the position and rewiring references.
How is deletion done in a linked list?
Requires connecting the preceding node to the following node.
What is a doubly linked list?
Each node has three fields: info (data), next (address of next node), and prev (address of previous node).
What is an advantage of doubly linked lists?
Allows traversal in both directions.
What is a key difference between arrays and linked lists?
Linked lists don’t require contiguous memory and can grow/shrink dynamically, but they need extra memory for storing references and don’t allow direct access to elements.
What is the floor function?
Think of this as ‘rounding down’ to the nearest whole number.
⎣3.14⎦ = 3 (round 3.14 down to 3)
What is the ceiling function?
This is ‘rounding up’ to the nearest whole number.
⎡3.14⎤ = 4 (round 3.14 up to 4)
What does the modulo operation do?
Gives you the remainder after division.
10 mod 3 = 1 (When you divide 10 by 3, you get 3 with 1 left over)