What operation does a queue perform when it removes the item at the front?
Correct answer:
B) Push
Explanation: The pop operation in a queue removes the item at the front, following the FIFO (First In, First Out) principle.
What operation does a queue perform when it removes the item at the front?
Correct answer:
B) Push
Explanation: The pop operation in a queue removes the item at the front, following the FIFO (First In, First Out) principle.
What is the output of the code my_list = [5, 10, 20] when calling print(my_list[0:2])?
Correct answer:
B) [5, 10]
Explanation: Slicing with [0:2] in Python includes elements from index 0 up to (but not including) index 2.
What operation would you use to create a duplicate of the list my_list?
Correct answer:
C) my_list[:]
Explanation: Slicing with [:] copies the entire list, producing a shallow copy.
In a dictionary d, which command retrieves all keys?
Correct answer:
C) d.keys()
Explanation: d.keys() returns a view object of all the dictionarys keys.
What is an advantage of using a linked list over an array for insertion operations?
Correct answer:
B) No shifting of elements needed for insertion
Explanation: Linked lists use pointers for node connections, allowing insertion without shifting elements, unlike arrays.
Which ADT allows duplicate items and does not require ordered elements?
Correct answer:
C) Bag
Explanation: Bags allow duplicates and do not impose any ordering on elements.
What is the primary purpose of a reference count in garbage collection?
Correct answer:
B) To indicate the number of variables referencing an object
Explanation: Reference counting tracks references to objects, marking those with zero references for collection.
What type of loop executes as long as its condition is true?
Correct answer:
B) while loop
Explanation: A while loop repeats as long as its condition remains true.
What would print(user_value * 5) display if user_value = "-"?
Correct answer:
D) -----
Explanation: Multiplying a string by 5 repeats it five times, resulting in "-----".
What is displayed when for i in range(3) is used in a loop?
Correct answer:
B) 0, 1, 2
Explanation: range(3) generates numbers from 0 up to (but not including) 3.
What does the type() function in Python display?
Correct answer:
C) Objects data type
Explanation: type() outputs the data type of the specified object.
What is the average runtime complexity of a shell sort?
Correct answer:
D) O(n log n)
Explanation: Shell sort generally performs at O(n log n) in its average case due to its gap-based sorting approach.
Which data type should be used for a large, fixed-size set of numbers in Java?
Correct answer:
B) Array
Explanation: Arrays are ideal for fixed-size data storage, providing efficient access and memory usage.
In a Python list, how would you retrieve elements from start to end-1 with a specified step?
Correct answer:
A) my_list[start:end:stride]
Explanation: Using start:end:stride accesses elements with specified intervals in a Python list.
Which ADT is used to associate keys with values, allowing fast retrieval?
Correct answer:
C) Dictionary
Explanation: Dictionaries allow key-value mappings, enabling fast lookups based on keys.
In a binary search tree, the right subtree of a node contains only nodes with values that are...
Correct answer:
C) Greater than the node
Explanation: In a binary search tree, the right subtree always holds values greater than the parent node.
What is the runtime complexity of searching in a binary search tree in its average case?
Correct answer:
B) O(log n)
Explanation: Searching in a balanced binary search tree has a complexity of O(logn)O(\log n)O(logn).
How are items organized in a priority queue?
Correct answer:
C) By priority value
Explanation: Priority queues dequeue items based on their priority levels rather than their insertion order.
Which traversal method visits nodes in the order: left child, root, right child?
Correct answer:
B) In-order
Explanation: In-order traversal visits the left child, then the root, and finally the right child, commonly used for BSTs.
What is an example of a Last-In-First-Out (LIFO) data structure?
Correct answer:
D) Stack
Explanation: Stacks operate on LIFO, where the most recently added item is the first to be removed.
What type of function complexity is represented by O(n^2)?
Correct answer:
B) Quadratic
Explanation: O(n^2) complexity grows quadratically, often observed in algorithms with nested loops.
Which function finds the smallest value in an unsorted list in linear time?
Correct answer:
A) min()
Explanation: The min() function inspects each element, achieving linear time complexity O(n).
What is the time complexity of insertion in a max heap?
Correct answer:
A) O(log n)
Explanation: Inserting in a max heap involves placing the item at the end and "bubbling up," which takes O(logn).
Which ADT operation returns the number of items in a stack?
Correct answer:
C) GetLength
Explanation: GetLength in stack implementations returns the count of items without altering the stack.
What sorting algorithm selects the smallest element and moves it to the correct position?
Correct answer:
C) Selection Sort
Explanation: Selection sort repeatedly selects the smallest unsorted element and moves it to its sorted position.
Which ADT is appropriate for a collection of distinct items without duplicates?
Correct answer:
C) Set
Explanation: Sets hold only unique items, discarding any duplicates added.
Which structure supports both FIFO and LIFO behaviors?
Correct answer:
B) Deque
Explanation: Deques allow insertion and removal from both ends, enabling FIFO and LIFO operations.
How can you remove a leaf node in a binary search tree?
Correct answer:
B) Unlink the node
Explanation: Removing a leaf node simply involves unlinking it, as it has no children.
What does the append method do in an array-based list?
Correct answer:
D) Adds an item to the end
Explanation: append adds an item at the list's end, expanding the array-based list size.
What does the pop function do in a priority queue?
Correct answer:
A) Removes and returns the item with the highest priority
Explanation: pop in a priority queue removes the highest priority item, regardless of insertion order.
Which Big-O notation describes a binary search?
Correct answer:
C) O(log n)
Explanation: Binary search halves the search space each time, yielding a logarithmic O(logn) complexity.
What is the Big-O notation for merging two sorted arrays?
Correct answer:
B) O(n)
Explanation: Merging two sorted arrays involves comparing and combining elements, requiring O(n) time complexity.
Which function would you use to retrieve a dictionary's items?
Correct answer:
B) dict.items()
Explanation: The items() function returns key-value pairs in the dictionary.
How are elements accessed in an associative array?
Correct answer:
C) By unique key
Explanation: Elements in an associative array (dictionary) are accessed through unique keys.
In a binary tree, how many parents does each node have?
Correct answer:
B) One
Explanation: Each node has one parent, except for the root node, which has no parent.
In Python, what would any(b) return if b is a dictionary?
Correct answer:
B) True if any key in b is true
Explanation: any(b) checks dictionary keys, returning True if any key evaluates as true.
What is the time complexity of traversing a binary search tree?
Correct answer:
C) O(n)
Explanation: Traversal of all nodes in a binary search tree takes linear time, O(n), as each node is visited once.
Which traversal method is useful for sorting a binary search tree?
Correct answer:
B) In-order
Explanation: In-order traversal produces nodes in sorted order in a binary search tree.
What structure is used to store a key-value pair in an associative array?
Correct answer:
C) Record
Explanation: Records are data structures holding named subitems like key-value pairs in dictionaries.
In a hash table, what is a bucket?
Correct answer:
C) A cell in the array to hold hash items
Explanation: Buckets are array cells where hash table items are stored based on hash values.
In a hash function, what property must be satisfied for secure hashing?
Correct answer:
C) Irreversibility
Explanation: Secure hashing requires irreversibility, preventing retrieval of input data from its hash.
In which data structure does the largest element in a max-heap tree reside?
Correct answer:
C) Root
Explanation: In a max-heap, the root contains the largest value, with smaller values in subsequent levels.
What complexity classifies an algorithm that breaks problems into smaller chunks?
Correct answer:
B) O(log n)
Explanation: Algorithms with logarithmic complexity (O(log n)) divide problems into progressively smaller parts.
What is a record in a data structure?
Correct answer:
C) A structure with subitems and named values
Explanation: Records store multiple subitems with named fields, grouping related data.
What type of ADT stores unique elements in an unordered manner?
Correct answer:
B) Set
Explanation: Sets store unique, unordered items, discarding duplicates.
What is the complexity of an algorithm using a doubly nested loop?
Correct answer:
B) O(n^2)
Explanation: A doubly nested loop yields quadratic complexity O(n2)O(n^2)O(n2) due to the pairwise iteration.
What does the peek function do in a stack?
Correct answer:
C) Returns the top item without removal
Explanation: The peek function in a stack views the top item without changing the stack's content.
What data structure allows removal of items in constant time on average?
Correct answer:
B) Hash Table
Explanation: Hash tables offer O(1) average-time removal by directly accessing items via hash indexes.
In which case would a doubly linked list be more beneficial than a singly linked list?
Correct answer:
C) When traversing in both directions
Explanation: Doubly linked lists support forward and backward traversal, which singly linked lists do not.
What is the primary use of a binary tree's in-order traversal?
Correct answer:
B) Sorting a tree
Explanation: In-order traversal of a binary search tree yields nodes in sorted order from least to greatest.
If this exam is giving you a hard time, let us be your helping hand. Contact us, and we'll provide the assistance you need to pass and move forward.