50 multiple-choice questions with answers and detailed explanations. Untimed — choose an answer to check it instantly.
0/50 answered0 correct
Question 1 of 50
Which statement describes a queue data structure?
Correct answer: C) Insertions are at the back end, and deletions are at the front end
Explanation: A queue follows a First-In-First-Out (FIFO) principle, where items are added to the end (back) and removed from the front, making it suitable for scenarios requiring sequential processing.
Question 2 of 50
What are the official indexes for the list list01 given this declaration? int[] list01 = {0, 2, 4, 6, 8, 10};
Correct answer: B) 0, 1, 2, 3, 4, 5
Explanation: Arrays in Java and many programming languages are zero-indexed, meaning the first element starts at index 0, followed by consecutive indexes.
Question 3 of 50
Which abstract data type (ADT) allows retrieval of elements based on index or position?
Correct answer: C) List
Explanation: A list ADT enables indexing, allowing access to elements by their position, which is not supported in ADTs like stacks and queues.
Question 4 of 50
Which category of data does the tuple ("FB", 75.00, 75.03, 74.90) represent?
Correct answer: D) Tuple
Explanation: A tuple is an immutable sequence, often containing heterogeneous data. In Python, a tuple can store different types of data within a single grouping.
Question 5 of 50
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.
Question 6 of 50
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.
Question 7 of 50
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.
Question 8 of 50
In a dictionary d, which command retrieves all keys?
Correct answer: C) d.keys()
Explanation: d.keys() returns a view object of all the dictionary’s keys.
Question 9 of 50
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.
Question 10 of 50
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.
Question 11 of 50
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.
Question 12 of 50
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.
Question 13 of 50
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 "-----".
Question 14 of 50
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.
Question 15 of 50
What does the type() function in Python display?
Correct answer: C) Object’s data type
Explanation: type() outputs the data type of the specified object.
Question 16 of 50
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.
Question 17 of 50
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.
Question 18 of 50
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.
Question 19 of 50
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.
Question 20 of 50
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.
Question 21 of 50
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).
Question 22 of 50
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.
Question 23 of 50
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.
Question 24 of 50
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.
Question 25 of 50
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.
Question 26 of 50
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).
Question 27 of 50
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).
Question 28 of 50
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.
Question 29 of 50
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.
Question 30 of 50
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.
Question 31 of 50
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.
Question 32 of 50
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.
Question 33 of 50
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.
Question 34 of 50
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.
Question 35 of 50
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.
Question 36 of 50
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.
Question 37 of 50
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.
Question 38 of 50
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.
Question 39 of 50
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.
Question 40 of 50
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.
Question 41 of 50
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.
Question 42 of 50
What is the time complexity of binary search on a sorted array of n elements?
Correct answer: B) O(log n)
Explanation: Binary search halves the search range at each step, so it needs about log2(n) comparisons.
Question 43 of 50
Which data structure follows First-In, First-Out (FIFO) order?
Correct answer: C) Queue
Explanation: A queue removes elements in the order they were added. A stack is Last-In, First-Out (LIFO).
Question 44 of 50
What is the worst-case time complexity of quicksort?
Correct answer: A) O(n^2)
Explanation: Quicksort averages O(n log n), but poor pivot choices (for example on already sorted data) can make it O(n^2).
Question 45 of 50
Which tree traversal visits the nodes of a binary search tree in ascending order?
Correct answer: D) In-order
Explanation: In-order traversal visits left subtree, node, then right subtree, which produces sorted order in a binary search tree.
Question 46 of 50
What is the time complexity of accessing an element in an array by its index?
Correct answer: B) O(1)
Explanation: Arrays store elements contiguously, so the address of any index can be computed directly in constant time.
Question 47 of 50
In a hash table, what is a collision?
Correct answer: C) When two different keys hash to the same index
Explanation: Collisions are resolved with techniques such as chaining (lists at each bucket) or open addressing (probing for another slot).
Question 48 of 50
Which sorting algorithm repeatedly divides the list in half, sorts each half and merges them, with O(n log n) worst-case time?
Correct answer: A) Merge sort
Explanation: Merge sort is a divide-and-conquer algorithm that guarantees O(n log n) time but needs extra memory for merging.
Question 49 of 50
Which data structure is typically used to implement a priority queue efficiently?
Correct answer: D) Binary heap
Explanation: A binary heap supports inserting and removing the highest-priority element in O(log n) time.
Question 50 of 50
In a singly linked list, what does each node contain?
Correct answer: B) A value and a reference to the next node
Explanation: Each node stores its data and a pointer to the next node. Doubly linked lists also store a pointer to the previous node.
Set 1 complete
You scored 0%
0 correct out of 0 answered (50 questions in this set).