SA1-ALGORITHM Flashcards

(79 cards)

1
Q

What is an algorithm?
Group of answer choices

A sequence of unambiguous instructions for solving a problem

A method for creating infinite loops

A set of ambiguous rules

A random sequence of instructions

A

A sequence of unambiguous instructions for solving a problem

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

Which of the following is NOT a characteristic of an algorithm?
Group of answer choices

Ambiguity

Effectiveness

Definiteness

Finiteness

A

Ambiguity

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

Which step involves translating each step of an algorithm into code?
Group of answer choices

Algorithm analysis

Algorithm specification

Implementation of an algorithm

Problem definition

A

Implementation of an algorithm

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

What is pseudocode?**
Group of answer choices

A programming language with strict syntax rules

A high-level description of an algorithm without syntax restrictions

A formal mathematical proof

A type of algorithm used only for sorting

A

A high-level description of an algorithm without syntax restrictions

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

What is the primary purpose of program testing?
Group of answer choices

To find errors in the program

To document the program

To optimize the program’s runtime

To prove the program is completely correct

A

To find errors in the program

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

Which of the following is NOT a fundamental data structure?
Group of answer choices

Algorithm

Linked list

Stack

Array

A

Algorithm

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

What is the time complexity of an algorithm?
Group of answer choices

The amount of memory it uses

The relationship between input size and the number of steps required

The number of lines of code

The clarity of the pseudocode

A

The relationship between input size and the number of steps required

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

What is the purpose of the Sieve of Eratosthenes?
Group of answer choices

Sorting numbers

Solving graph problems

Generating a list of prime numbers

Finding the greatest common divisor

A

Generating a list of prime numbers

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

Which algorithm is used to find the greatest common divisor (GCD) of two numbers?
Group of answer choices

Insertion sort

Bubble sort

Euclid’s algorithm

Binary search

A

Euclid’s algorithm

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

What is the key difference between arrays and linked lists?
Group of answer choices

Arrays are always sorted, while linked lists are not

Arrays cannot store integers, while linked lists can

Arrays use contiguous memory, while linked lists use arbitrary memory locations

Arrays are dynamic, while linked lists are static

A

Arrays use contiguous memory, while linked lists use arbitrary memory locations

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

Which data structure follows the LIFO principle?
Group of answer choices

Stack

Graph

Queue

Priority queue

A

Stack

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

What is the main advantage of binary search over sequential search?
Group of answer choices

Binary search is faster for large, sorted datasets

Binary search works on unsorted data

Binary search requires more memory

Binary search works only on strings

A

Binary search is faster for large, sorted datasets

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

What is a graph in computer science?
Group of answer choices

A collection of points called vertices connected by edges

A type of sorting algorithm

A method for storing strings

A collection of vertices and edges

A

A collection of points called vertices connected by edges

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

What is a tree in the context of data structures?
Group of answer choices

A sorting algorithm

A linear data structure

A connected acyclic graph

A type of graph with cycles

A

A connected acyclic graph

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

Which of the following is NOT a property of a binary search tree?
Group of answer choices

The tree is ordered

Values in the left subtree are smaller than the parent

Values in the right subtree are smaller than the parent

Each node has at most two children

A

Values in the right subtree are smaller than the parent

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

What is the maximum number of edges in an undirected graph with n vertices?
Group of answer choices

2n

n-1

n(n-1)/2

n

A

n(n-1)/2

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

What is the height of a tree?
Group of answer choices

The number of vertices in the tree

The length of the shortest path from the root to a leaf

The length of the longest simple path from the root to a leaf*

The number of edges in the tree

A

The length of the longest simple path from the root to a leaf*

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

Which sorting algorithm is typically implemented using recursion?
Group of answer choices

Bubble sort

Merge sort

Insertion sort

Selection sort

A

Merge sort

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

What is the main purpose of documentation in software development?
Group of answer choices

To make the program run faster

To reduce memory usage

To improve maintainability and knowledge transfer*

To replace testing

A

To improve maintainability and knowledge transfer*

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

What is recursion in the context of algorithms?
Group of answer choices

A process where a function calls another function repeatedly

A technique that avoids using functions entirely

A method that exclusively uses loops to solve problems

A process where a function calls itself directly or indirectly

A

A process where a function calls itself directly or indirectly

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

Which of the following best describes the difference between iteration and recursion?
Group of answer choices

Recursion is always faster than iteration

Iteration uses repetition structures while recursion uses selection structures

Recursion consumes less memory than iteration

Iteration uses the stack while recursion does not

A

Iteration uses repetition structures while recursion uses selection structures

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

What is the primary reason for defining a base case in a recursive function?
Group of answer choices

To avoid infinite loops

To increase execution speed

To allow multiple functions to be called simultaneously

To reduce memory usage

A

To avoid infinite loops

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

In the context of recursion, what is tail recursion?
Group of answer choices

When the recursive call is the last operation performed in the function

When the function calls another function instead of itself

When the recursive call happens at the beginning of the function

When there are multiple recursive calls within the same function

A

When the recursive call is the last operation performed in the function

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

What is the output of the following recursive function when n=3? int fun(int n){ if(n==1) return 1;else return 1 + fun(n-1);}
Group of answer choices

1

2

4

3

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the time complexity of an algorithm that checks each triple in an array of size N? Group of answer choices O(N³) O(N log N) O(N) O(log N)
O(N³)
26
Which asymptotic notation represents the worst-case scenario of an algorithm's running time? Group of answer choices Θ (Theta) β (Beta) O (Big Oh) Ω (Omega)
O (Big Oh)
27
What is space complexity in the context of algorithm analysis? Group of answer choices The number of CPU cycles needed to execute an algorithm The time it takes to compile an algorithm The amount of memory required by an algorithm to run The number of lines of code in an algorithm
The amount of memory required by an algorithm to run
28
If an algorithm has a space complexity of O(1), what does this indicate? Group of answer choices The space required grows exponentially with input size The space required is constant regardless of input size The space required depends on the number of recursive calls The space required grows linearly with input size
The space required is constant regardless of input size
29
What is the time complexity of binary search in a sorted array of size N? Group of answer choices O(N log N) O(log N) O(N²) O(N)
O(log N)
30
Which type of recursion occurs when a function calls another function, which in turn calls the original function? Group of answer choices Tail recursion Non-tail recursion Indirect recursion Direct recursion
Indirect recursion
31
What is the main advantage of iteration over recursion? Group of answer choices Iteration is easier to implement Iteration can handle larger input sizes Iteration typically consumes less memory Iteration is always faster
Iteration typically consumes less memory
32
In the context of algorithm analysis, what does the term "best case" refer to? Group of answer choices The maximum resources an algorithm might need The minimum resources an algorithm might need The average performance across all possible inputs The most common scenario encountered
The minimum resources an algorithm might need
33
What is the space complexity of an algorithm that uses a temporary array of size N? Group of answer choices O(log N) O(N) O(N²) O(1)
O(N)
34
Which of the following represents the correct order of growth rates from smallest to largest? Group of answer choices O(log N), O(1), O(N), O(N²), O(N log N) O(1), O(log N), O(N), O(N log N), O(N²) O(N²), O(N log N), O(N), O(log N), O(1) O(1), O(N), O(log N), O(N log N), O(N²)
O(1), O(log N), O(N), O(N log N), O(N²)
35
What is the time complexity of the following code snippet? for(int i=0; i Group of answer choices O(N²) O(N log N) O(log N) O(N)
O(N²)
36
Which of the following is TRUE about Big Omega (Ω) notation? Group of answer choices It represents the exact running time It represents both upper and lower bounds It represents the upper bound of an algorithm's running time It represents the lower bound of an algorithm's running time
It represents the lower bound of an algorithm's running time
37
What is the primary factor that determines the efficiency of an algorithm? Group of answer choices Only time complexity Both time and space complexity The programming language used Only space complexity
Both time and space complexity
38
Which of the following scenarios is best suited for using recursion? Group of answer choices Problems that can be broken down into smaller, similar subproblems Problems where execution speed is critical Problems requiring minimal memory usage Problems involving simple arithmetic operations
Problems that can be broken down into smaller, similar subproblems
39
What is the output of the following recursive function when n=5?void printNumbers(int n) { if(n == 0) return; System.out.println(n); printNumbers(n-1); } Group of answer choices 1 2 3 4 5 5 5 5 5 5 5 4 3 2 1 0 1 2 3 4
5 4 3 2 1
40
Which of the following best defines an algorithm? A. A vague set of steps to solve a problem B. A sequence of unambiguous instructions for solving a problem in a finite amount of time C. A computer program written in a specific language D. A set of mathematical equations with no specific order
B
41
2. Which requirement of an algorithm states that each step must be precisely defined and unambiguous? A. Finiteness B. Effectiveness C. Definiteness
C
42
What is the algorithm requirement that ensures it will always terminate after a certain number of steps? A. Finiteness B. Input C. Output D. Definiteness
A
43
In the problem development steps, which phase involves the programmer fully understanding the problem statement? A. Implementation of an Algorithm B. Problem definition C. Designing an Algorithm D. Program testing
B
44
What is the term for a mathematical proof that plays a critical role in formal verification because total correctness depends on it? A. Loop invariant B. Termination proof C. Recursive step D. Base case
B
45
Functional correctness of an algorithm refers to which behavior? A. The speed of the algorithm B. The input-output behavior C. The amount of memory used D. The length of the code
B
46
Which type of correctness requires that if an answer is returned, it will be correct, but does not guarantee the algorithm will terminate? A. Total correctness B. Partial correctness C. Absolute correctness D. Relative correctness
B
47
What is the primary purpose of program testing? A. To show that no errors exist B. To find errors C. To document the code D. To increase the speed of the program
B
48
Which of the following is a high-level description of an algorithm that avoids language-specific syntax but remains human-readable? A. Source code B. Binary code C. Pseudocode D. Assembly language
C
49
Who is the 9th-century mathematician from whose name the word "algorithm" is derived? A. Euclid B. Muhammad ibn Musa al-Khwarizmi C. Eratosthenes D. Alan Turing
B
50
Euclid’s algorithm is used to find which of the following? A. Prime numbers B. The shortest path in a graph C. Greatest common divisor (GCD) of two integers D. The median of a list
C
51
The Sieve of Eratosthenes is an algorithm designed to find: A. The square root of a number B. All prime numbers less than or equal to a given integer C. The factorial of a number D. The Fibonacci sequence
B
52
A sorting algorithm is considered "stable" if it: A. Does not require extra memory B. Terminates in $O(n)$ time C. Preserves the relative order of equal elements D. Is used for small datasets only
C
53
An "in-place" sorting algorithm is one that: A. Requires a significant amount of extra memory B. Does not require extra memory except for a few units C. Only works on arrays D. Is always recursive
B
54
Which searching algorithm divides the data into two parts at each stage and requires the data to be sorted? A. Sequential search B. Binary search C. Depth-first search D. Breadth-first search
B
55
Which data structure follows the Last-In, First-Out (LIFO) principle? A. Queue B. Linked list C. Stack D. Array
C
56
In a tree data structure, what is a vertex without children called? A. Root B. Leaf C. Parent D. Sibling
B
57
What is defined as the length of the longest simple path from the root to a leaf in a tree? A. Depth B. Height C. Breadth D. Degree
B
58
Which linear data structure consists of nodes where each node contains data and a pointer to the next node? A. Array B. Stack C. Linked list D. Queue
C
59
A binary tree is an ordered tree where every vertex has no more than: A. One child B. Two children C. Three children D. Four children
B
60
What is the process in which a function calls itself directly or indirectly? A. Iteration B. Recursion C. Compilation D. Encapsulation
B
61
To avoid infinite loops in recursion, what must be defined? A. A recursive call B. A global variable C. A base case D. A loop counter
C
62
Which structure does iteration typically use? A. Selection structure B. Repetition structure C. Jump structure D. Sequential structure
B
63
Which of the following is a disadvantage of recursion compared to iteration? A. Recursion makes the code longer B. Recursion is usually slower due to stack overhead C. Recursion uses less memory D. Recursion does not support complex tasks
B
64
When comparing memory usage, which is generally true? A. Recursion uses more memory than iteration B. Iteration uses more memory than recursion C. Both use the same amount of memory D. Neither uses memory while executing
A
65
The efficiency of an algorithm is analyzed based on which two main resources? A. Reliability and Scalability B. Time and Space C. Input and Output D. Complexity and Simplicity
B
66
Space complexity is the sum of which two components? A. Time space and Data space B. Auxiliary space and Input space C. Instruction space and Environment space D. Constant space and Variable space
B
67
Which type of space is used to save the compiled version of instructions? A. Data Space B. Environmental Stack C. Instruction Space D. Auxiliary Space
C
68
The "frequency count" in time complexity analysis refers to: A. The number of variables in the code B. The number of times a statement is executed C. The speed of the processor D. The size of the input
B
69
Which asymptotic notation represents the upper bound and the worst-case complexity of an algorithm? A. Big Omega ($\Omega$) B. Big Theta ($\Theta$) C. Big Oh ($O$) D. Small o
C
70
Which notation provides the best-case complexity or lower bound? A. Big Oh ($O$) B. Big Omega ($\Omega$) C. Big Theta ($\Theta$) D. Alpha notation
B
71
What is the time complexity class of Binary Search? A. $O(1)$ B. $O(\log n)$ C. $O(n)$ D. $O(n^2)$
B
71
Which notation is used for the average case as it represents a tight bound? A. Big Oh ($O$) B. Big Omega ($\Omega$) C. Big Theta ($\Theta$) D. Infinity notation
C
72
Bubble Sort is categorized under which complexity class? A. Linear B. Logarithmic C. Quadratic ($O(n^2)$) D. Exponential
C
73
If an algorithm's time complexity is $O(n!)$, it is described as: A. Constant B. Polynomial C. Factorial D. Cubic
C
74
What does "space complexity" primarily measure? A. The number of lines of code B. The amount of memory required for the algorithm to run C. The time it takes to compile D. The physical size of the computer
B
74
In Big-O notation, what is the rule regarding constant multipliers? A. They must be added to the result B. They should be dropped C. They are the most important part D. They should be squared
B
74
Which complexity class grows the fastest as the input size increases? A. $O(n)$ B. $O(n \log n)$ C. $O(2^n)$ D. $O(\log n)$
C
75
Successful documentation helps with which of the following? A. Increasing the clock speed of the CPU B. Maintenance and knowledge transfer C. Eliminating the need for testing D. Making the code run in $O(1)$ time
B
75
The systematic approach used to analyze algorithms is called the: A. Design Pattern B. Analysis Framework C. Logic Flow D. Complexity Map
B