Question 1 of 50
Which data structure stores unordered items by mapping each item to a specific location in an array?
Correct answer:
C) Hash Table
Explanation: Hash tables use a hashing function to map data to specific array locations, allowing efficient access and storage of unordered items.
Question 2 of 50
Which ADT requires only unique elements and does not allow duplicates?
Correct answer:
D) Set
Explanation: Sets do not allow duplicate values, ensuring each element is unique within the data structure.
Question 3 of 50
What type of loop is generally associated with O(n^2) complexity?
Correct answer:
B) Nested loop
Explanation: Nested loops typically exhibit quadratic time complexity, O(n2), because each loop iterates over the data structure.
Question 4 of 50
What is the time complexity of accessing a specific element in an array?
Correct answer:
B) O(1)
Explanation: Accessing an element by index in an array takes constant time O(1), as it does not depend on the array size.
Question 5 of 50
Which data structure stores nodes with a parent-child relationship, and each node has at most two children?
Correct answer:
C) Binary Tree
Explanation: In a binary tree, each node can have up to two children, called the left and right child.
Question 6 of 50
Which sorting algorithm uses comparisons to arrange elements in order?
Correct answer:
C) Quick Sort
Explanation: Quick Sort is a comparison-based sorting algorithm that arranges elements by comparing values around a pivot.
Question 7 of 50
What is the Big-O notation for the worst-case time complexity of bubble sort?
Correct answer:
C) O(n^2)
Explanation: Bubble sort has a quadratic time complexity O(n2) in the worst case due to repeated comparisons and swaps.
Question 8 of 50
What is a characteristic of linked allocation in data structures?
Correct answer:
B) Allocates memory dynamically with pointers
Explanation: Linked allocation uses pointers to dynamically allocate memory as needed, making it flexible and non-contiguous.
Question 9 of 50
What is the output of print(my_list[2:]) if my_list = [5, 10, 20, 40, 80]?
Correct answer:
B) [20, 40, 80]
Explanation: Slicing with [2:] retrieves elements starting from index 2 to the end of the list.
Question 10 of 50
What is an advantage of using a doubly linked list over a singly linked list?
Correct answer:
C) Allows traversal in both directions
Explanation: Doubly linked lists support both forward and backward traversal, thanks to pointers to both previous and next nodes.
Question 11 of 50
What is the primary purpose of the __init__ method in a Python class?
Correct answer:
B) Initializing class attributes
Explanation: The __init__ method is a constructor that initializes an objects attributes when it is created.
Question 12 of 50
Which method is used to remove a key-value pair from a Python dictionary?
Correct answer:
A) pop()
Explanation: The pop() method removes a key-value pair based on the specified key and returns the removed value.
Question 13 of 50
What data structure is often used to represent a collection of nodes connected by edges?
Correct answer:
C) Graph
Explanation: Graphs consist of nodes (vertices) connected by edges, representing relationships between items.
Question 14 of 50
What is the effect on an object when its reference count reaches zero in a memory-managed environment?
Correct answer:
C) It becomes available for garbage collection
Explanation: When no variables reference an object, its memory can be reclaimed by garbage collection.
Question 15 of 50
What method is commonly used to add a new element to the end of a Python list?
Correct answer:
D) append()
Explanation: The append() method adds an element to the end of a list, expanding its length by one.
Question 16 of 50
Which ADT follows a First-In-First-Out (FIFO) structure?
Correct answer:
B) Queue
Explanation: A queue is a FIFO structure where elements are removed in the same order they were added.
Question 17 of 50
In a stack, what operation adds an item to the top?
Correct answer:
D) Push
Explanation: Push adds an item to the top of the stack, following the Last-In-First-Out (LIFO) principle.
Question 18 of 50
What does my_list[0:5:3] return if my_list = [5, 10, 20, 40, 80]?
Correct answer:
A) [5, 40]
Explanation: Slicing with [0:5:3] selects elements starting from index 0 to index 5 with a step of 3, yielding [5, 40].
Question 19 of 50
What is the main purpose of a hash function in a hash table?
Correct answer:
B) To map data to specific bucket indexes
Explanation: Hash functions calculate the bucket index for each item, facilitating quick access within the hash table.
Question 20 of 50
What is the time complexity of searching for an item in a well-designed hash table on average?
Correct answer:
A) O(1)
Explanation: Hash tables provide average O(1) time complexity for search operations by directly accessing data via hash indexes.
Question 21 of 50
In which scenario would a stack be the most appropriate data structure to use?
Correct answer:
B) Undo functionality in text editors
Explanation: Stacks follow LIFO, which is ideal for handling actions that need to be reversed, such as the "undo" feature.
Question 22 of 50
Which ADT is used when data must be stored with no specific order and duplicates are allowed?
Correct answer:
B) Bag
Explanation: Bags allow duplicates and do not impose any order on elements, making them suitable for unordered collections.
Question 23 of 50
What is the purpose of the range() function in Python?
Correct answer:
C) To generate a sequence of integers
Explanation: The range() function produces a sequence of integers, often used in loops.
Question 24 of 50
What is an advantage of using a binary search tree?
Correct answer:
B) Enables fast searching with O(log n) complexity
Explanation: Binary search trees allow efficient search, insert, and delete operations with O(logn) complexity when balanced.
Question 25 of 50
Which function would you use to count occurrences of a specific value in a list?
Correct answer:
A) count()
Explanation: The count() function counts how many times a specified value appears in a list.
Question 26 of 50
What is the result of my_list[:4] if my_list = [5, 10, 20, 40, 80]?
Correct answer:
B) [5, 10, 20, 40]
Explanation: Slicing with [:4] selects elements from the start of the list up to, but not including, index 4.
Question 27 of 50
What does a dictionary.keys() function return in Python?
Correct answer:
C) All dictionary keys
Explanation: The keys() function provides access to all keys in a dictionary, allowing iteration over them.
Question 28 of 50
Which complexity is typical of an insertion sort?
Correct answer:
C) O(n^2)
Explanation: Insertion sort has a time complexity of O(n2) due to its nested loop structure for shifting elements.
Question 29 of 50
What traversal method is used in binary trees to delete nodes?
Correct answer:
C) Post-order
Explanation: Post-order traversal processes child nodes before the parent, making it suitable for deleting nodes without leaving references.
Question 30 of 50
In which traversal is the root node visited last?
Correct answer:
C) Post-order
Explanation: Post-order traversal visits the root node after its children, making it effective for operations like node deletion.
Question 31 of 50
What does isEmpty() check in a stack?
Correct answer:
A) If the stack contains any items
Explanation: isEmpty() checks if a stack has items, returning true if no items are present.
Question 32 of 50
What is a priority queue's main characteristic?
Correct answer:
C) Elements are removed based on priority
Explanation: In priority queues, elements are dequeued based on priority rather than order of arrival.
Question 33 of 50
What traversal in a binary search tree yields sorted output?
Correct answer:
C) In-order
Explanation: In-order traversal of a BST visits nodes in ascending order, producing sorted output.
Question 34 of 50
Which function removes all key-value pairs from a dictionary in Python?
Correct answer:
A) clear()
Explanation: clear() removes all items from a dictionary, leaving it empty.
Question 35 of 50
Which ADT is used when both FIFO and LIFO are needed?
Correct answer:
C) Deque
Explanation: A deque supports both FIFO and LIFO by allowing insertions and deletions from both ends.
Question 36 of 50
In a graph, what is a connection between two vertices called?
Correct answer:
C) Edge
Explanation: Edges represent connections between vertices in a graph, forming paths.
Question 37 of 50
What is a min-heap property?
Correct answer:
C) Root is the smallest element
Explanation: In a min-heap, the root contains the smallest element, with larger elements in child nodes.
Question 38 of 50
What operation removes the front item in a queue?
Correct answer:
A) dequeue()
Explanation: dequeue() removes the front item in a queue, adhering to FIFO order.
Question 39 of 50
What is the role of hash() in Python?
Correct answer:
C) To generate a unique value for fast lookups
Explanation: hash() provides unique hash values for objects, enabling efficient access in hash tables.
Question 40 of 50
What type of ADT is implemented when items can only be inserted or removed from the top?
Correct answer:
C) Stack
Explanation: Stacks allow insertions and removals only from the top, following the LIFO structure.
Question 41 of 50
In a max-heap, where is the largest value typically stored?
Correct answer:
C) Root node
Explanation: In a max-heap, the largest value is stored at the root, following the max-heap property.
Question 42 of 50
What is a typical use case for binary search?
Correct answer:
B) To find an element in a sorted list
Explanation: Binary search is efficient for finding elements in sorted lists with O(logn) complexity.
Question 43 of 50
What complexity does traversing all nodes in a graph have?
Correct answer:
D) O(V + E)
Explanation: Graph traversal depends on both vertices (V) and edges (E), yielding O(V+E) complexity.
Question 44 of 50
What is a tuple in Python?
Correct answer:
C) An immutable sequence of items
Explanation: Tuples are ordered, immutable sequences that cannot be changed once created.
Question 45 of 50
What traversal is commonly used to create a copy of a binary tree?
Correct answer:
A) Pre-order
Explanation: Pre-order traversal is useful for creating identical tree copies by visiting the root before its children.
Question 46 of 50
How many parents does a node have in a binary tree?
Correct answer:
B) One
Explanation: Each node in a binary tree has one parent, except the root node, which has no parent.
Question 47 of 50
What is the primary advantage of hash tables for storing key-value pairs?
Correct answer:
B) They provide O(1) access time
Explanation: Hash tables use hashing to map keys to array positions, enabling constant-time O(1) access.
Question 48 of 50
What does the len() function return in Python?
Correct answer:
C) The number of elements in an object
Explanation: len() provides the count of items in collections like lists, strings, or dictionaries.
Question 49 of 50
What is a binary search tree's average insertion complexity?
Correct answer:
B) O(log n)
Explanation: Balanced binary search trees have O(logn) average insertion complexity due to their hierarchical structure.
Question 50 of 50
In a graph, what is the name of an individual item represented as a node?
Correct answer:
C) Vertex
Explanation: Each item in a graph is represented as a vertex, connected to others by edges.
Set 3 completeYou scored 0%
0 correct out of 0 answered (50 questions in this set).