Chapter 10. Datatypes and Structures Flashcards

1
Q

What is an algorithm?

A
  • A step-by-step procedure or formula for solving a problem.
  • Consists of a finite set of instructions that produce a desired outcome.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the characteristics of a good algorithm?

A
  • Clear and unambiguous.
  • Finite: Has a clear end point.
  • Effective: Produces the correct result.
  • Efficient: Uses minimal resources.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are flowcharts used for in algorithm design?

A
  • Visual representations of the steps in an algorithm.
  • Use symbols like ovals for start/end, rectangles for processes, and diamonds for decision points.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are pseudocode and its purpose?

A
  • A high-level description of an algorithm using structured, natural language.
  • Bridges the gap between human language and programming code.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the basic control structures in algorithms?

A
  • Sequence: A set of instructions executed in order.
  • Selection: Decision-making (if-else statements).
  • Iteration: Repeating a set of instructions (loops).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between linear search and binary search?

A
  • Linear search: Checks each element one by one.
  • Binary search: Divides the search interval in half, requires a sorted list.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a recursive algorithm?

A
  • An algorithm that calls itself to solve smaller instances of the same problem.
  • Example: Factorial calculation, Fibonacci series.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the advantages of recursive algorithms?

A
  • Simplifies the code for problems that have a recursive nature.
  • Reduces the need for complex loops and conditionals.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the disadvantages of recursive algorithms?

A
  • Can lead to high memory usage (stack overflow) if not properly managed.
  • Often less efficient than iterative solutions.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the purpose of sorting algorithms?

A
  • To arrange data in a specific order (ascending or descending).
  • Examples: Bubble sort, quicksort, merge sort.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between bubble sort and quicksort?

A
  • Bubble sort: Simple but inefficient, compares adjacent elements.
  • Quicksort: More efficient, uses a divide-and-conquer approach.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a greedy algorithm?

A
  • An algorithm that makes the best choice at each step with the hope of finding the global optimum.
  • Example: Dijkstra’s algorithm for shortest path.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is dynamic programming?

A
  • A method for solving complex problems by breaking them down into simpler subproblems.
  • Stores the results of subproblems to avoid redundant computations.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between breadth-first search (BFS) and depth-first search (DFS)?

A
  • BFS: Explores all neighbors at the current depth before moving to the next level.
  • DFS: Explores as far as possible along each branch before backtracking.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a heuristic in problem-solving?

A
  • An approach to finding a satisfactory solution where finding an optimal solution is impractical.
  • Often used in artificial intelligence and optimization problems.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a backtracking algorithm?

A
  • An algorithm that tries to build a solution incrementally, removing solutions that fail to satisfy the problem constraints.
  • Example: Solving a maze or Sudoku puzzle.
17
Q

What is the role of a decision table in problem-solving?

A
  • A tabular method for representing and analyzing decision rules.
  • Helps in systematic identification of different possible actions.
18
Q

What is the difference between a deterministic and a non-deterministic algorithm?

A
  • Deterministic: Produces the same output for a given input every time.
  • Non-deterministic: May produce different outputs for the same input on different runs.
19
Q

What is a divide-and-conquer algorithm?

A
  • An algorithm that divides the problem into smaller subproblems, solves them independently, and combines their solutions.
  • Example: Merge sort, quicksort.
20
Q

What are the typical steps in algorithm design?

A
  • Understand the problem.
  • Plan the algorithm (pseudocode or flowchart).
  • Implement the algorithm.
  • Test and debug the algorithm.