CSC-230 Recursion, Sorting Algorithms, and Data Structures Key Concepts

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/42

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.

43 Terms

1
New cards

What are the 3 key components of a recursive algorithm?

Decomposition, Composition, Base/stopping case

2
New cards

What is a base case in recursion?

A condition that stops recursion without making a recursive call

3
New cards

What is the factorial formula recursively?

factorial(0) = 1; factorial(n) = n × factorial(n-1)

4
New cards

What is tail recursion?

When there are NO pending operations after returning from a recursive call

5
New cards

What is the Fibonacci sequence formula?

fib(0) = 0; fib(1) = 1; fib(n) = fib(n-1) + fib(n-2)

6
New cards

What happens if a recursive function has no base case?

Infinite recursion / stack overflow error

7
New cards

What is the time complexity of recursive factorial?

O(n)

8
New cards

What is the time complexity of naive recursive Fibonacci?

O(2^n)

9
New cards

What is the time complexity of binary search (recursive)?

Best case: O(1); Worst case: O(log n)

10
New cards

What is the time complexity of Tower of Hanoi?

O(2^n)

11
New cards

How does Selection Sort work?

Partition into sorted/unsorted parts; select smallest element from unsorted

12
New cards

What is the time complexity of Selection Sort?

O(n²) for all cases

13
New cards

How does Insertion Sort work?

Divide into sorted/unsorted; insert first unsorted element into sorted part

14
New cards

What is the time complexity of Insertion Sort?

Best case: O(n); Average/Worst case: O(n²)

15
New cards

How does Bubble Sort work?

Compare adjacent elements and swap if out of order

16
New cards

What is the time complexity of Bubble Sort?

Best case: O(n); Worst case: O(n²)

17
New cards

How to optimize Bubble Sort?

Use a 'swapped' flag to terminate early if no swaps occur

18
New cards

What approach does Merge Sort use?

Divide-and-conquer approach

19
New cards

What are the 3 main steps of Merge Sort?

Divide, Conquer, Combine

20
New cards

What is the time complexity of Merge Sort?

O(n log n) for all cases

21
New cards

What is a disadvantage of Merge Sort?

Requires extra space O(n)

22
New cards

How does Quick Sort work?

Pick pivot, partition elements, recursively sort sub-arrays

23
New cards

What is the time complexity of Quick Sort?

Best/Average: O(n log n); Worst: O(n²)

24
New cards

How to improve Quick Sort pivot selection?

Use median-of-three method

25
New cards

Which sorting algorithms sort 'in place'?

Selection Sort, Insertion Sort, Bubble Sort, Quick Sort

26
New cards

What is a Linked List?

A sequence of nodes with data and a pointer to the next node

27
New cards

What are the components of a singly linked list node?

Data portion and next pointer

28
New cards

What does the last node in a Linked List point to?

null

29
New cards

What are the advantages of Linked Lists over Arrays?

Dynamic size, easy insertion/deletion, no contiguous memory required

30
New cards

What are the steps to insert at the front of a linked list?

Make new node point to first node, update front to new node

31
New cards

What are the steps to insert at the end of a linked list?

Locate last node, make new node point to null, update last node

32
New cards

What are the steps to delete the first node in a linked list?

Make front point to second node

33
New cards

What is a Stack?

LIFO data structure

34
New cards

What are the 3 basic operations of a Stack?

push, pop, peek

35
New cards

What are some use cases for Stacks?

Method call stack, expression evaluation, undo functionality

36
New cards

What is a Queue?

FIFO data structure

37
New cards

What are the 3 basic operations of a Queue?

add (enqueue), remove (dequeue), peek

38
New cards

What are some use cases for Queues?

Print job queues, process scheduling, waiting lines

39
New cards

What does Big O notation represent?

Upper bound on worst-case running time

40
New cards

What is the time complexity of nested loops (both go 0 to n)?

O(n²)

41
New cards

What is the divide-and-conquer paradigm?

Divide problem, conquer sub-problems, combine solutions

42
New cards

What does binary search return on a failed search?

-insertion_point - 1

43
New cards

Which sorting algorithm has the best performance?

Merge Sort: O(n log n) guaranteed