2.1, 2.3

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/56

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.

57 Terms

1
New cards

OOP v Procedural

OOP defines objects as independent entities with private attributes and methods; allows multiple instances without rewriting declarations; reduces code quantity and errors via reuse; subroutines self-contained ⟶ Procedural code executes statements in written order, requiring correct variable passing or use of globals

2
New cards

How private attributes improve the integrity of data

Properties are encapsulated and only accessible via methods; validation enforced on assignment; prevents accidental access or modification

3
New cards

What is meant by a record

A data structure storing multiple values (possibly of different types) under one identifier

4
New cards

Why a 1D array is suitable for a record

Enables indexed access to each item; holds multiple elements of the same type

5
New cards

Function

A routine that returns a value

6
New cards

Procedure

A routine that does not return a value

7
New cards

Similarities and differences of a record and a class

A record is a passive data structure; a class is a template for objects with private attributes and methods; both can store multi-type data under one name

8
New cards

Count-controlled loop meaning

A loop that repeats a fixed number of times

9
New cards

Purpose of pointerValue in stack

Points to the top of the stack (next free slot in the array)

10
New cards

Implementing a stack as a 1D array

Define array size; maintain a stack pointer; increment on push, decrement on pop

11
New cards

How a queue can be implemented using an array

Use head and tail pointers; increment tail on enqueue, head on dequeue (wrap via modulo)

12
New cards

Describe enqueue

Check for full: if (tail+1)%length == head then fail; advance tail = (tail+1)%length; store element at tail

13
New cards

Purpose of head pointer in a queue

Points to the first element (next to be removed)

14
New cards

Purpose of tail pointer in a queue

Points to the last element (most recently added)

15
New cards

Define queue

A dynamic FIFO data structure

16
New cards

Queue vs Stack

Queue is FIFO; Stack is LIFO

17
New cards

Characteristics of trees

Hierarchical with a root and leaves; nodes linked by edges; no cycles

18
New cards

How a leaf node is deleted from a BST

Locate node; clear its content; have parent point to node’s right child (or null); add cleared node to free list

19
New cards

Adding a node to a BST

Traverse to find parent; create new node; link parent to this node

20
New cards

Describe how a BST can be searched

Check root; if equal, done; if less traverse left subtree; if greater traverse right; repeat until found or empty

21
New cards

Directed vs Undirected graphs

Directed graphs have one-way edges; undirected have two-way

22
New cards

Graph vs Tree

Graphs have no fixed root, may have cycles and weights; trees are acyclic, rooted, hierarchical

23
New cards

Similarities of graph and tree

Both consist of nodes connected by edges; both are dynamic, non-linear structures

24
New cards

Purpose of headPointer in linked list

Indicates the first node in the list

25
New cards

Purpose of freeListPointer in linked list

Points to the next free node for insertion

26
New cards

Meaning of null pointer in linked list

Indicates end of the list (no further node)

27
New cards

Describe how a new item is added to end of a linked list

Check freeListPointer != null; insert at freeListPointer; traverse to last node; link its next to new; update freeListPointer

28
New cards

How an item is removed from a linked list

Traverse to node before target; set its next pointer to target.next

29
New cards

How backtracking is used in depth-first traversal

Descend one branch to leaf, pushing visited nodes onto stack; on leaf backtrack to last node with unvisited children; repeat

30
New cards

Breadth-first vs Depth-first

Breadth-first uses a queue, good when target is near root, O(n) time; Depth-first uses a stack (or recursion), good when target is deep, O(n) time, linear space

31
New cards

Max number of passes to bubble sort list of length N

N

32
New cards

Describe bubble sort

Compare each pair of adjacent elements, swapping if out of order; repeat passes until no swaps occur

33
New cards

Bubble sort complexities

Best O(n); average/worst O(n²); space O(1)

34
New cards

Disadvantages of bubble sort

Inefficient O(n²) worst time; outperformed by insertion, quick-, and merge-sort

35
New cards

Insertion sort complexities

Best O(n); worst O(n²); space O(1)

36
New cards

Describe merge sort

Recursively split list into sublists until single items; merge pairs by comparing heads into a new list; repeat until fully merged

37
New cards

Describe quicksort

Select pivot; partition elements into less-and greater-than lists; recursively sort partitions

38
New cards

Why quicksort is divide-and-conquer

Decomposes problem into smaller subsets, sorts each, then combines

39
New cards

Define heuristics

Rules-of-thumb estimating distance to goal, guiding search order

40
New cards

Precondition of binary search

Data must be ordered

41
New cards

Binary search complexities

Time O(log n); space O(1)

42
New cards

Describe binary search

Compute midpoint; compare to target; if equal return; if less search right (or left if greater); repeat until bounds cross

43
New cards

Describe linear search

Scan sequentially comparing each element to target until found or end reached

44
New cards

Linear search complexity

Time O(n); space O(1)

45
New cards

Define abstraction

Removal of unnecessary details to focus on core aspects

46
New cards

Need for abstraction

Reduces development time and code complexity; lowers resource requirements; simplifies understanding

47
New cards

Define caching

Storing previously accessed data for faster future retrieval

48
New cards

Benefits and drawbacks of caching

Improves speed when items repeat; relies on data locality

49
New cards

Need for reusable components

Improves efficiency, maintainability and readability; enables independent testing; saves development time; supports libraries and collaboration

50
New cards

Define decomposition

Breaking a problem into smaller sub-problems

51
New cards

Why decompose

Makes development, testing and reuse easier; enables parallel work; clarifies design

52
New cards

Describe concurrent processing

Multiple threads/processes run in parallel (or interleaved), each with processor time slices

53
New cards

Benefits of concurrent processing

Better CPU utilisation; long tasks don’t block short; keeps UI responsive

54
New cards

Benefits on shared data structures

Handles multiple simultaneous requests; avoids queuing delays; allows parallel reads/writes

55
New cards

Drawbacks of concurrent processing

Some tasks must remain serial; speedup not linear with cores; adds complexity

56
New cards

Drawbacks on shared data structures

Storage bottlenecks; requires locking (risk of deadlocks); complicates programming

57
New cards