Data Structures & Algorithms - III Lecture Notes

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

1/39

flashcard set

Earn XP

Description and Tags

Practice flashcards covering simple sorting algorithms, 5-step problem solving, recursion, and divide and conquer strategies.

Last updated 10:19 AM on 7/10/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

40 Terms

1
New cards

According to the lecture, why is sorting considered a prerequisite for searching?

Sorting is an upfront investment that unlocks lightning-fast searching methods, like Binary Search.

2
New cards

Why can sorting massive datasets cause a system to crash or freeze?

Computers must compare elements one pair at a time rather than glancing at the data, making systematic ordering essential to avoid inefficiency.

3
New cards

What are three examples of sorted items providing benefits outside of the computer field?

Waste Management, Organization, and Pattern Recognition.

4
New cards

What is the core execution strategy of the Bubble Sort algorithm?

Compare adjacent items and swap them if the left item is greater than the right item.

5
New cards

Why is Bubble Sort practically unused in professional software development?

It suffers from massive inefficiency on large datasets.

6
New cards

What is the function signature provided in the code for Bubble Sort?

void bubbleSort(int arr[], int size)

7
New cards

How does Insertion Sort compare elements to find the correct position for a target card?

It compares the target with cards already in the hand from right to left, shifting larger elements to the right to create a gap.

8
New cards

In what industrial context is Insertion Sort considered highly efficient?

It is highly efficient for small or nearly sorted datasets.

9
New cards

Which advanced industrial algorithm uses Insertion Sort under the hood for small chunks of data?

Timsort

10
New cards

What is the worst-case Time Complexity for both Bubble Sort and Insertion Sort?

O(n2)O(n^2) (Quadratic Time)

11
New cards

Under what condition does Insertion Sort achieve O(n)O(n) Linear Time complexity?

When the data provided is already sorted.

12
New cards

What is the Space Complexity for both Bubble Sort and Insertion Sort?

O(1)O(1) (Constant Space)

13
New cards

What defines an "In-Place" sorting algorithm?

An algorithm that rearranges elements directly within the original space provided for the data structure.

14
New cards

List the 5 steps of the Universal Framework for problem solving.

  1. Read/Listen, 2. Visualize (Think of Examples), 3. BRUTE FORCE, 4. Optimize, 5. Test.
15
New cards

What are the 'Key Questions' to ask during Step 1 (Read/Listen) of problem solving?

What is our goal? What are we looking for? What do we start with? What information is given?

16
New cards

In Step 2 (Think of Examples), searching for 'cat' in the array ['bat', 'cat', 'dog'] is an example of what?

A Normal Case (standard, expected input).

17
New cards

What is 'Edge Case Planning' in the context of industry software engineering?

Planning for unexpected or strange user behaviors to prevent application crashes.

18
New cards

What is the primary goal of the BRUTE FORCE step in problem solving?

To overcome "blank page" syndrome by finding the easiest, most straightforward way to make the solution work.

19
New cards

What is a 'Proof of Concept' (POC)?

A demonstration to prove that a concept or idea works to avoid "building castles in the air."

20
New cards

What is the definition of a 'Minimum Viable Product' (MVP)?

The absolute baseline of a product or program that works completely and successfully.

21
New cards

When comparing search algorithms in Step 4 (Optimize), what is the efficiency of Binary Search compared to Linear Search?

Binary Search is O(log(n))O(\log(n)) while Linear Search is O(n)O(n).

22
New cards

What C++ header and function are suggested for handling case-insensitive string comparisons?

The header file and the strcasecmp() function.

23
New cards

What is the definition of Recursion?

A programming technique where a function calls itself inside its own definition to solve problems by breaking them into smaller, self-similar instances.

24
New cards

What are the two ironclad properties a recursive procedure must have?

The Base Case and the Recursive Step.

25
New cards

What is the 'Base Case' in recursion?

The smallest version of the problem that we know how to solve and where the function stops calling itself.

26
New cards

What system error occurs if a recursive function does not have a base case?

Stack Overflow

27
New cards

In the recursive factorial example, what is the base case for n!n!?

1! = 1

28
New cards

What specific data structure do recursive functions use under the hood?

A Last-In-First-Out (LIFO) structure known as the Stack.

29
New cards

Why does iteration have a lower space complexity than recursion?

Iteration uses O(1)O(1) space, while every recursive call requires extra space in the system's Stack Memory.

30
New cards

When is recursion considered the industry standard despite memory costs?

For hierarchical data (like file directories or DOM trees) and Divide-and-Conquer algorithms.

31
New cards

What are the three strict steps of the Divide & Conquer paradigm?

  1. Divide, 2. Conquer, 3. Combine.
32
New cards

What is the difference between Divide & Conquer and Recursion theory?

Divide & Conquer is the problem-solving strategy (theory), while Recursion is the mechanism to write the code (implementation).

33
New cards

In Merge Sort, how is the 'Divide' step executed?

The unsorted array is split in half repeatedly until there are nn sub-arrays of exactly 1 element.

34
New cards

What is the 'Conquer' step in Merge Sort?

A 1-element array is recognized as completely sorted by definition.

35
New cards

What is the Time Complexity of Merge Sort across all cases (Worst, Average, Best)?

O(nlog(n))O(n \log(n))

36
New cards

What is the Space Complexity of Merge Sort and why?

O(n)O(n), because it require allocation of temporary sub-arrays to store merged data.

37
New cards

When finding the MAX value using Divide & Conquer, what is the Time Complexity?

O(n)O(n) (Linear Time)

38
New cards

Why does finding the MAX value with Divide & Conquer result in O(n)O(n) rather than O(log(n))O(\log(n))?

The computer must touch every element to find the true maximum; it cannot discard half the array like in Binary Search.

39
New cards

What is the Space Complexity for the Divide & Conquer MAX value algorithm described?

O(log(n))O(\log(n)) (representative of the Stack Depth).

40
New cards

According to the lecture, what utility function is used to display the results of Merge Sort?

printArray(int arr[], int size)