Miscellaneous Programming Quiz

(This quiz does not cover object-oriented programming or sorting algorithms. For a Python quiz, see this.)

1. What is a sink in a directed graph?
__________________

2. What is the difference between a vertex and a node?
__________________

3. Space complexity of a program, or its memory usage requirements, are often irrelevant compared to the computational complexity of the solution.

True
False

4. What usually happens when a data set is too large for memory but the data set needs to be ordered?

______________________________

5. How is an anchor case different from a base case in recursion?

a. An anchor case ensures the recursion doesn't go on forever, and the base case handles the iterations (the main benefit of recursion).
b. The case ensures the recursion doesn't go on forever, and the anchor case handles the iterations (the main benefit of recursion).
c. There is no such thing as an "anchor" case in recursion.
d. There is no such thing as a "base" case in recursion.
e. None of the above as they are synonyms.

6. What is the computational complexity of an operation going through a list of m lists with n items?

a. O(m)
b. O(n)
c. O (m log n)
d. O(n*m) (a quadratic)

7. What is the space complexity of an algorithm with an operation that exists simultaneously on the call stack for every list of m lists and every n item of those lists when the lists have a length of n?

a. O(1)
b. O(N)
c. O(m log n)
d. O(n log m)
e. O(n*m)

8. What is the space complexity of an operation going through a list of m lists where each list has n items with no simultaneous calls to the stack? The operation happens one at a time and does not simultaneously keep each individual operation on the stack.

a. O(1)
b. O(N)
c. O(m log n)
d. O(n log m)
e. O(n*m)

9. What is the significance of 10**9 + 7?

a. The highest integer value for a float.
b. The way to calculate pi to 9 decimal places.
c. 1000000007, a very large prime number used regularly in computer programming.
d. The largest known prime number.
e. None of the above

10. Can a Boolean conditional statement be considered ternary operator if there is one expression for True and one expression for False?

Yes.
No.

11. To do CI, you must have automated testing.

True
False

12. What could be the best space complexity of a given "for" loop that iterates through n items calling a function each time?

a. O(1)
b. O(n)
c. O(nlog(n))
d. None of the above.

13. What is a mutex?

a. A binary semaphore
b. A system-wide lock
c. A mutually exclusive lock
d. A concept for thread synchronization in multi-threading programming
e. All of the above.
f. None of the above

14. Which of the following statements is true for programs that solve problems with subproblems?

a. Dynamic programming excels when you do not need to compute every sub-problem and memoization is preferred when every sub-problem must be solved.
b. Memoization excels when you do not need to compute every sub-problem and dynamic programming is preferred when every sub-problem must be solved.
c. Dynamic programming is optimal compared to memoization.
d. Memoization is optimal compared to dynamic programming.
e. None of the above.

15. What is the computational complexity of looking for a node in a heap?

a. O(1)
b. O(log n)
c. O(n log n)
d. O(n)
e. None of the above.

16. What book says that "Representation is the essence of programming."?

a. The Art of Programming
b. The Mythical Man-Month
c. The Cathedral and the Bazaar
d. The DevOps Handbook
e. Refactoring by Beck and Fowler
f. Design Patterns: Elements of Reusable Object-Oriented Software
g. None of the above.

17. What are the differences between "string interpolation", "variable interpolation", "variable substitution", and "variable expansion"?
____________________


To see the answers, see this page.

Miscellaneous Programming Quiz & Answers

(This quiz does not cover object-oriented programming or sorting algorithms. For a Python quiz, see this.)

1. What is a sink in a directed graph?
__________________
Answer: A vertex with no route/edge to another vertex; a terminating vertex. Source: Elements of Programming Interviews in Python

2. What is the difference between a vertex and a node?
__________________

Answer: There is no difference. Source: StackOverflow.

3. Space complexity of a program, or its memory usage requirements, are often irrelevant compared to the computational complexity of the solution.

True
False

Answer: False. Source page 238 of The Mythical Man-Month.

4. What usually happens when a data set is too large for memory but the data set needs to be ordered?
_____________________

Answer: Data is separated into subfiles that are small enough to be read into memory two at a time. These subfiles are read into memory, sorted, and persisted into files again. Source: Page 149 of Programming Interviews Exposed: Secrets to Landing Your Next Job.

5. How is an anchor case different from a base case in recursion?

a. An anchor case ensures the recursion doesn't go on forever, and the base case handles the iterations (the main benefit of recursion).
b. The case ensures the recursion doesn't go on forever, and the anchor case handles the iterations (the main benefit of recursion).
c. There is no such thing as an "anchor" case in recursion.
d. There is no such thing as a "base" case in recursion.
e. None of the above as they are synonyms.

Answer: E. Taken from https://www.datacamp.com/community/tutorials/understanding-recursive-functions-python

The base case allows for termination (according to IBM's website).

We find the term "anchor case" to be used less frequently than the term "base case" in the context of recursion. Sometimes the term is called a "termination condition" or a "terminating condition".

6. What is the computational complexity of an operation going through a list of m lists with n items?

a. O(m)
b. O(n)
c. O (m log n)
d. O(n*m) (a quadratic)

Answer: D. Source: Page 40 of Cracking the Coding Interview.

7. What is the space complexity of an algorithm with an operation that exists simultaneously on the call stack for every list of m lists and every n item of those lists when the lists have a length of n?

a. O(1)
b. O(N)
c. O(m log n)
d. O(n log m)
e. O(n*m)

Answer: E. Source: Pages 40 and 41 of Cracking the Coding Interview. Recursion can involve simultaneous calls.

8. What is the space complexity of an operation going through a list of m lists where each list has n items with no simultaneous calls to the stack? The operation happens one at a time and does not simultaneously keep each individual operation on the stack.

a. O(1)
b. O(N)
c. O(m log n)
d. O(n log m)
e. O(n*m)

Answer: A. Source: Page 41 of Cracking the Coding Interview. Avoiding recursion can involve non-simultaneous call stack usage.

9. What is the significance of 10**9 + 7?

a. The highest integer value for a float.
b. The way to calculate pi to 9 decimal places.
c. 1000000007, a very large prime number used regularly in computer programming.
d. The largest known prime number.
e. None of the above

Answer: C. Source https://www.geeksforgeeks.org/modulo-1097-1000000007/

10. Can a Boolean conditional statement be considered ternary operator if there is one expression for True and one expression for False?

Yes.
No.

Answer: Yes. The conditional statement evaluating to True/False is the first expression. The action for True and the action for False are the second and third statements respectively. The word "ternary" means pertaining to three.

For the source of this answer see this: https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c-c/

11. To do CI, you must have automated testing.

True
False

Answer: False
Sources and their relevant excerpts:
"… automated testing is not strictly part of CI it is typically implied." taken from CloudBees' website.

"Simply put, CI is the process of integrating code into a mainline code base…CD is more complicated. CD is about the processes that have to happen after code is integrated for app changes to be delivered to users. Those processes involving testing, staging and deploying code." Taken from
https://devops.com/continuous-integration-vs-continuous-delivery-theres-important-difference/

12. What could be the best space complexity of a given "for" loop that iterates through n items calling a function each time?

a. O(1)
b. O(n)
c. O(nlog(n))
d. None of the above.

Answer: A. Source page 41 of Cracking the Coding Interview. To paraphrase, the calls do not simultaneously exist on the stack. Avoiding recursion can involve non-simultaneous call stack usage.

13. What is a mutex?

a. A binary semaphore
b. A system-wide lock
c. A mutually exclusive lock
d. A concept for thread synchronization in multi-threading programming
e. All of the above
f. None of the above

Answer: E.
Source: These three links help explain why:

StackOverlfow.com. (for A and B)

Sciencedirect.com. (For C)

Geeksforgeeks.org. (For D)

14. Which of the following statements is true for programs that solve problems with subproblems?

a. Dynamic programming excels when you do not need to compute every sub-problem and memoization is preferred when every sub-problem must be solved.

b. Memoization excels when you do not need to compute every sub-problem and dynamic programming is preferred when every sub-problem must be solved.

c. Dynamic programming is optimal compared to memoization.

d. Memoization is optimal compared to dynamic programming.

e. None of the above.

Answer: B. Source: https://stackoverflow.com/questions/6184869/what-is-the-difference-between-memoization-and-dynamic-programming
Explanation:

You can use memoization for only the subproblems you definitely need.

Dynamic programming can involve building up a table of subproblems. This can involve working backward from a solution where an algorithm is designed to compute different combinations of sub-problems; this is considered a bottom-up approach and it is ideal when every sub-problem must be evaluated any way (for business reasons).

The top-down approach of memoization involves keeping the call stack open and iterating through the subproblems to find a solution; the business requirement of avoiding certain sub-solutions could make the top-down approach of memoization ideal.

15. What is the computational complexity of looking for a node in a heap?

a. O(1)
b. O(log n)
c. O(n log n)
d. O(n)
e. None of the above.

Answer: D. Source page 80 of Programming Interviews Exposed by Mongan, Kindler and Giguere. See also stackoverflow.com.

16. What book says that "Representation is the essence of programming."?

a. The Art of Programming
b. The Mythical Man-Month
c. The Cathedral and the Bazaar
d. The DevOps Handbook
e. Refactoring by Beck and Fowler
f. Design Patterns: Elements of Reusable Object-Oriented Software
g. None of the above.

Answer: B. Page 229 of the 20th Anniversary Edition of The Mythical Man-Month.

17. What are the differences between "string interpolation", "variable interpolation", "variable substitution", and "variable expansion"?
____________________

Answer: There are no differences. A constant expression in computer programming is a placeholder of a variable. The terms to describe this practice are "string interpolation", "variable interpolation", "variable substitution", and "variable expansion"?

Three Companies Grew by 1,000% in Five Years

In the past five years as of 8/30/21,

Cryptocurrency and financial technology appear to have very bright futures. To learn more about cryptocurrency, read these postings. To get a book about cryptocurrency, see this list.

How Do You Troubleshoot WordPress Posting Previews That Don’t Wrap on One Page?

Problem scenario
You have a website powered by WordPress. You see a big gulf of space between your widgets/ads and your posting previews. It only happens on one page of previews (not other pages). The ads are too far to the right when the preview doesn't wrap. Why are your previews not wrapping on one page?

Solution
The problem may be one posting. Change the postings (e.g., dates or categories), so they appear on different pages. You may need to have fewer articles on a given page to narrow it down. Once you determine (isolate and identify) the posting that is causing the problem, modify that posting. The previews it is among will not wrap with the problem posting. Sometimes republishing the problem posting will eliminate the problem. Alternatively you could republish every posting on the preview page that has the problem.

How Do You Print the Current Price of Bitcoin with Python without Installing New Packages?

Problem scenario
You do not want to install new Python modules. How do you use Python to print out the latest price of Bitcoin?

Solution
Run this program:

import requests
resp = requests.get("https://api.coindesk.com/v1/bpi/currentprice/USD.json")
print(resp.json()['bpi'])

Here is a modified version of the program:

import requests
resp = requests.get("https://api.coindesk.com/v1/bpi/currentprice/USD.json")
print(resp.json()['bpi']['USD']['rate'])

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.

How Do You Troubleshoot ‘Target “release” does not exist in the project “apache-cassandra”‘?

Problem scenario
You try to run an ant command. But you get this error: 'Target "release" does not exist in the project "apache-cassandra"'

What should you do?

Solution
Omit the word "release" when you run the ant command.

How Do You Play a .WAV File Using Ubuntu?

Problem scenario
You want to listen to a .WAV (or an .mp3) file on your Ubuntu/Debian/Linux Mint machine from the command line. What should you do?

Solution
Run this: sudo apt -y install sox

Run this (but substitute "/play/to" with the path to your file and replace "nameof.wav" with the name of the file you want to listen to): play /path/to/nameof.wav

How Are Provisioners Different from Providers in Terraform?

Question
The terms provisioner and provider seem similar. How would one be compared versus the other? Are provisioners and providers in Terraform the same? If not, how are they different?

Answer
Provisioners in Terraform run commands and do various things to a given server (e.g., transfer a file, run a shell command, run chef-client commands). (This was taken from page 213 of Terraform: Up & Running, 2nd Edition by Yevgeniy Brikman (O'Reilly), Copyright 2019, 978-1-492-04690-5.)

Providers are resources to create platforms, infrastructure, or applications on. Examples of providers include AWS, Azure, GCP and Kubernetes. To read more about providers, see https://registry.terraform.io/browse/providers

Do You Build, Create, Develop, Grow, Produce or Write software?

Question
Attention to details such as terminology can be important in technical writing. When making software, should you use the term build, create, develop, grow, produce or write?

Answer
We think that context matters. It seems that the terms write or build are often ideal when you are describing the process for creating/producing a software product, application or "work."

Richard Stallman said 'I think it is ok for authors (please let's not call them "creators", they are not gods) to ask for money for copies of their works (please let's not devalue these works by calling them "content").' (This quote was taken from https://web.archive.org/web/20171108235001/http://mail.fsfeurope.org/pipermail/wsis-pct/2006-April/001115.html)

Fred Brooks said this:

I still remember the jolt I felt in 1958 when I first heard a friend talk about building a program, as opposed to writing one. In a flash be broadened my whole view of the software process. The metaphor shift was powerful, and accurate…
…any software system should be grown by incremental development…
…bit-by-bit it is fleshed out, with the subprograms in turn being developed into actions or calls…
…I find that teams can grow much more complex entities in four months than they can build.

http://worrydream.com/refs/Brooks-NoSilverBullet.pdf