
Verified & Latest Foundations-of-Computer-Science Dump Q&As with Correct Answers
Latest Foundations-of-Computer-Science dumps - Instant Download PDF
NEW QUESTION # 33
How can a user subset a NumPy array bmi to only include values over 23?
- A. bmi[bmi > 23]
- B. bmi.select(23)
- C. bmi.get_values(>23)
- D. bmi.where(bmi > 23)
Answer: A
Explanation:
NumPy supports a powerful technique calledBoolean indexing(also called Boolean masking) to filter arrays based on a condition. When you write bmi > 23, NumPy performs an element-wise comparison and produces a Boolean array of the same shape, containing True where the condition holds and False otherwise. Using that Boolean array inside square brackets, as in bmi[bmi > 23], tells NumPy to return a new 1D array containing only the elements whose mask value is True. This approach is heavily emphasized in scientific computing curricula because it expresses selection logic without explicit loops and runs efficiently in optimized compiled code.
Option B looks close but is not standard NumPy usage. The function commonly used is np.where(condition) or np.where(condition, x, y). While np.where(bmi > 23) can return indices, bmi.where(...) is not a NumPy array method; it is more associated with pandas objects. Options A and C are not valid NumPy APIs for filtering.
Boolean indexing is central in data analysis tasks such as removing invalid measurements, selecting a population subgroup, applying thresholds, and building feature subsets. It composes cleanly with vectorized computation, for example bmi[bmi > 23].mean(), enabling concise and high-performance numerical workflows.
NEW QUESTION # 34
What is an ndarray in Python?
- A. A module that provides network socket functions similar to XML.
- B. A built-in Python data array used to store collections of items.
- C. An n-dimensional array object provided by the NumPy library.
- D. A native Python object that represents a tree-like hierarchical data structure.
Answer: C
Explanation:
An ndarray is NumPy's fundamental data structure: ann-dimensional arraydesigned for efficient numerical computation. The term stands for "N-dimensional array," and it is implemented as numpy.ndarray. Unlike Python's built-in list, an ndarray stores elements in a compact, homogeneous format defined by its dtype (such as integers or floating-point numbers). This uniform representation enables fast, vectorized operations and efficient use of memory, which is why ndarray is central in scientific computing and data analysis.
An ndarray supports multiple dimensions: a 1D array behaves like a vector, a 2D array like a matrix (rows and columns), and higher-dimensional arrays represent tensors. Textbooks emphasize that ndarray operations are typically element-wise by default (for example, a + b adds corresponding elements), and that slicing and broadcasting allow powerful computations without explicit loops. This approach is both expressive and efficient because the heavy lifting happens in optimized low-level code.
Option A is incorrect because ndarray is not built into core Python; it comes from NumPy. Option B describes a tree, which is a different data structure entirely. Option D is incorrect because sockets and XML-related functionality belong to other parts of Python's standard library, not to NumPy or ndarray.
In short, an ndarray is the primary array object of NumPy, providing high-performance multi- dimensional numerical storage and computation.
NEW QUESTION # 35
Which action is taken if the first number is the lowest value in a selection sort?
- A. It swaps the selected element with the first unsorted element.
- B. The first number is duplicated.
- C. The first number is increased by one.
- D. It swaps the selected element with the last unsorted element.
Answer: A
Explanation:
Selection sort works by maintaining a boundary between a sorted prefix and an unsorted suffix. On each pass, the algorithm finds the smallest value in the unsorted portion and places it into the first position of that unsorted portion (which is also the next position in the sorted prefix). This is usually done by swapping the element at the minimum's index with the element at the boundary index (the "first unsorted element"). That description matches option D.
If the first element of the unsorted portion is already the smallest, then the minimum's index equals the boundary index. In textbook implementations, the algorithm may still execute a swap operation, but it becomes a swap of an element with itself (a no-op), leaving the array unchanged. Many implementations include a small optimization: perform the swap only if the minimum index differs from the boundary index.
Either way, conceptually the "action taken" by selection sort is still "swap the selected minimum into the first unsorted position," which is exactly what option D states.
Options A and B are unrelated to sorting; selection sort never increases or duplicates values. Option C is incorrect because selection sort swaps the minimum with thefirstunsorted element, not the last. After the swap (or no-op), the sorted region grows by one element, and the algorithm repeats from the next boundary position.
This logic is fundamental for understanding how selection sort ensures correctness: after pass i, the smallest i+1 elements are fixed in their final positions.
NEW QUESTION # 36
Which method converts the default smallest-to-largest index order of a list to instead be the opposite?
- A. reverse()
- B. invert()
- C. flip()
- D. sortDescending()
Answer: A
Explanation:
Python lists maintain an order, and sometimes you need to reverse that order so the last element becomes first and the first becomes last. The standard list method for reversing the elementsin placeis reverse(). For example, if nums = [1, 2, 3, 4], then nums.reverse() mutates the list so it becomes [4, 3, 2, 1]. This is a built-in operation taught in introductory programming texts because it is efficient and conceptually simple: it does not create a new list unless you explicitly copy the data.
It is important to distinguish reversing from sorting. Reversing changes the sequence order as-is, while sorting rearranges elements according to comparisons. The question refers to converting the index order to the opposite, which is reversing. If you wanted descendingsortedorder, you would typically use sort (reverse=True) or sorted(nums, reverse=True). But the direct method that reverses the list's order is reverse().
The other options are not standard Python list methods. sortDescending(), flip(), and invert() are not part of Python's built-in list API. Textbooks emphasize learning the correct method names because Python's standard library provides a consistent, widely used interface across programs. Thus, reverse() is the correct answer for reversing the index order of a list.
NEW QUESTION # 37
How is the NumPy package imported into a Python session?
- A. import num_py
- B. using numpy
- C. include numpy
- D. import numpy as np
Answer: D
Explanation:
In Python, external libraries are brought into a program using the import statement. NumPy, which provides the ndarray type and a large collection of numerical computing functions, is conventionally imported with an alias for convenience. The standard and widely taught pattern is import numpy as np. This imports the numpy module and binds it to the shorter name np, making code more readable and reducing repeated typing, especially in mathematical expressions such as np.array(...), np.mean(...), or np.dot(...).
Option A is incorrect because the module name is numpy, not num_py. Options C and D resemble syntax from other languages (for example, "using" in C# or "include" in C/C++), but they are not valid Python import mechanisms. Python's module system is based on imports, and the aliasing feature (as np) is built into the import statement.
Textbooks also emphasize that importing a package requires that it be installed in the active Python environment. If NumPy is not installed, import numpy as np will raise an ImportError (or ModuleNotFoundError in modern Python). Once imported, the alias np is used consistently in scientific computing materials, notebooks, and professional data analysis codebases, which is why this option is considered the correct and expected answer.
NEW QUESTION # 38
Which is the most powerful command line interface on Windows systems?
- A. Task Manager
- B. Control Panel
- C. Command Prompt
- D. PowerShell
Answer: D
Explanation:
On Windows,PowerShellis generally regarded as the most powerful command-line environment because it is both a shell and a scripting language designed for system administration and automation. Traditional Command Promptfocuses on running console commands and batch files with plain-text input and output.
PowerShell, by contrast, uses an object-oriented pipeline: commands (calledcmdlets) output structured objects rather than raw text. This enables more reliable scripting and data manipulation, since you can filter, sort, and transform results without fragile text parsing.
Textbooks covering operating systems and administration emphasize automation and management at scale.
PowerShell integrates tightly with Windows management technologies, such as WMI/CIM, the registry, services, event logs, and Active Directory environments. It also supports remote management, scripting modules, robust error handling, and modern security features. This makes it particularly suitable for tasks like provisioning users, configuring machines, auditing systems, and orchestrating deployments.
The other options are not command-line interfaces in the same sense. Task Manager is a GUI tool for viewing processes and performance. Control Panel is also GUI-based for system configuration. Command Prompt is a command line interface, but it is less capable for complex administration compared to PowerShell's scripting and object pipeline.
Therefore, from a computer science and systems perspective, PowerShell is the most powerful Windows CLI environment among the choices.
NEW QUESTION # 39
Which type of files are meant to be inaccessible to standard users, but can be critical in terms of functionality?
- A. Extension files
- B. Backup files
- C. Log files
- D. System files
Answer: D
Explanation:
Operating systems contain many files that are essential for booting, hardware support, security enforcement, and core services. These are generally referred to assystem files. Textbooks explain that system files are often protected by permissions and special attributes because accidental modification or deletion could destabilize the OS, break device drivers, prevent applications from running, or even stop the machine from booting.
Therefore, standard (non-administrator) users are typically restricted from accessing or altering them, and the OS may hide them by default to reduce the risk of user error.
Examples include kernel-related components, shared libraries, driver files, configuration databases, and critical service executables. Modern OS designs enforce protection through user accounts, access control lists, and privilege separation. This ensures only trusted processes and administrators can change system-critical components.
Log files record events and are sometimes protected, but many logs are readable by users or administrators depending on policy; they are not necessarily "meant to be inaccessible" in the same strict sense. Backup files are important for recovery but are not inherently system-critical for day-to-day operation, and their accessibility depends on organizational policy. "Extension files" is not a standard category; file extensions describe formats rather than a protected functional class.
Thus, the files intended to be inaccessible to standard users yet critical for functionality are system files, reflecting core OS security principles such as least privilege and integrity protection.
NEW QUESTION # 40
Which aspect is excluded from a NumPy array's structure?
- A. The data pointer
- B. The data type or dtype pointer
- C. The encryption key of the array
- D. The shape of the array
Answer: C
Explanation:
A NumPy ndarray is designed for efficient numerical computing, and its structure is defined by metadata required to interpret a contiguous (or strided) block of memory as an n-dimensional array. Textbooks and NumPy's own conceptual model describe key components such as: adata buffer(where the raw bytes live), a data pointer(reference to the start of that buffer), thedtype(which specifies how to interpret each element's bytes-e.g., int32, float64), theshape(the size in each dimension), andstrides(how many bytes to step in memory to move along each dimension). Together, these allow fast indexing, slicing, and vectorized operations without Python-level loops.
Options A, B, and C are all part of what an array must track to function correctly: the array must know where its data is, how it is laid out (shape/strides), and how to interpret bytes (dtype). In contrast, anencryption key is not a concept that belongs to the internal representation of a numerical array. Encryption is a security mechanism applied at storage or transport layers (for example, encrypting a file on disk or encrypting data sent over a network), not something built into the in-memory structure of a NumPy array object.
Therefore, the aspect excluded from a NumPy array's structure is the encryption key.
NEW QUESTION # 41
What are Python functions that belong to specific Python objects?
- A. Libraries
- B. Modules
- C. Scripts
- D. Methods
Answer: D
Explanation:
In object-oriented programming, amethodis a function that is associated with an object (or its class) and is called using the dot operator. In Python, everything is an object, and many operations are provided through methods. For example, "hello".upper() calls the upper method of a str object, and [1, 2, 3].append(4) calls the append method of a list object. Textbooks emphasize that methods operate on an object's internal state and typically receive the object itself as an implicit first argument (commonly named self in class definitions).
This is what distinguishes methods from standalone functions.
Modules, scripts, and libraries are different organizational concepts. Amoduleis a file containing Python code, including function and class definitions. Ascriptis a Python program intended to be run directly. A libraryis a collection of modules that provides reusable functionality. None of these terms specifically mean
"functions that belong to objects."
Understanding methods matters because it connects to encapsulation and abstraction: objects provide behaviors (methods) that manipulate their data in well-defined ways. This design enables clearer APIs and supports polymorphism, where different object types can expose methods with the same name but different implementations. In Python, method calls are central to working with built-in types (strings, lists, dictionaries) and with user-defined classes, making "methods" the correct term for functions that belong to specific objects.
NEW QUESTION # 42
What is the purpose of the pointer element of each node in a linked list?
- A. To indicate the next node
- B. To indicate the current position
- C. To store the data value
- D. To keep track of the list size
Answer: A
Explanation:
In a singly linked list, each node is a small record that typically contains two main parts: a data field and a pointer field. The data field stores the actual value being kept in the list. The pointer field stores the address or reference of another node. The pointer element's purpose is to connect one node to the next by indicating where the next node is located in memory. This is essential because linked-list nodes are not stored in contiguous memory locations the way array elements are. Nodes may exist anywhere in memory, and the pointer is what preserves the logical sequence of the list.
This design supports efficient structural changes. For traversal, a program starts at the head node and repeatedly follows the pointer to reach subsequent nodes. For insertion, a new node can be added by adjusting a small number of pointers instead of shifting many elements, as would be required in an array. For deletion, the list can "skip over" a node by updating the pointer in the previous node to reference the node after the removed one. The end of the list is typically represented by a null pointer value, signaling there is no next node.
Keeping track of list size or current position is not the responsibility of each node's pointer field; these are usually handled by separate variables or computed during traversal.
NEW QUESTION # 43
What is the correct way to represent a boolean value in Python?
- A. true
- B. "True"
- C. True
- D. "true"
Answer: C
Explanation:
Python has a built-in boolean type named bool, which has exactly two values: True and False. These are language keywords/constants and are case-sensitive. Therefore, the correct representation of a boolean value is True (capital T, lowercase rest) or False (capital F). This is consistently taught in introductory programming textbooks because it affects conditional statements (if, while), logical operations (and, or, not), and comparisons.
Option A, "True", is a string literal, not a boolean. While it visually resembles the boolean constant, it behaves differently: non-empty strings are "truthy" in conditions, but "True" == True is false because they are different types (str vs bool). Option B, "true", is also a string, and it differs in casing as well. Option D, true, is not valid in Python; it will raise a NameError unless a variable named true has been defined.
Textbooks also stress that boolean values often result from comparisons, such as x > 0, and that booleans are a subtype of integers in Python (True behaves like 1 and False like 0 in arithmetic contexts). Still, their primary use is representing logical truth values for control flow and decision- making.
NEW QUESTION # 44
The np_2d array stores information about multiple family members. Each row represents a different person, and the columns store family member attributes in the following order:
Age (years)
Weight (pounds)
Height (inches)
How is the weight of all family members selected from the np_2d array?
- A. np_2d[2, :]
- B. np_2d[1, :]
- C. np_2d[:, 1]
- D. np_2d[:, 2]
Answer: C
Explanation:
In a 2D NumPy array, rows and columns represent different dimensions of the data. The indexing form array
[row_selection, column_selection] allows you to select entire rows, entire columns, or submatrices. The slice :
means "all indices along this dimension." Since each row corresponds to a family member (a person), selecting weights forallfamily members means selectingall rowsfor the weight column.
The problem states the columns are ordered as: Age (column 0), Weight (column 1), Height (column 2).
Therefore, the weight column has index 1. The expression np_2d[:, 1] uses : to take every row and 1 to take the second column, producing a 1D array (or a column view) containing the weight values for all people.
Option A, np_2d[:, 2], would select the height column, not weight. Option C, np_2d[2, :], selects the third row (the third person) and all columns-age, weight, and height for just that one person. Option D, np_2d[1, :], selects the second person's entire row.
This column selection technique is fundamental in data analysis because datasets are often stored as
"rows = observations, columns = features," and extracting a feature vector is a frequent operation before computing statistics or building models.
NEW QUESTION # 45
What is another term for the inputs into a function?
- A. Procedures
- B. Variables
- C. Arguments
- D. Outputs
Answer: C
Explanation:
In programming, a function takes inputs, performs computation, and may return an output. The standard term for a function's inputs isarguments(also commonly discussed alongside the closely related termparameters).
Textbooks typically distinguish the two:parametersare the names listed in the function definition, while argumentsare the actual values supplied when the function is called. For example, in def f(x, y):, x and y are parameters. In the call f(3, 5), 3 and 5 are arguments. Many introductory materials use "arguments" informally to refer to the inputs overall, which matches the wording of this question.
Options A, B, and C do not fit the textbook definition. "Variables" is too broad; inputs can be literals, expressions, or variables, but the conceptual role is "arguments." "Procedures" are callable units of code (often used in some languages to mean functions without return values), not the inputs. "Outputs" refers to returned results, not what you pass in.
Understanding arguments is important because it connects to call semantics, scope, and correctness.
Different languages support positional arguments, keyword arguments, default values, and variadic arguments (e.g., *args, **kwargs in Python). This flexibility shapes API design and influences how programmers structure reusable code.
NEW QUESTION # 46
What is the main advantage of using NumPy arrays over regular Python lists for data analysis?
- A. NumPy arrays can only hold elements of the same type.
- B. NumPy arrays can concatenate lists by default.
- C. NumPy arrays can perform calculations over entire collections of values.
- D. NumPy arrays can bring different types into the array at the same time.
Answer: C
Explanation:
The primary advantage of NumPy arrays in data analysis is their support for fast, vectorized computation over whole collections of numeric data. A NumPy `ndarray` stores elements in a contiguous memory block with a single, fixed data type, enabling efficient low-level operations implemented in optimized C/Fortran code. As a result, expressions like `arr + 5`, `arr * arr`, or `np.mean(arr)` operate over the entire array without explicit Python loops. This style is commonly called **vectorization**, and it is a central theme in scientific computing textbooks because it is both clearer to read and significantly faster for large datasets.
Option A describes a property of Python lists, not NumPy arrays. Python lists can mix types freely, but this flexibility comes with overhead. Option B is true-NumPy arrays typically hold a single dtype-but it is not the main advantage; it is more of an implementation feature that enables speed and memory efficiency.
Option D is not a defining advantage; both lists and arrays can be concatenated, and NumPy provides dedicated functions such as `np.concatenate`, but concatenation is not the core reason NumPy dominates data analysis workflows.
# Because NumPy operations are applied element-wise across entire arrays and can leverage CPU vector instructions and efficient memory access patterns, they form the foundation for higher-level tools like pandas, SciPy, and many machine learning libraries. This is why the best answer is that NumPy arrays can perform calculations over entire collections of values.
NEW QUESTION # 47
Which protocol provides encryption while email messages are in transit?
- A. FTP
- B. IMAP
- C. HTTP
- D. TLS
Answer: D
Explanation:
"Encryption in transit" means protecting data while it moves across a network so that eavesdroppers cannot read or modify it. For email systems, this protection is most commonly provided byTLS (Transport Layer Security). TLS is a cryptographic protocol that can wrap application protocols (including mail protocols) to provide confidentiality, integrity, and server (and sometimes client) authentication. In practice, TLS is used to secure connections such as SMTP submission (often with STARTTLS or implicit TLS), IMAP over TLS, and POP3 over TLS. Textbooks present TLS as the standard successor to SSL and the foundation of secure communication on the modern Internet.
The other options are not correct in this context. FTP is a file transfer protocol and is traditionally unencrypted unless paired with additional security mechanisms (e.g., FTPS, which uses TLS, or SFTP, which uses SSH). HTTP is a web protocol; it becomes encrypted only when used as HTTPS, which again relies on TLS underneath. IMAP is an email retrieval protocol, butIMAP itself is not the encryption protocol- IMAP can be run over TLS (IMAPS) to become secure.
Therefore, the protocol that provides encryption while email messages (or email protocol traffic) are in transit is TLS.
NEW QUESTION # 48
Which statement describes the relationship between trees and graphs?
- A. Trees can have cycles.
- B. Trees can have unconnected nodes.
- C. Trees do not have levels.
- D. Trees cannot have cycles.
Answer: D
Explanation:
In discrete mathematics and computer science, atreeis a special kind ofgraph. The standard graph-theory definition is that a tree is aconnected, acyclicundirected graph. "Acyclic" means it containsno cycles, i.e., you cannot start at a vertex, follow a sequence of edges, and return to the starting vertex without repeating edges in a way that forms a loop. (Wikipedia) This property is exactly what makes option D correct.
The other options contradict the definition. If a structure has cycles, it is not a tree (though it may still be a graph). If it has unconnected nodes, it is not connected; such a structure is more like aforest(a disjoint union of trees) rather than a single tree. (Wikipedia) The idea of "levels" belongs to a particular computer-science representation called arooted tree, where one node is chosen as the root and nodes can be assigned depths
/levels based on distance from the root. But levels are not required in the abstract definition of a tree as a graph; they arise from choosing a root and orientation for convenience in algorithms like BFS/DFS, heaps, and parse trees.
So, the relationship is: every tree is a graph with extra structure-specifically, no cycles and (typically) connectivity-and the "no cycles" rule is the key distinguishing feature. (Discrete Mathematics)
NEW QUESTION # 49
What Python code would return the value 40 from np_2d, where np_2d = np.array([[1, 2, 3, 4], [10, 20, 30,
40]])?
- A. np_2d[3, 1]
- B. np_2d[0, 4]
- C. np_2d[4, 1]
- D. np_2d[1, 3]
Answer: D
Explanation:
In a 2D NumPy array, indexing is written as array[row_index, column_index] using zero-based indices. The array np_2d = np.array([[1, 2, 3, 4], [10, 20, 30, 40]]) has two rows (indices 0 and 1) and four columns (indices 0, 1, 2, 3). The value 40 is located in the second row and the fourth column. Using zero-based indexing, that corresponds to row index 1 and column index 3. Therefore, np_2d[1, 3] returns 40.
Option A attempts to access row 3, which does not exist and would raise an IndexError. Option C attempts to access column 4 in row 0, but valid column indices are only 0 through 3, so it would also error. Option D likewise refers to a non-existent row 4. Only option B uses valid indices and points to the correct location.
Textbooks emphasize multi-dimensional indexing because it underlies matrix operations, dataset manipulation, and feature extraction in data science. Correctly interpreting rows and columns is essential when rows represent observations (like people) and columns represent attributes (like age, weight, height). This question tests precise control over row/column addressing, which prevents subtle bugs in numerical analysis.
NEW QUESTION # 50
Which line of code below contains an error in the use of NumPy?
- A. arr = np.array([3, 2, 0, 1])
- B. wgu_list = np.quicksort(arr)
- C. import numpy as np
- D. print(wgu_list)
Answer: B
Explanation:
The NumPy library provides arrays and efficient numerical operations, including sorting. However, NumPy doesnotprovide a function named np.quicksort. That is the API misuse in the code, making option A the correct answer. In NumPy, sorting is commonly performed using np.sort(arr) (which returns a sorted copy) or arr.sort() (which sorts in-place). If a specific algorithm is desired, NumPy exposes it through the kind parameter, such as np.sort(arr, kind="quicksort"), kind="mergesort", or kind="heapsort". Textbooks present this as a typical design: a single sorting interface with selectable strategies, rather than separate top-level functions per algorithm name.
Option C is correct and necessary: import numpy as np is standard convention. Option B is also correct:
printing a variable is valid assuming it exists. Option D, written as arr = np.array([3, 2, 0, 1]), is valid NumPy usage for constructing a 1D array from a Python list.
A subtle point taught in scientific computing courses is that library APIs matter as much as syntax: you can write perfectly valid Python that still fails if you call a function that the library does not define. In this case, the fix is to replace np.quicksort(arr) with np.sort(arr) or np.sort(arr, kind="quicksort") depending on whether you need to specify the algorithm.
NEW QUESTION # 51
......
The Ultimate WGU Foundations-of-Computer-Science Dumps PDF Review: https://exams4sure.actualcollection.com/Foundations-of-Computer-Science-exam-questions.html