Locked in the 1P03

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/59

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

60 Terms

1
New cards

What is an array?

A data structure that holds multiple elements of the same type, accessed by index.

2
New cards

Are array indices zero-based or one-based in Java?

Zero-based.

3
New cards

What does the length property of an array represent?

The total number of elements (not the highest index).

4
New cards

Can the size of an array be changed after initialization?

No, array size is fixed once created.

5
New cards

What happens when you access an invalid index?

IndexOutOfBoundsException.

6
New cards

What are right-sized and variable-sized arrays?

Right-sized: exact number of needed cells.
Variable-sized: larger array with some unused cells tracked by a separate size variable.

7
New cards

What types can arrays hold in Java?

Primitive types (int, double, etc.) or objects (String, Student, etc.).

8
New cards

How do you traverse an array safely?

Use a for loop with condition i < array.length.

9
New cards

What is a 2D array?

An array of arrays (table-like), accessed by two indices [row][col].

10
New cards

What does data.length return for a 2D array?

The number of rows.

11
New cards

What are row-major and column-major traversals?

Row-major: iterate through rows first, then columns.
Column-major: iterate through columns first, then rows.

12
New cards

Lecture 2

13
New cards

What is asymptotic complexity?

A theoretical measure of an algorithm’s efficiency as input size grows

14
New cards

What does Big-O represent?

The worst-case upper bound of an algorithm.

15
New cards

What does Big-Ω (Omega) represent?

The best-case lower bound.

16
New cards

What does Big-Θ (Theta) represent?

The average case or tight bound.

17
New cards

Why do we ignore constants in Big-O?

Because constants are insignificant as input size grows very large.

18
New cards

What is the mathematical definition of Big-O?

f(x) ≤ C·g(x) for x ≥ k, where C and k are constants.

19
New cards

What is the order of efficiency from fastest to slowest?

O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ) < O(n!).

20
New cards

How do nested loops affect complexity?

Multiply their complexities (e.g., two O(n) loops = O(n²)).

21
New cards

How do sequential (non-nested) loops affect complexity?

Add their complexities, then keep the dominant term.

22
New cards

What is the Big-O of binary search?

O(log n).

23
New cards

What is a singly linked list?

A dynamic data structure made of nodes where each node points to the next.

24
New cards

What are the parts of a Node?

item (data) and next (reference to the next node).

25
New cards

What does the head variable represent?

The first node in the linked list.

26
New cards

What is the time complexity to access an element in a linked list?

O(n), because traversal starts from the head.

27
New cards

What does print() do?

Traverses the list and prints all items until null.

28
New cards

What is the time complexity of print()?

O(n).

29
New cards

What does insertAtFront() do?

Inserts a new node at the front (before the head).

30
New cards

What is the time complexity of insertAtFront()?

O(1).

31
New cards

What does removeAtFront() do?

Removes and returns the first node.

32
New cards

What is the time complexity of removeAtFront()?

O(1).

33
New cards

What does insertAtRearOnePointer() do?

Traverses to the last node and appends a new node at the end.

34
New cards

What is its time complexity?

O(n).

35
New cards

What does insertAtRearTwoPointers() do?

Uses two pointers (p, q) to reach the end before insertion.

36
New cards

What is sortedInsertion()?

Inserts a node while maintaining ascending order using two pointers.

37
New cards

Lecture 4

38
New cards

What is the purpose of sortedInsertion()?

Insert a node in its sorted position, maintaining list order.

39
New cards

What operator prevents NullPointerException in loops?

&& (logical AND short-circuit).

40
New cards

What does the remove() method do in a singly linked list?

Deletes a node by linking the previous node to the next one.

41
New cards

What is a tail reference?

A pointer to the last node, allowing O(1) insertion at the rear

42
New cards

What is a doubly linked list?

A structure where each node has a prev, item, and next, allowing bidirectional traversal.

43
New cards

What are the advantages of a doubly linked list?

Easier deletion and traversal in both directions.

44
New cards

What is the structure of a doubly linked list node?

prev, item, and next

45
New cards

How is sorted insertion done in a doubly linked list?

Create a new node between two existing ones and update both surrounding pointers.

46
New cards

What is the deletion rule in linked lists?

Nothing should point to the node being deleted — that’s when it’s garbage-collected.

47
New cards

What is a circular linked list?

A linked list where the last node’s next points back to the first node.

48
New cards

Lecture 5

49
New cards

What is an interface?

A blueprint for a class; defines methods (no code) and public instance variables.

50
New cards

What’s automatically true for interface variables?

They’re public static final (constants shared by all).

51
New cards

Can interfaces have private variables?

No — only public variables.

52
New cards

How do you implement an interface?

Use implements, match all method headers exactly (same name, parameters, return type, and must be public).

53
New cards

What happens if you miss a method when implementing?

Compilation error.

54
New cards

Can a class have more methods than defined in the interface?

Yes, extra methods are allowed.

55
New cards

What are the 4 types of Access Modifiers?

public, private, protected, and default (no keyword).

56
New cards

What’s an exception?

An event that disrupts normal program flow (error).

57
New cards

How to make a custom exception?

public class EmptyLinkedListException extends RuntimeException {}

58
New cards

How to throw an exception?

if (head == null) {

throw new EmptyLinkedListException();

}

59
New cards

How to catch an exception?

try {

// risky code

} catch (EmptyLinkedListException e) {

// handle error

}

60
New cards

Why catch exceptions?

Prevents program crash; lets you handle issues gracefully.