Here
Here
Large datasets: Merge Sort or Quick Sort (O(n log n)) are
preferred.
Stability Requirements:
Memory Constraints:
In-place sorting (Quick Sort, Heap Sort, Insertion Sort) use O(1)
or O(log n) extra space.
Best for general cases: Quick Sort and Merge Sort (O(n log n)).
Bubble Sort Analysis: Bubble Sort has O(n²) complexity and is inefficient for
large datasets. Optimized Bubble Sort introduces a flag to track swaps,
improving performance on nearly sorted data (best-case complexity is O(n) for
a sorted input).
Insertion Sort Analysis: It is preferred over Bubble Sort and has a best case
time complexity of O(n) for nearly sorted data. However, it requires O(n²) in
the worst case (reverse sorted input).
Quick Sort vs. Merge Sort: Merge Sort requires O(n) additional space, while
Quick Sort is in-place but has O(log n) space complexity for recursion.
When to use Counting Sort: When the range of the input data (k) is small
relative to the number of elements (n). It has a O(n + k) time complexity.
Key:
Chapter 2 Choice
1.According to the document, which characteristic best describes
comparison-based sorting algorithms?
(a) They rely on digit values and frequency counts.
(b) They determine the order of elements based on pairwise comparisons.
(c) They achieve O(n) time complexity regardless of input.
(d) They are limited to sorting integers.
Correct Answer: (b) They determine the order of elements based on pairwise
comparisons.
Explanation: The document explicitly states that comparison-based sorts
determine the order by comparing elements.
3.As stated in the document, why is sorting data often performed before
searching?
(a) Sorting has no impact on searching efficiency.
(b) Sorting makes it impossible to use searching at all
(c) Sorted data enables the use of more efficient search algorithms, such as
binary search.
(d) Unsorted data always require a search using a heap
Correct Answer: (c) Sorted data enables the use of more efficient search
algorithms, such as binary search.
Explanation: Binary search (O(log n)) requires sorted data and is significantly
faster than linear search (O(n)) on unsorted data.
4.According to the document, for very large datasets, one should generally
prefer sorting algorithms with:
(a) O(n²) time complexity.
(b) O(n) time complexity.
(c) O(1) time complexity.
(d) O(n log n) time complexity.
Correct Answer: (d) O(n log n) time complexity.
Explanation: The document notes that more efficient O(n log n) algorithms are
better for large datasets.
Specific Algorithms
11.For the optimized version of Bubble Sort, what does the document state
as the time complexity when the input data is already sorted?
(a) O(n²)
(b) O(log n)
(c) O(1)
(d) O(n)
Correct Answer: (d) O(n)
Explanation: For an already sorted list it iterates through once and determines
that no swaps are necessary.
14.The document states that, according to the provided text, what makes
Insertion Sort worst case and how it's performance is impacted?
(a) occurs when the input is reverse sorted resulting in O(log n).
(b) occurs when the input is reverse sorted resulting in O(n²).
(c) occurs when the input is nearly sorted resulting in O(log n).
(d) occurs when the input is reverse sorted resulting in O(1).
Correct Answer: (b) occurs when the input is reverse sorted resulting in O(n²).
Explanation: The documents specifies that worst-case in insertion sort is a
reverse sorted array.
15.Based on the text what does Merge Sort need more of compared to
Quick Sort in terms of space complexity?
(a) It is in-place so requires O(1) of memory.
(b) Requires 0(log n) auxiliary space.
(c) Requires 0(n) auxiliary space.
(d) It sorts by partitioning the data.
Correct Answer: (c) Requires 0(n) auxiliary space.
Explanation: The documents specifies that Merge Sort requires O(n) auxiliary
space, while Quick Sort is an in place algorithm.
Algorithm Properties
23.If you have an unsorted array and need to find a specific element, the
document's discussion implies the most basic approach is:
(a) Binary Search.
(b) Merge Sort.
(c) Linear Search.
(d) Quick Sort.
Correct Answer: (c) Linear Search.
Explanation: Linear search scans the dataset linearly, element-by-element.
24.Based on the text, which is not a use case for stable sorting?
25.If an algorithm takes twice as long to run when the input size doubles,
its time complexity is most likely:
(a) O(1)
(b) O(log n)
(c) O(n)
(d) O(n²)
Correct Answer: (c) O(n)
Explanation: A linear relationship describes the execution rate.
26.If an algorithm takes four times as long to run when the input size
doubles, its time complexity is most likely:
(a) O(1)
(b) O(log n)
(c) O(n)
(d) O(n²)
Correct Answer: (d) O(n²)
Explanation: A quadratic relationship describes the execution rate.
28.As stated in the document, when would Counting Sort be the best choice
over Merge Sort or Quick Sort?
(a) The range of elements is significantly larger than the dataset size.
(b) The elements are sorted.
(c) The range of input data is small relative to the number of elements.
(d) The elements consist of floating-point numbers.
Correct Answer: (c) The range of input data is small relative to the number of
elements.
Explanation: The document says Counting Sort is preferred when the number
of elements(n) is small relative to the size of the range k, also when a data
limited range is provided.
29.What does the document mention as the core operation in Quick Sort?
In-place Sorting.
(b) Partitioning.
(c) Recursive function call.
(d) Data that is sorted in linear time.
Correct Answer: (b) Partitioning.
Explanation: Partitioning allows us to get the pivot element by rearranging the
elements into one side being less than and greater than to the pivot.
Scenarios
31.You have a dataset of 10 integers that are almost entirely sorted. Which
sorting algorithm, discussed in the document, would likely be the most
efficient in terms of speed?
(a) Quick Sort
(b) Merge Sort
(c) Insertion Sort
(d) Bubble Sort
Correct Answer: (c) Insertion Sort
Explanation: The document specifies that when we are using a nearly sorted
array an insertion sort is the most effective with its time complexity of O(n).
32.You have a large dataset of strings that need to be sorted alphabetically.
Memory usage is a primary concern. Based on the document's information,
which sorting algorithm should you prefer?
(a) Merge Sort
(b) Counting Sort
(c) Quick Sort
(d) Radix Sort
Correct Answer: (c) Quick Sort
Explanation: Counting Sort/Radix Sort are not well suited for sorting strings
alphabetcially and Merge sort takes O(n) which we are trying to avoid.
IGNORE_WHEN_COPYING_START
content_copy download
Use code with caution.
IGNORE_WHEN_COPYING_END
37.The general sorting algorithm question states for nearly sorted data
what is ideal?
Chapter 1 Choice
1. According to the document, what is a data structure?
(a) A specific programming language.
(b) A collection of data elements that provides an efficient way to
store and organize data.
(c) A type of computer hardware.
(d) A way to encrypt sensitive data.
Correct Answer: (b) A collection of data elements that provides
an efficient way to store and organize data.
Explanation: The introduction defines a data structure as such.
2. The document mentions which of the following as common
examples of data structures?
(a) Compilers, operating systems, and artificial intelligence.
(b) Arrays, linked lists, stacks, and queues.
(c) Entities, attributes, records, and files.
(d) Sorting, searching, inserting, and deleting.
Correct Answer: (b) Arrays, linked lists, stacks, and queues.
Explanation: The introduction lists these as examples.
3. As stated in the document, data structures play a fundamental
role in areas like:
(a) Web browsing and email communication.
(b) Operating systems and compiler design.
(c) Social media and online gaming.
(d) Electronic music production and video editing.
Correct Answer: (b) Operating systems and compiler design.
Explanation: The document lists operating systems, compiler
design, artificial intelligence and graphics.
4. According to the document, what is the benefit of choosing the
appropriate data structure?
(a) It makes programming code shorter and easier to read.
(b) It can significantly enhance software performance and ensure
faster storage and retrieval of user data.
(c) It automatically encrypts data for improved security.
(d) It reduces the need for skilled programmers.
Correct Answer: (b) It can significantly enhance software
performance and ensure faster storage and retrieval of user data.
Explanation: The introduction states that performance can be
significantly enhanced by selecting the appropriate data structure.
5. According to the 'Basic Terminology' section, what is the
smallest unit of information?
(a) An attribute.
(b) A field.
(c) A record.
(d) Data.
Correct Answer: (d) Data.
Explanation: Data is defined as the "smallest unit of information".
6. What does the document define as a collection of related data
items?
(a) A file.
(b) A field.
(c) A record.
(d) An attribute.
Correct Answer: (c) A record.
Explanation: The document defines a "record" as a collection of
related data items.
7. According to the document, an entity represents a category of
objects and what defines their properties?
(a) Records
(b) Attributes
(c) Data
(d) Elements
Correct Answer: (b) Attributes
Explanation: The document states, "An entity represents a
category of objects, and each entity has attributes that define its
properties."
8. According to the 'Need for Data Structures' section, as data
grows into billions of records even powerful processors may:
(a) Become more efficient.
(b) Struggle to handle such large datasets efficiently.
(c) Automatically allocate more memory.
(d) Be able to handle it.
Correct Answer: (b) Struggle to handle such large datasets
efficiently.
Explanation: Section highlights challenges that arise when
managing very large amount of data.
9. To overcome the issues mentioned in the 'Need for Data
Structures' section, what is necessary?
(a) Faster internet connections.
(b) Efficient data structures.
(c) More experienced programmers.
(d) Smaller datasets.
Correct Answer: (b) Efficient data structures.
Explanation: Efficient data structures help organize data for
quicker operations.
10. According to the document, what is an advantage of data
structures?
(a) They guarantee complete data security.
(b) They require no programming knowledge.
(c) They can be reused in multiple applications.
(d) They automatically write code.
Correct Answer: (c) They can be reused in multiple applications.
Explanation: Reusability is listed as an advantage.
11. What term does the document use to describe an
implementation detail, where a user interacts with the
interface without needing to understand how it works?
(a) ADT
(b) Reusability
(c) Efficiency
(d) Entity
Correct Answer: (a) ADT
Explanation: Abstraction notes that data structure are
implemented using Abstract Data Types.
12. According to the classification section, how would we
classify an Array?
(a) Primitive, Linear, Dynamic
(b) Non Primitive, Linear, Static
(c) Primitive, Linear, Static
(d) Primitive, Non-Linear, Static
Correct Answer: (c) Primitive, Linear, Static
Explanation: In the diagram the categorization is Primitive ->
Linear -> Static
13. According to the classification section, what are 2
examples of non-linear data structures?
(a) Stack, Queue
(b) Stack, Linked List
(c) Stack, Tree
(d) Tree, Graph
Correct Answer: (d) Tree, Graph
Explanation: In the diagram Tree and Graph originate from Non-
Linear.
14. In the document's explanation of linear data structures,
elements have which 2 elements (except first and last)?
(a) Element, Data
(b) Field, Data
(c) Successor, Predecessor
(d) Field, Attribute
Correct Answer: (c) Successor, Predecessor
Explanation: Stated in the "Linear Data Structures" section
15. What are the common data operations mentioned on the
last page?
(a) Stack, Queue, Linear Search
(b) Stack, Search, Post-Condition
(c) Worst Case, Merging, Insertion
(d) Sorting, Searching, Deletion
Correct Answer: (d) Sorting, Searching, Deletion
Explanation: Listed under "The major categories of algorithms
are given below:" are the operations.
Chapter 3 Choice
Structures (3.1)
1. The document describes linked lists as the most basic type of:
(a) Primitive data type.
(b) Abstract data type.
(c) Self-referential structure.
(d) Aggregate variable.
Correct Answer: (c) Self-referential structure.
Explanation: The document says "Linked lists are the most basic
self-referential structures."
2. According to the document, what advantage do linked lists
have over arrays?
(a) Arrays are simpler and faster.
(b) Linked lists require pre-allocation of a fixed size, unlike arrays.
(c) Linked lists allow for flexible space use by dynamically
allocating space as needed.
(d) Arrays can store pointers to themselves.
Correct Answer: (c) Linked lists allow for flexible space use by
dynamically allocating space as needed.
Explanation: The text mentions "Flexible space use by
dynamically allocating space for each element as needed" as an
advantage of linked lists.
3. According to the document, what is a drawback of arrays?
(a) Arrays are complex and slow.
(b) Arrays cannot allocate space dynamically.
(c) They can not point to the NULL value.
(d) Arrays have to know their size when construction time occurs.
Correct Answer: (d) Arrays have to know their size when
construction time occurs.
Explanation: Text mentioned "Arrays are simple and fast but we
must specify their size at construction time.".
4. According to the document, a linked list node contains the data
item and:
(a) Another linked list.
(b) A file path to the next node.
(c) A pointer to the next node.
(d) A global variable to reference the chain.
Correct Answer: (c) A pointer to the next node.
Explanation: The document says "Each node contains: the data
item,