Programming Algorithms Explained
- 26Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary factor that defines an algorithm, even if different methods produce the same numerical result?
What is the primary factor that defines an algorithm, even if different methods produce the same numerical result?
26 questions
- 1
What is the primary factor that defines an algorithm, even if different methods produce the same numerical result?
- A
The specific steps employed to successfully complete the computation
- B
The total number of variables declared throughout the entire function
- C
The programming language chosen for implementing the mathematical process
- D
The aesthetic appeal of the program's written source code structure
Correct answer
AThe specific steps employed to successfully complete the computation
Explanation
An algorithm is defined by the specific steps used to complete a computation. Even if multiple methods yield the same result, the sequence of operations constitutes the algorithm.
- A
- 2
Which factor is generally considered a primary indicator of a 'better' algorithm, assuming equal results are produced?
- A
The total number of steps required to complete its computation
- B
The number of times a function is called repeatedly
- C
The total amount of memory that the algorithm consumes
- D
The total number of unique variable names declared inside
Correct answer
AThe total number of steps required to complete its computation
Explanation
Generally, the fewer steps an algorithm takes to compute, the better it is. Other factors like memory usage can also be important, but step count is a primary measure.
- A
- 3
From which historical figure and field does the term 'algorithm' originate?
- A
Euclid, known for his work in classical geometry principles
- B
Leonardo Fibonacci, famous for his numerical sequences
- C
Isaac Newton, recognized for his contributions to calculus
- D
Muḥammad ibn Mūsā al-Khwārizmī, a Persian polymath
Correct answer
DMuḥammad ibn Mūsā al-Khwārizmī, a Persian polymath
Explanation
The term algorithm comes from the Persian polymath Muḥammad ibn Mūsā al-Khwārizmī, who was one of the fathers of algebra more than a millennium ago.
- A
- 4
What common data structure is described as a series of items, such as airfare prices, used for sorting in introductory programming examples?
- A
A binary tree, organizing data in a hierarchical structure
- B
An array, holding a collection of elements in sequence
- C
A hash table, mapping keys to associated values directly
- D
A linked list, connecting data elements through pointers
Correct answer
BAn array, holding a collection of elements in sequence
Explanation
A series of items, like airfare prices, is commonly called an array when discussing data representation in memory for sorting algorithms.
- A
- 5
What is the initial step in the Selection Sort algorithm when sorting an array in ascending order?
- A
Comparing the first two elements and swapping them if needed
- B
Splitting the array into two smaller, equal-sized halves
- C
Taking the last element and placing it at the very beginning
- D
Scanning the entire array to locate the very smallest number
Correct answer
DScanning the entire array to locate the very smallest number
Explanation
Selection Sort begins by scanning down the array to find the smallest number. Once found, it's swapped with the element in the first position.
- A
- 6
After finding the smallest number in the entire array during Selection Sort, what is the next action to sort in ascending order?
- A
It is left in its current position until all numbers are found
- B
It is placed at the very end of the array temporarily
- C
It is swapped with the number currently in the top location
- D
It is merged with another sorted sub-array immediately
Correct answer
CIt is swapped with the number currently in the top location
Explanation
Once the smallest number is found in Selection Sort, it is swapped with the number in the top (first unsorted) location to place it correctly.
- A
- 7
How does the Selection Sort algorithm proceed after the first smallest number has been placed in its correct position?
- A
It reverses the array and then applies the same sorting method again
- B
It repeats the entire process starting one spot below the previous start
- C
It recursively calls itself on the remaining, unsorted half of the array
- D
It inserts the next smallest number into a new array structure
Correct answer
BIt repeats the entire process starting one spot below the previous start
Explanation
Selection Sort repeats the same procedure, but instead of starting at the top, it starts one spot below the previously sorted section, effectively working on the remaining unsorted part.
- A
- 8
What computational complexity characterizes the Selection Sort algorithm when sorting N items, as expressed in Big O notation?
- A
It has a linear complexity, represented as O(N) for execution
- B
It exhibits a quadratic complexity, written as O(N^2) total
- C
It is characterized by a logarithmic complexity, O(log N) overall
- D
It performs with an exponential complexity, O(2^N) generally
Correct answer
BIt exhibits a quadratic complexity, written as O(N^2) total
Explanation
Selection Sort has a computational complexity of O(N^2) because it involves nested loops; one loop iterates through each position, and another nested loop finds the smallest number for that position.
- A
- 9
What is the impact on running time if an array size for Selection Sort increases from 8 items to 80 items?
- A
The running time increases by approximately 20 times in total
- B
The running time increases by approximately 50 times in total
- C
The running time increases by approximately 100 times in total
- D
The running time increases by approximately 10 times in total
Correct answer
CThe running time increases by approximately 100 times in total
Explanation
For Selection Sort, if the array size increases from 8 to 80 (10 times), the running time increases by 10 squared (100 times), from 64 to 6,400.
- A
- 10
What is the very first action performed by the Merge Sort algorithm when given an array of items?
- A
It checks if the array's size is greater than one element currently
- B
It reverses the entire order of all the items within the array
- C
It compares the first and last elements to determine their order
- D
It scans for the smallest item to place it at the beginning position
Correct answer
AIt checks if the array's size is greater than one element currently
Explanation
The first thing Merge Sort does is check if the size of the array is greater than 1. If it is, it proceeds to split the array.
- A
- 11
How does Merge Sort typically divide an array if its size is greater than one?
- A
It divides the array into three equal parts recursively
- B
It creates individual sub-arrays for each element found
- C
It splits the array into two distinct halves repeatedly
- D
It segregates elements based on whether they are even or odd numbers
Correct answer
CIt splits the array into two distinct halves repeatedly
Explanation
If an array's size is greater than one, Merge Sort splits the array into two halves. This splitting continues recursively until arrays of size one are created.
- A
- 12
What is the final stage of the Merge Sort algorithm, which gives it its characteristic name?
- A
The repeated merging of individually sorted arrays into larger sorted arrays
- B
The systematic comparison of each element with all other elements
- C
The initial scanning for the smallest element at the start of the array
- D
The process of recursively splitting arrays until they are single elements
Correct answer
AThe repeated merging of individually sorted arrays into larger sorted arrays
Explanation
After splitting, the final stage is merging. Merge Sort gets its name from the process of merging individually sorted arrays into larger sorted arrays until the entire array is sorted.
- A
- 13
What characterizes the 'Big O' computational complexity of the Merge Sort algorithm for N items?
- A
It is characterized by O(N^2), similar to Selection Sort generally
- B
It exhibits a complexity of O(log N), indicating efficiency always
- C
It has a complexity of O(N log N), combining comparisons and merges
- D
It shows an exponential complexity of O(2^N), growing very rapidly
Correct answer
CIt has a complexity of O(N log N), combining comparisons and merges
Explanation
The 'Big O' computational complexity of Merge Sort is O(N log N). The N comes from comparing and merging items, and the log N comes from the number of merge steps (due to repeated halving).
- A
- 14
In Merge Sort, what aspect of the algorithm contributes the 'log N' component to its computational complexity?
- A
The number of times the array is split into two halves
- B
The quantity of data transferred between memory locations
- C
The number of individual merge operations performed directly
- D
The number of times elements are compared individually
Correct answer
AThe number of times the array is split into two halves
Explanation
The 'log N' component in Merge Sort's complexity comes from the number of merge steps, which is logarithmically related to the number of items because the array is repeatedly split in half.
- A
- 15
What happens to the number of split steps in Merge Sort if an array's size doubles from 8 items to 16 items?
- A
The number of split steps also doubles from the original amount
- B
The number of split steps remains exactly the same as before
- C
The number of split steps is reduced by half in this scenario
- D
The number of split steps increases by exactly one additional step
Correct answer
DThe number of split steps increases by exactly one additional step
Explanation
If the array size doubles from 8 to 16, the number of split steps only increases by 1 (log base 2 of 8 is 3, log base 2 of 16 is 4). This demonstrates its efficiency.
- A
- 16
What is a 'graph' in the context of computer science algorithmic problems?
- A
A mathematical function representing data trends over time
- B
A graphical user interface element for data entry points
- C
A network of interconnected nodes joined by various lines
- D
A database schema defining relationships between tables
Correct answer
CA network of interconnected nodes joined by various lines
Explanation
A graph is defined as a network of nodes connected by lines, often used to represent relationships or paths, similar to cities and roads on a map.
- A
- 17
What term is used to describe the labels on lines connecting nodes in a graph, often representing duration or distance?
- A
A directional vector, showing the exact path of movement
- B
A cost or weight, indicating the value of traversing the line
- C
A node identifier, specifying the unique name of a location
- D
An adjacency matrix, representing all direct connections
Correct answer
BA cost or weight, indicating the value of traversing the line
Explanation
The lines in a graph can be labeled with a cost or weight, which often represents measures like time or distance between connected nodes.
- A
- 18
Which algorithmic approach involves systematically trying every possible permutation of an array to check if it is sorted?
- A
A greedy algorithm, making locally optimal choices at each step
- B
A divide and conquer strategy, splitting problems into smaller ones
- C
A brute force approach, exploring all possible solutions exhaustively
- D
A dynamic programming method, storing results of subproblems
Correct answer
CA brute force approach, exploring all possible solutions exhaustively
Explanation
A brute force approach would involve systematically trying every permutation of the array to check if it’s sorted, which has an N factorial complexity.
- A
- 19
What computational complexity characterizes a brute force approach to sorting by trying every permutation of N items?
- A
It has a complexity of N factorial, which is extremely inefficient
- B
It yields a linear complexity, performing tasks proportionally to input size
- C
It has a complexity of N squared, making it highly efficient for sorting
- D
It results in a logarithmic complexity, suitable for large datasets
Correct answer
AIt has a complexity of N factorial, which is extremely inefficient
Explanation
A brute force approach to sorting by trying every permutation would have an N factorial complexity, meaning the number of nodes times one less, and so on until 1, which is much worse than N squared.
- A
- 20
Which renowned computer scientist invented the classic algorithmic solution for finding the shortest path in a graph?
- A
Grace Hopper, a pioneer in programming language development
- B
Edsger Dijkstra, a prominent figure in computer science theory
- C
Donald Knuth, famous for his analyses of algorithms
- D
Alan Turing, known for his work on theoretical computer science
Correct answer
BEdsger Dijkstra, a prominent figure in computer science theory
Explanation
The classic algorithmic solution to the graph problem of finding the shortest path was invented by Edsger Dijkstra, and is appropriately named Dijkstra's algorithm.
- A
- 21
What is the initial state of node costs in Dijkstra's algorithm when starting from a source node with cost 0?
- A
All other cities are marked with question marks as unknown costs
- B
Every node is assigned a random cost value to begin calculations
- C
All connected nodes are immediately assigned their direct path cost
- D
Only the final destination node is given a definite, high cost value
Correct answer
AAll other cities are marked with question marks as unknown costs
Explanation
Dijkstra's algorithm starts with the source node having a cost of 0, and all other cities (nodes) are initially marked with question marks, indicating their costs are unknown.
- A
- 22
How does Dijkstra's algorithm decide which node to process next in its search for the shortest path?
- A
It always selects the node that is furthest away from the start node
- B
It randomly picks an unvisited node to explore next in the graph
- C
It consistently starts with the unvisited node that has the lowest known cost
- D
It prioritizes nodes with the highest number of direct connections
Correct answer
CIt consistently starts with the unvisited node that has the lowest known cost
Explanation
Dijkstra's algorithm always starts with the unvisited node that has the lowest known cost, processing paths from there to its connecting nodes.
- A
- 23
When Dijkstra's algorithm finds a new path to an already visited node with a higher total cost, what action does it take?
- A
It flags the node for re-evaluation in the subsequent algorithm rounds
- B
It overwrites the previous path with the new, higher cost path
- C
It disregards the new path and retains the previous, lower cost path
- D
It records both paths and averages their costs for later use
Correct answer
CIt disregards the new path and retains the previous, lower cost path
Explanation
If Dijkstra's algorithm finds a new path to a node with a higher total cost than a previously found path, it disregards the new path and sticks with the previous, better (lower cost) path.
- A
- 24
What was the initial computational complexity of Dijkstra's original algorithm, conceived in 1956?
- A
It exhibited a factorial complexity, O(N!)
- B
It was characterized by a linear complexity, O(N)
- C
It possessed a complexity of the number of nodes in the graph squared
- D
It had a logarithmic complexity, O(log N)
Correct answer
CIt possessed a complexity of the number of nodes in the graph squared
Explanation
Dijkstra's original algorithm, conceived in 1956, had a complexity of the number of nodes in the graph squared, which is not ideal for scaling to large problems.
- A
- 25
How was the computational complexity of Dijkstra's algorithm later improved, making it more efficient for large-scale problems?
- A
It was refined to N times log N, plus the number of lines
- B
It was improved to N cubed, but only for certain graph types
- C
It was simplified to just the number of lines, disregarding nodes
- D
It was optimized to N factorial, making it much faster now
Correct answer
AIt was refined to N times log N, plus the number of lines
Explanation
Dijkstra's algorithm was improved a few years later to take the number of nodes in the graph, times the log of the number of nodes, PLUS the number of lines, making it significantly faster.
- A
- 26
What real-world application commonly uses algorithms similar to Dijkstra's to find optimal routes?
- A
Online shopping carts to process and manage inventory levels
- B
Music streaming services to recommend personalized playlists
- C
Navigation services like Google Maps to calculate directions
- D
Social media feeds to determine content visibility and engagement
Correct answer
CNavigation services like Google Maps to calculate directions
Explanation
Every time you use a service like Google Maps to find directions, an algorithm much like Dijkstra's is running on servers to figure out the best route for you.
- A

Ask anything
We've read this whole study set, so questions about it get the best answers.