DCSN04C mid term

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/89

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 12:59 PM on 4/14/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

90 Terms

1
New cards

Searching

The process of locating a specific record with a particular key value.

2
New cards

LINEAR SEARCH (SEQUENTIAL SEARCH)

A method that checks each element one by one

3
New cards

Brute Force Approach

• No shortcut

• No assumption about order

• Just scan everything

4
New cards

Linear search

is SIMPLE but becomes SLOW as data grows.

5
New cards

BINARY SEARCH

a searching method that divides the data into halves repeatedly

6
New cards

Divide and Conquer

• Instead of checking ALL elements

• It eliminates half of the data each step

7
New cards

Binary search

is FAST but requires preparation (sorting)

8
New cards

BIG-O COMPLEXITY

Measures how operations scale as input size increases.

• Focus is NOT exact time

• Focus is growth behavior

9
New cards

Linear Search

None

Iterative

O(n)

Easy

10
New cards

Binary Search

Must be sorted

Divide & Conquer

O(log n)

Complex

11
New cards

BIG-O NOTATION

measures how fast an algorithm grows as input increases.

12
New cards

tree structure

• Data can be stored in different forms

• Efficiency depends on how we structure and access it

“Same data, different structure = different performance.”

13
New cards

BINARY SEARCH TREE (BST)

Fundamental Rule

Left child ≤ Parent ≤ Right child

organizes data for fast searching

14
New cards

TREE OPERATIONS (TRAVERSAL & SEARCH)

Inorder Traversal

Search

Min/Max

15
New cards

Inorder Traversal

• Left → Root → Right

• Output is sorted

16
New cards

Search

Compare and move left/right

17
New cards

Min/Max

Go extreme left/right

18
New cards

Binary Search Tree (BST) Search

A tree-based search where:

• Left child < Parent

• Right child > Parent

19
New cards

Sorting

arranging data in order (ascending/descending)

20
New cards

SIMPLE SORTING ALGORITHMS

Bubble Sort

Selection Sort

Insertion Sort

21
New cards

Bubble Sort

repeatedly swaps adjacent elements

Steps:

1. Compare adjacent elements

2. Swap if wrong order

3. Repeat

22
New cards

Selection Sort

finds the smallest element and places it in correct position

Steps:

1. Find minimum

2. Swap with first element

3. Repeat

23
New cards

Insertion Sort

builds sorted list one element at a time

Steps:

1. Take one element

2. Insert into correct position

24
New cards

EFFICIENT SORTING ALGORITHMS

Merge Sort

Quick Sort

Heap Sort

25
New cards

Merge Sort

Divide and conquer

Steps:

1. Divide array

2. Sort each part

3. Merge

26
New cards

Quick Sort

Uses pivot element

Steps:

1. Choose pivot

2. Partition

3. Recursively sort

27
New cards

Heap Sort

Uses heap data structure

28
New cards

TREE DATA STRUCTURES

• Root

• Parent / Child

• Leaf

• Height

29
New cards

In-order

Left → Root → Right

30
New cards

Pre-order

Root → Left → Right

31
New cards

Post-order

Left → Right → Root

32
New cards

Tree Traversal

In-order

Pre-order

Post-order

33
New cards

AVL Trees

Self-balancing BST

Key Idea:

• Balance factor = -1, 0, 1

34
New cards

Red-Black Trees

Balanced tree with rules:

1. Nodes are red or black

2. Root is black

3. No two red nodes adjacent

35
New cards

B-Trees & B+ Trees

Used in:

• Databases

• File systems

Key Idea:

• Multi-level indexing

• Efficient disk access

36
New cards

AVL Trees

are self-balancing Binary Search Trees. They automatically adjust themselves

to keep the height minimal, ensuring fast operations.

is a Binary Search Tree where the difference in height between the left

and right subtree (called the balance factor) is at most -1, 0, or +1.

37
New cards

RED-BLACK TREES

is also a self-balancing BST, but instead of strict balancing

it uses color rules to maintain balance.

is a Binary Search Tree where:

1. Each node is either Red or Black

2. The root is always Black

3. No two consecutive Red nodes

4. Every path has the same number of Black nodes

38
New cards

B-TREES

are multi-level, multi-child trees used in databases and file systems to handle

large amounts of data efficiently.

is a self-balancing tree where each node can have multiple keys and children,

designed to minimize disk reads.

39
New cards

B+ TREES

An improved version of B-Trees where all data is stored in leaf nodes, and leaves are

connected.

is a type of B-Tree where:

• Internal nodes store only keys (indexing)

• All actual data is stored in leaf nodes

• Leaf nodes are linked for fast traversal

40
New cards

AVL Tree

Strictly balanced

Fast searching

41
New cards

Red-Black Tree

Balanced with rules

Frequent insert/delete

42
New cards

B-Tree

Multi-children nodes

Databases

43
New cards

B+ Tree

Data in leaves only

Large systems & indexing

44
New cards

O(1)

Fastest

Constant

45
New cards

O(log n)

Fast

Dividing

46
New cards

O(n)

Normal

One-by-one

47
New cards

O(n²)

Slow

Nested loops

48
New cards

Bubble

O(n²)

Very slow

49
New cards

Selection

O(n²)

Simple

50
New cards

Insertion

O(n²)

Good for small

51
New cards

Merge

O(n log n)

Needs memory

52
New cards

Quick

O(n log n)

Fast in practice

53
New cards

Heap

O(n log n)

Efficient

54
New cards

Tree

tree is a finite nonempty set of elements.

It is an abstract model of a hierarchical structure.

consists of nodes with a parent-child relation.

Applications:

Organization charts

File systems

Programming environments

55
New cards

Root

node without parent (A)

56
New cards

Siblings

nodes share the same parent

57
New cards

Internal node

node with at least one child

58
New cards

External node (leaf )

node without children

59
New cards

Ancestors

parent, grandparent, grand-grandparent, etc of a node

60
New cards

Descendant

child, grandchild, grand-grandchild, etc of a node

61
New cards

Depth

number of ancestors

62
New cards

Height

maximum depth of any node (3)

63
New cards

Degree (node)

the number of its children

64
New cards

Degree (tree)

the maximum number of its node.

65
New cards

Subtree

tree consisting of a node and its descendants

66
New cards

Tree ADT

We use positions to abstract nodes

67
New cards

Generic methods of TREE ADT

integer size()

boolean isEmpty()

objectIterator elements()

positionIterator positions()

68
New cards

Accessor methods of TREE ADT

position root()

position parent(p)

positionIterator children(p)

69
New cards

Query methods of TREE ADT

boolean isInternal(p)

boolean isExternal(p)

boolean isRoot(p)

70
New cards

Update methods of TREE ADT

swapElements(p, q)

object replaceElement(p, o)

71
New cards

object

useful information

72
New cards

M

root of tree

73
New cards

Binary Tree

is a tree with the following properties:

  • Each internal node has at most two children (degree of two)

  • The children of a node are an ordered pair

We call the children of an internal node left child and right child

Alternative recursive definition: a binary tree is either

  • a tree consisting of a single node, OR

  • a tree whose root has an ordered pair of children, each of which is a binary tree

74
New cards

node

is represented by an object storing

Element

Parent node

Sequence of children nodes

75
New cards

Arithmetic Expression Tree

Binary tree associated with an arithmetic expression

internal nodes: operators

external nodes: operands

76
New cards

IN-order Traversal

a node is visited first going to its ancestor then on its sibling

77
New cards

Preorder Traversal

A traversal visits the nodes of a tree in a systematic manner

a node is visited before its descendants

78
New cards

Postorder Traversal

a node is visited after its descendants

79
New cards

Two Dimensional Array

It is an array of an array

Also called as tables or matrices

80
New cards

Row

first dimension of 2d array

81
New cards

Column

second dimension of 2d array

82
New cards

Curly braces

is the alternative constructor for 2D arrays

83
New cards

brackets

Declaration and instantiation of 2D array similar to that of 1D array

84
New cards

MATRIX

is a mathematical object which arises in many physical problems

Consists of m rows and n columns

m x n (read as m by n) is written to designate a matrix with m rows and n columns

85
New cards

LINEAR SEARCH

Checks every element of a list one at a time in sequence

Also called sequential search

86
New cards

Interpolation Search

is an improved version of binary search, especially suitable for large and uniformly distributed arrays. It calculates the probable position of the target value based on the value of the key and the range of the search space.

87
New cards

Jump Search

is another searching algorithm suitable for sorted arrays. It jumps ahead by a fixed number of steps and then performs a linear search in the smaller range.

an efficient searching algorithm for sorted arrays that balances the simplicity of Linear Search with the performance of Binary Search

88
New cards

Jump Search

works by skipping a fixed number of elements (jumping) and then performing a linear search within a specific block.

89
New cards

Time complexity

how long a task takes as the data increases

90
New cards

Space complexity

how much memory or space is needed