Sorting Algorithm Quiz & Answers

1. What of the following requires the most memory space?

a. Quick Sort
b. Bubble Sort
c. Merge Sort
d. Insertion Sort
e. Selection Sort

Answer: C. Source: https://www.bigocheatsheet.com/#:~:text=Array%20Sorting%20Algorithms%20%20%20%20Algorithm%20,%20O%20%28n%29%20%2010%20more%20rows%20

2. What sorting algorithm is canonically the best for data sets that cannot reside in memory (and must be persisted to disk)?

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

Answer: E. Merge sort. Source page 149 of Programming Interviews Exposed.

3. Which sorting algorithm does this describe?

Without doing comparisons among the elements, iteratively placing elements into buckets those items based on the least significant digit, then placing them into sub-buckets based on the second least significant digit, until it reaches the most significant digit.

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

Answer: A
Source: https://www.geeksforgeeks.org/radix-sort/

4. Which sorting algorithm does this describe?

Take non-overlapping partitions of the data set, order them individually, then build a larger ordered partition from the smaller sub-portions until you have an ordered result.

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

Answer: E. Source: Pages 148 and 149 of Programming Interviews Exposed.

5. Which sorting algorithm does this describe?

Gradually build a sorted array by taking one random element at a time from the source array. Each new element is placed in order via comparison with sorted elements in what will be the final result.

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

Answer: C. Insertion sort.
Source: Page 145 of Programming Interviews Exposed.

6. Which sorting algorithm does this describe?

Take one element to be a pivot value. Place all bigger and equal elements to the left of the pivot value and all the smaller values to the right. To sort these smaller sub-partitions to the left and right, take one element to be a pivot value. Place all bigger or equal elements of this subpartition to the right of this pivot value and elements that are smaller to the left.

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

Answer: F. Quicksort. Source: Page 146 of Programming Interviews Exposed.

7. Which sorting algorithm does this describe?

Find the smallest element then move it to the far left. Find the second smallest element, then move it to the second-to-most-left position. Find the third smallest element…

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

Answer: D. Source: Page 144 of Programming Interviews Exposed.

8. In the I.T. industry it is common to code various sorting algorithms in the workplace.

True
False

Answer: False. Source page 143 of Programming Interviews Exposed.

9. A comparison-based sorting algorithm in a worst case scenario can have which of the following runtime complexities?

a. O(N)
b. O(n log n)
c. O(n^2)
d. None of the above

Answer: B. Source: Page 144 of Programming Interviews Exposed by Mongan, Kindler and Giguere.

10. What is the average runtime complexity of insertion sort?

a. O(n)
b. O(n log n)
c. O(n^2)
d. None of the above.

Answer: C. Source page 146 of Programming Interviews Exposed by Mongan, Kindler and Giguere.

Sorting Algorithms Quiz

1. What of the following requires the most memory space?

a. Quick Sort
b. Bubble Sort
c. Merge Sort
d. Insertion Sort
e. Selection Sort

2. What sorting algorithm is canonically the best for data sets that cannot reside in memory (and must be persisted to disk)?

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

3. Which sorting algorithm does this describe?

Without doing comparisons among the elements, iteratively placing elements into buckets those items based on the least significant digit, then placing them into sub-buckets based on the second least significant digit, until it reaches the most significant digit.

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

4. Which sorting algorithm does this describe?

Take non-overlapping partitions of the data set, order them individually, then build a larger ordered partition from the smaller sub-portions until you have an ordered result.

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

5. Which sorting algorithm does this describe?

Gradually build a sorted array by taking one random element at a time from the source array. Each new element is placed in order via comparison with sorted elements in what will be the final result.

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

6. Which sorting algorithm does this describe?

Take one element to be a pivot value. Place all bigger and equal elements to the left of the pivot value and all the smaller values to the right. To sort these smaller sub-partitions to the left and right, take one element to be a pivot value. Place all bigger or equal elements of this subpartition to the right of this pivot value and elements that are smaller to the left.

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

7. Which sorting algorithm does this describe?

Find the smallest element then move it to the far left. Find the second smallest element, then move it to the second-to-most-left position. Find the third smallest element…

a. Radix sort
b. Bubble sort
c. Insertion sort
d. Selection sort
e. Merge sort
f. Quick sort

8. In the I.T. industry it is common to code various sorting algorithms in the workplace.

True
False

9. A comparison-based sorting algorithm in a worst case scenario can have which of the following runtime complexities?

a. O(N)
b. O(n log n)
c. O(n^2)
d. None of the above

10. What is the average runtime complexity of insertion sort?

a. O(n)
b. O(n log n)
c. O(n^2)
d. None of the above.

How Do You Troubleshoot a Script or Program That Automates Tasks when The Logs Do Not Help you?

Problem Scenario
An automated process is failing. You look in the logs and they don’t help you. You have Googled the error. What should you do?

Solution
Has it ever worked? If so, did something change?

If not, Google for the command most recently entered before the error happens. New characters could be added into the command that you do not realize. The command itself may not work (due to an upgrade to the OS or a change in a configuration).

Manually reproduce the process as you believe it is being implemented in a program to the best of your ability. Sometimes the automated process happens in a different user context or in a shell that does not have resources that you assumed were available.

What is Memoization?

Question
In computer programming, what is memoization?

Answer
Memoization is the act of pre-computing or pre-processing certain values for the sake of an algorithm's performance. Rather than perform the same exact operation (which could be very complex and computationally expensive) multiple times, memoization will involve writing code to compute it once and store it in memory as a variable. This optimization can allow the call stack to have less to store (e.g., when it circumvents recursion by accessing a variable's value) and you can reduce CPU consumption (by merely having a precomputed variable in memory).

See also pages 132 and 133 of Cracking the Coding Interview or https://en.wikipedia.org/wiki/Memoization

What Is The Third Way of the Three-Way Handshake?

Question
You want to know discretely what the third way of the three-way handshake is in the context of TCP/IP networking. What is it?

Short Answer
It is the sending of a TCP packet with a flag of "ACK" from the client to the server/destination.

Longer Answer
The third way is sending a TCP packet with the "ACK" flag (of which several potential flags are possible) to the destination:
Client -----> Server

TCP is used in HTTP communications. TCP uses a three-way handshake; each way has a specific flag in a TCP packet and a specific source and destination (among the two end point devices involved). When a workstation tries to connect to a website (e.g., https://www.continualintegration.com), the workstation sends a TCP packet with a SYN flag to www.continualintegration.com. Then the server sends a SYN-ACK to the client, and this is the second way. Then the client returns with a TCP packet with an ACK flag to the server, and this is the third way.

To read more, see these:
https://ddos-guard.net/en/terminology/protocols/tcp-3-way-handshake
https://www.techopedia.com/definition/10339/three-way-handshake
What Is The First Way of The Three-Way Handshake?
What Is The Second Way of The Three-Way Handshake?

What Is The Second Way of the Three-Way Handshake?

Question
You want to know discretely what the second way of the three-way handshake is in the context of TCP/IP networking. What is it?

Short Answer
It is the sending of a TCP packet with a flag of "SYN-ACK" from the server/destination to the initiating client (after the first way was completed).

Longer Answer
The second way is sending a TCP packet with the "SYN-ACK" flag (of which several potential flags are possible) to the destination:
Server -----> Client (initiating machine)

TCP is used in HTTP communications. TCP uses a three-way handshake; each way has a specific flag in a TCP packet and a specific source and destination (among the two end point devices involved). When a workstation tries to connect to a website (e.g., https://www.continualintegration.com), the workstation sends a TCP packet with a SYN flag to www.continualintegration.com. Then the server sends a SYN-ACK to the client, and this is the second way.

To read more, see these postings:
https://ddos-guard.net/en/terminology/protocols/tcp-3-way-handshake
https://www.techopedia.com/definition/10339/three-way-handshake
What Is The First Way of the Three-Way Handshake?
What Is The Third Way of the Three-Way Handshake?

What Is The First Way of The Three-Way Handshake?

Question
You want to know discretely what the first way of the three-way handshake is in the context of TCP/IP networking. What is it?

Short Answer
It is the sending of a TCP packet with a flag of "SYN" from the client to the server/destination.

Longer Answer
TCP is used in HTTP communications. TCP uses a three-way handshake; each way has a specific flag in a TCP packet and a specific source and destination (among the two end point devices involved). When a workstation tries to connect to a website (e.g., https://www.continualintegration.com), the workstation sends a TCP packet with a SYN flag to www.continualintegration.com.

The first way is sending a TCP packet with the "SYN" flag (of which several potential flags are possible) to the destination:
Client -----> Server

To read more, see these postings:
https://ddos-guard.net/en/terminology/protocols/tcp-3-way-handshake
https://www.techopedia.com/definition/10339/three-way-handshake
What Is The Second Way of The Three-Way Handshake?
What Is The Third Way of The Three-Way Handshake?

What Does a Colon Mean in Python when You See Something Like This “new_var = a[i:i + counter]”?

Question
You are not familiar with this example of a colon. It appears to be an assignment of a value to itself. You have seen Python function signatures with colons to explain the data type. You have seen colons to signify an if conditional or a for loop. You are not sure what this line of code does:

new_var = a[i:i + counter]

What does this type of colon syntax mean?

Answer
The colon above is not an assignment; the colon in the syntax in the question above is a slice. It is a slice of a list with a starting value "i" (that is inclusive) and a terminating value "i + counter" (that is exclusive). We recommend putting parentheses around the "i + counter" to make it more clear the order of operations.

Here is how we would code the above:

new_var = a[i:(i + counter)]

How Do You Use Python to Find The Latest Prices of Bitcoin, Ethereum, Litecoin and Ripple?

Problem scenario
You want to use Python to calculate the latest price of various cryptocurrencies. What should you do?

Solution
Prerequisite

This assumes you have installed pip.

Procedures
Install the Python package cryptocompare: pip install cryptocompare

Run this program:

import cryptocompare

print(cryptocompare.get_price('BTC', 'USD'))
print(cryptocompare.get_price('BTC', 'USD'))
print(cryptocompare.get_price('ETH', 'USD'))
print(cryptocompare.get_price('LTC', 'USD'))
print(cryptocompare.get_price('XRP', 'USD'))

If you want to receive free cryptocurrency by just learning more, try Coinbase; it is ideal for Americans. For Europeans, the platform/company Iconomi.com can allow you to buy crypto or learn more.