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.
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.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.