{ "@context": "https://schema.org", "@type": "Organization", "name": "Brainscape", "url": "https://www.brainscape.com/", "logo": "https://www.brainscape.com/pks/images/cms/public-views/shared/Brainscape-logo-c4e172b280b4616f7fda.svg", "sameAs": [ "https://www.facebook.com/Brainscape", "https://x.com/brainscape", "https://www.linkedin.com/company/brainscape", "https://www.instagram.com/brainscape/", "https://www.tiktok.com/@brainscapeu", "https://www.pinterest.com/brainscape/", "https://www.youtube.com/@BrainscapeNY" ], "contactPoint": { "@type": "ContactPoint", "telephone": "(929) 334-4005", "contactType": "customer service", "availableLanguage": ["English"] }, "founder": { "@type": "Person", "name": "Andrew Cohen" }, "description": "Brainscape’s spaced repetition system is proven to DOUBLE learning results! Find, make, and study flashcards online or in our mobile app. Serious learners only.", "address": { "@type": "PostalAddress", "streetAddress": "159 W 25th St, Ste 517", "addressLocality": "New York", "addressRegion": "NY", "postalCode": "10001", "addressCountry": "USA" } }

Problem solving + Pseudocode Flashcards

(30 cards)

1
Q

What is a good first step when solving a new programming problem?

A

Understand the inputs and desired outputs, then break the problem into smaller steps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does ‘decomposition’ mean in programming?

A

Breaking a problem into smaller, more manageable sub-problems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does ‘divide and conquer’ mean?

A

A technique where a problem is divided into smaller parts, each solved recursively, and combined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give an example of divide and conquer.

A

Merge Sort: divide the array, sort each half, merge them back together.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why is recursion often used in divide and conquer?

A

Because each subproblem can be solved with the same method, reducing code repetition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you write pseudocode to reverse a string?

A

function reverse(s): result = “”, for i from length(s)-1 to 0: result += s[i], return result

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you find the largest number in an array (pseudocode)?

A

function max(arr): largest = arr[0], for each item in arr: if item > largest then largest = item, return largest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write pseudocode for a linear search.

A

function linearSearch(arr, target): for each item in arr: if item == target: return true, return false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write pseudocode for counting how many times a value appears in a list.

A

function countOccurrences(arr, value): count = 0, for item in arr: if item == value then count += 1, return count

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why is it useful to write pseudocode before coding?

A

It helps plan logic without worrying about syntax, making the code easier to write and debug.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you trace a recursive function by hand?

A

Use a call stack: track each function call and return value step by step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What’s the purpose of base cases in recursion?

A

They stop the recursion to prevent infinite loops and return final results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the three parts of a recursive function?

A

Base case, recursive call, and a step that moves toward the base case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe the problem-solving pattern: Input → Process → Output.

A

It means: Read inputs → Perform operations → Return/display results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Write pseudocode for checking if a number is even.

A

function isEven(n): return n % 2 == 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is an algorithm?

A

A finite set of steps that solve a problem or complete a task.

17
Q

How would you break down the problem ‘Find the average of a list of numbers’?

A

Add all numbers, divide by the number of items, return result.

18
Q

What is dry-run testing?

A

Manually walking through code or pseudocode to track variable values and ensure correctness.

19
Q

How can you simplify a complex problem?

A

Identify repeated patterns, use functions, or split into subproblems.

20
Q

What is an example of a brute-force approach?

A

Trying all possible combinations, such as checking every pair of numbers for a sum.

21
Q

Write pseudocode to count how many even numbers are in a list.

A

function countEvens(arr): count = 0, for each num in arr: if num % 2 == 0 then count += 1, return count

22
Q

Write pseudocode to check if a list is sorted in ascending order.

A

function isSorted(arr): for i from 0 to length(arr)-2: if arr[i] > arr[i+1] then return false, return true

23
Q

Write pseudocode to calculate the sum of all numbers in a list.

A

function sumList(arr): total = 0, for each num in arr: total += num, return total

24
Q

Write pseudocode to reverse the order of a list.

A

function reverseList(arr): result = [], for i from length(arr)-1 to 0: result.append(arr[i]), return result

25
Write pseudocode to return the index of the smallest number in a list.
function indexOfMin(arr): minIndex = 0, for i from 1 to length(arr)-1: if arr[i] < arr[minIndex] then minIndex = i, return minIndex
26
Write pseudocode to remove duplicates from a list.
function removeDuplicates(arr): result = [], for each item in arr: if item not in result then result.append(item), return result
27
Write pseudocode to count the frequency of each item in a list.
function countFrequencies(arr): freq = empty dictionary, for each item in arr: if item in freq then freq[item] += 1 else freq[item] = 1, return freq
28
Write pseudocode to return True if two lists are equal (same values, same order).
function areEqual(a, b): if length(a) != length(b) then return false, for i from 0 to length(a)-1: if a[i] != b[i] then return false, return true
29
Write pseudocode to merge two sorted lists into one sorted list.
function mergeSorted(a, b): result = [], i = 0, j = 0, while i < length(a) and j < length(b): if a[i] < b[j] then result.append(a[i]); i += 1 else result.append(b[j]); j += 1, append remaining elements from a and b, return result
30
Write pseudocode to check if a string is a palindrome.
function isPalindrome(s): for i from 0 to length(s)//2: if s[i] != s[length(s)-1-i] then return false, return true