1.
Check all statements that are true. (Some are false.)
Correct Answer(s)
A. Swift has Optionals, whereas Java 7 does not.
B. Swift has Structs, whereas Java 7 does not.
F. Swift has Type Inferencing, while Java does not.
I. A regular Array in Swift is mutable if you declare it using var, while a regular Array in Java is immutable regardless of how you declare it.
Explanation
The given answer is correct because it accurately identifies the true statements among the given options. It states that Swift has Optionals, Structs, Type Inferencing, and that a regular Array in Swift is mutable if declared using var, while a regular Array in Java is immutable regardless of how it is declared. These statements correctly highlight the differences between Swift and Java in terms of their features and behavior.
2.
In building the code for the Linked List, what main "cases" did you have to consider? Check all that apply.
Correct Answer(s)
A. The given Node belongs at the beginning and should replace the head because it is less than the head.
B. The given Node belongs at the end.
D. The given Node belongs in the middle.
Explanation
The code for the Linked List needs to consider the following main cases:
1. The given Node belongs at the beginning and should replace the head because it is less than the head. This means that if the value of the given Node is less than the value of the current head, it should become the new head.
2. The given Node belongs at the end. This means that if the Linked List is not empty, the given Node should be added as the last node.
3. The given Node belongs in the middle. This means that if the Linked List is not empty and the value of the given Node is between two existing nodes, it should be inserted in the appropriate position.
These are the main cases that need to be considered while building the code for the Linked List.
3.
Which of the following options best characterizes inOrder?
Correct Answer
A. Left, Head, Right
Explanation
The correct answer is "Left, Head, Right". In an inOrder traversal of a binary tree, the left subtree is visited first, then the current node (head), and finally the right subtree. This order ensures that the elements are visited in ascending order in a binary search tree.
4.
Which of the following best characterizes preOrder?
Correct Answer
D. Head, Left, Right
Explanation
PreOrder is a traversal method used in binary trees. It starts by visiting the head or root node, then visits the left subtree, and finally visits the right subtree. Therefore, the correct answer is "Head, Left, Right".
5.
Which of the following best characterizes postOrder?
Correct Answer
C. Left, Right, Head
Explanation
PostOrder is a traversal method used in binary trees where the left subtree is visited first, followed by the right subtree, and finally the root node. This means that the correct answer is "Left, Right, Head" because it accurately describes the order in which the nodes are visited during a postOrder traversal.
6.
Recursion is always the best way to code programs and create functions.
Correct Answer
B. False
Explanation
Recursion is not always the best way to code programs and create functions. While recursion can be a powerful tool in certain scenarios, it is not suitable for every situation. In some cases, using iterative approaches or other programming techniques can be more efficient and easier to understand. Therefore, the statement that recursion is always the best way is false.
7.
A Linked List is a ________ data structure.
Correct Answer
recursive
Explanation
A linked list is not a recursive data structure. It is a linear data structure consisting of nodes where each node contains a reference to the next node in the sequence. The term "recursive" refers to a function or algorithm that calls itself. In the context of data structures, recursive data structures are those that can be defined in terms of themselves, such as a tree or a graph.
8.
Each element of a Linked List is called a ________.
Correct Answer
Node, node
Explanation
A linked list is a data structure that consists of a sequence of elements, where each element is called a node. Each node contains two parts: data and a reference to the next node in the sequence. Therefore, in a linked list, each element is referred to as a node.
9.
Each of the elements of a Linked List is made up of ________ and ________.
Correct Answer
the data, data
a reference to the next Node, a reference to the next node
Explanation
The elements of a Linked List are composed of two components: the data, which holds the actual value or information, and a reference to the next Node, which points to the next element in the list. This allows for the creation of a sequence of connected nodes, where each node contains both data and a reference to the next node in the list.
10.
The last element of the list has a reference to ________.
Correct Answer
nil
Explanation
The last element of the list has a reference to nil because nil is a special value in many programming languages that represents the absence of a value or a null value. In this case, it indicates that there is no reference or value associated with the last element of the list.
11.
The reference to the first element of the list is called the ________.
Correct Answer
head
Explanation
The term "head" refers to the first element of a list. It is commonly used in programming languages to access or manipulate the initial element of a list. In this context, "head" is the correct answer as it accurately describes the reference to the first element of the list.
12.
The primary advantage of a Linked List is that it can both ________.
Correct Answer
grow and shrink
Explanation
A linked list has the ability to grow and shrink dynamically, which means that elements can be added or removed from the list at any time. This is because each element in a linked list contains a reference to the next element, allowing for easy insertion or deletion. Unlike arrays, linked lists do not require a fixed amount of memory, making them more flexible in terms of size. Therefore, the primary advantage of a linked list is its ability to accommodate changes in size, allowing it to grow or shrink as needed.
13.
One disadvantage of a Linked List is that you cannot ________ the elements directly.
Correct Answer
access
Explanation
A disadvantage of a Linked List is that you cannot directly access the elements. Unlike an array, where you can access elements using their index, in a Linked List, you need to traverse through the list starting from the head node to reach the desired element. This can be time-consuming, especially if the element you are looking for is towards the end of the list.
14.
What is the Big O notation for a search operation in a Linked List?
Correct Answer
A. Big O of n
Explanation
The Big O notation for a search operation in a Linked List is Big O of n. This means that the time complexity of searching in a Linked List is directly proportional to the size of the list. In other words, as the size of the list increases, the time taken to search for an element in the list also increases linearly.
15.
What is the Big O notation of an insertion operation in a Linked List at the head and at the tail?
Correct Answer
B. Head: Big O of 1 Tail: Big O of n
Explanation
The Big O notation of an insertion operation in a Linked List at the head is O(1) because inserting a new node at the head only requires updating a few pointers and does not depend on the size of the list. On the other hand, the Big O notation of an insertion operation at the tail is O(n) because inserting a new node at the tail requires traversing the entire list to reach the end before performing the insertion.
16.
What is the Big O notation of removing an element from the Linked List?
Correct Answer
D. Big O of n
Explanation
The Big O notation of removing an element from a Linked List is O(n) because in order to remove an element, we need to traverse the list to find the element that needs to be removed. The time complexity of traversing a Linked List is O(n) as we may need to visit all the elements in the worst case scenario. Therefore, the overall time complexity of removing an element from a Linked List is O(n).
17.
The value of all the nodes in the left sub-tree of a Binary Search Tree that DOES NOT handle duplicates must be ________ the root node.
Correct Answer
less than, lesser, less
Explanation
In a Binary Search Tree that does not handle duplicates, the left sub-tree of any node contains values that are less than the root node. This is because in a Binary Search Tree, the values in the left sub-tree are always smaller than the root node, while the values in the right sub-tree are always greater. Therefore, the correct answer is "less than, lesser, less".
18.
The value of all the nodes in the right subtree of a Binary Seach Tree must be ________ the root node.
Correct Answer
greater than, greater
Explanation
In a Binary Search Tree, the nodes in the right subtree must have values greater than the root node. This is because the Binary Search Tree follows a specific ordering property where all values in the left subtree are less than the root node, and all values in the right subtree are greater than the root node. Therefore, the correct answer is "greater than".
19.
What is the Big O notation of searching through a Binary Search Tree that is balanced (meaning that for all nodes, the difference in heights between left and right subtrees is at most 1)? If confused, just refer to the image for an example of a BALANCED Binary Search Tree.
Correct Answer
C. Big O of logn
Explanation
The Big O notation of searching through a balanced Binary Search Tree is O(logn). This is because in a balanced tree, the height of the tree is logarithmic in relation to the number of nodes. As a result, the time complexity of searching for a specific value in the tree is also logarithmic.
20.
Perform an inOrder transversal. Which of the following would be the correct result?
Correct Answer
C. 8 10 12 15 16 20 25
Explanation
The correct result for an inOrder traversal is to visit the left child, then the root, and finally the right child of each node in a binary tree. In the given options, the sequence "8 10 12 15 16 20 25" follows this pattern, as it starts with the leftmost child (8), then goes to its parent (10), and so on until it reaches the rightmost child (25). Therefore, "8 10 12 15 16 20 25" would be the correct result for an inOrder traversal.
21.
Which of the following options successfully completes the fibonacci sequence function?
Correct Answer
B. Return fib(n - 1) + fib(n - 2)
Explanation
The correct answer is "return fib(n - 1) + fib(n - 2)". This is because the Fibonacci sequence is defined by adding the two previous numbers in the sequence to generate the next number. So, returning the sum of fib(n - 1) and fib(n - 2) will give the correct value for the nth number in the Fibonacci sequence.
22.
The Big O notation for the put operation of an UnsortedMap is ________.
Correct Answer
n, Big O of n
Explanation
The Big O notation for the put operation of an UnsortedMap is "n", which represents the time complexity of the operation. This means that the time taken to perform the put operation on an UnsortedMap increases linearly with the size of the map. As the number of elements in the map (n) increases, the time taken to add a new element also increases proportionally. Therefore, the time complexity of the put operation in an UnsortedMap is O(n).
23.
The Big O notation for the get operation of an UnsortedMap is ________.
Correct Answer
n, Big O of n
Explanation
The Big O notation for the get operation of an UnsortedMap is n, Big O of n. This means that the time complexity of the get operation in an UnsortedMap is directly proportional to the number of elements in the map. As the number of elements increases, the time taken to retrieve a specific element also increases linearly.
24.
The Big O notation for the get operation of a SortedMap is ________.
Correct Answer
logn, Big O of logn, log(n)
Explanation
The Big O notation for the get operation of a SortedMap is logn, which represents the logarithmic time complexity. This means that as the size of the SortedMap increases, the time taken to perform the get operation will grow at a logarithmic rate. This is because a SortedMap typically uses a binary search tree or a balanced tree structure to store its elements, allowing for efficient retrieval of values. Therefore, the time complexity of the get operation is logarithmic, denoted as O(logn).
25.
The Big O notation for the put operation of a SortedMap is ________.
Correct Answer
n, Big O of n
Explanation
The Big O notation for the put operation of a SortedMap is n, Big O of n. This means that the time complexity of the put operation in a SortedMap is directly proportional to the number of elements in the map. As the size of the map increases, the time taken to perform the put operation also increases linearly.
26.
The Big O notation for both the put and get operation of a HashMap is ________.
Correct Answer
1, constant, c, Big O of 1, constant time
Explanation
The Big O notation for both the put and get operation of a HashMap is 1, constant, c, or Big O of 1, constant time. This means that regardless of the size of the HashMap, the time complexity for both operations remains constant. It implies that the time taken to perform these operations does not depend on the number of elements in the HashMap.
27.
Assembly language time! What is the difference between "Begin:" and ".Start Test"? (Look at your "Silly VM Architecture" sheet for hints! Do not overthink this. Just look at the words I put in quotations.)
Correct Answer
A. Begin: is a label definition while .Start Test is an assembly directive telling the assembler that the program will begin at label "Test."
Explanation
Begin: is a label definition that is used to mark a specific location in the assembly code. It is not an instruction or directive that affects the execution of the program. On the other hand, ".Start Test" is an assembly directive that specifically instructs the assembler that the program will start executing from the label "Test." This directive is necessary for the assembler to correctly generate the machine code. Therefore, the difference between "Begin:" and ".Start Test" is that the former is a label definition while the latter is an assembly directive.
28.
What are the first and second slots of memory used for in your assembler?
Correct Answer
C. The first slot is for telling the assembler how long the program is and the second slot is for telling the assembler where the program should begin executing.
Explanation
The first slot of memory is used to store information about the length of the program, while the second slot is used to indicate the starting point of program execution. This allows the assembler to properly allocate memory and execute the program from the correct location.
29.
You are now an assembler. And since it's your first day on the job, you are given the following basic line of assembly language: "Begin: .Integer #0 ;Begin Printing Doubles." What do you do?
Correct Answer
D. You would construct a symbol table with one of its labels being "Begin:" and the memory address being "0."
Explanation
The correct answer is to construct a symbol table with one of its labels being "Begin:" and the memory address being "0." This is because in assembly language, labels are used to mark specific locations in the code, and the memory address associated with the label indicates the location of the instruction or data in memory. In this case, the label "Begin:" is being associated with the memory address "0," indicating that the instruction or data following the label is located at address 0 in memory.
30.
Structs are value types in Swift.
Correct Answer
A. True
Explanation
Structs are indeed value types in Swift. In Swift, structs are used to create custom data types that can store properties and methods. Unlike classes, which are reference types, structs are value types. This means that when a struct is assigned to a new constant or variable, or when it is passed as a parameter to a function, a copy of its value is created. This is different from reference types, where multiple variables can refer to the same instance. Therefore, the statement "Structs are value types in Swift" is correct.
31.
An enumeration is... (Choose the BEST answer)
Correct Answer
C. A first class type that defines or encapsulates a group of related values.
Explanation
An enumeration is a first class type that defines or encapsulates a group of related values. It allows us to define a set of related values as a distinct type, making our code more readable and maintainable. Enumerations in Swift can have associated values and methods, providing additional functionality and flexibility. They are commonly used to represent a finite set of possible values or states.
32.
Was this quiz.... (The correct answer is "Easy. I breezed through it.")
Correct Answer
A. Easy. I breezed through it.
Explanation
The person who took the quiz found it to be easy and was able to complete it quickly without any difficulty.