a Flashcards

1
Q

What are arrays in Java?

A

Arrays in Java are objects that store multiple values of the same type in sequential memory locations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the structure of an array?

A

An ordered collection where each value has a numeric index starting from 0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you declare an array in Java?

A

Created using syntax like int[] scores = new int[10];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you access individual elements in an array?

A

Individual elements accessed using square brackets (scores[2]).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the size of an array?

A

Fixed upon creation and stored in the length property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is bounds checking in Java arrays?

A

Java automatically throws exceptions for invalid indices.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you initialize an array?

A

Can use initializer lists like int[] units = {147, 323, 89};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What happens when an array is passed to methods?

A

Only the reference is passed (changes affect original).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are object arrays in Java?

A

Can store object references (String[] words = new String[25]), but objects must be created separately.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the main advantage of arrays?

A

Organizing large amounts of related data under a single variable name with efficient indexed access.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an element in an array?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the size of an array?

A

The total number of elements the array can hold.

For example, the array scores has a size of 3.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is an index in an array?

A

The numeric position used to access a specific element.

For example, in the scores array, valid indices are 0, 1, and 2.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a singly linked list?

A

Each node has two fields: info (data) and link/next (address of next node).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the head in a linked list?

A

First node’s address is stored in a variable called head or list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What operations can be performed on a singly linked list?

A

Operations include initialization, insertion, deletion, and traversal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How is insertion done in a linked list?

A

Requires finding the position and rewiring references.

18
Q

How is deletion done in a linked list?

A

Requires connecting the preceding node to the following node.

19
Q

What is a doubly linked list?

A

Each node has three fields: info (data), next (address of next node), and prev (address of previous node).

20
Q

What is an advantage of doubly linked lists?

A

Allows traversal in both directions.

21
Q

What is a key difference between arrays and linked lists?

A

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.

22
Q

What is the floor function?

A

Think of this as ‘rounding down’ to the nearest whole number.

⎣3.14⎦ = 3 (round 3.14 down to 3)

23
Q

What is the ceiling function?

A

This is ‘rounding up’ to the nearest whole number.

⎡3.14⎤ = 4 (round 3.14 up to 4)

24
Q

What does the modulo operation do?

A

Gives you the remainder after division.

10 mod 3 = 1 (When you divide 10 by 3, you get 3 with 1 left over)

25
What is algorithm analysis?
Measuring how fast a recipe will take to make as the number of ingredients increases.
26
What is Big-O notation?
A way to describe the speed of an algorithm.
27
What does O(1) represent?
Takes the same time no matter how much data.
28
What does O(log n) represent?
Gets slightly slower as data grows.
29
What does O(n) represent?
Takes time directly proportional to data size.
30
What does O(n²) represent?
Gets much slower as data grows.
31
What does O(2ⁿ) represent?
Becomes impossibly slow quickly.
32
What are simple rules to figure out speed?
For regular loops: O(n), nested loops: O(n²), separate steps: slowest part matters, if/else statements: consider longer path.
33
Non-primitive data types are called 
reference types, because they refer to objects.
34
Primitive types in Java are
predefined and built into the language
35
non-primitive types are created by
the programmer (except for String).
36
Non-primitive types can be used to call
methods to perform certain operations
37
Primitive types start with a
lowercase letter (like int)
38
non-primitive types typically starts with
an uppercase letter (like String).
39
Primitive types always hold
a value
40
 non-primitive types can be
be null.
41
 Strings, Arrays, Classes are
non-primitive types