0% found this document useful (0 votes)
10 views21 pages

Here

The document provides an overview of sorting algorithms, categorizing them into comparison-based and non-comparison-based types, detailing their time and space complexities. It discusses factors influencing the choice of sorting algorithms, including data size, stability requirements, and memory constraints, while also comparing the performance of various algorithms like Quick Sort, Merge Sort, and Bubble Sort. Additionally, it highlights the importance of sorting for efficient searching and outlines specific scenarios where certain algorithms are preferred.

Uploaded by

tommyassefa95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views21 pages

Here

The document provides an overview of sorting algorithms, categorizing them into comparison-based and non-comparison-based types, detailing their time and space complexities. It discusses factors influencing the choice of sorting algorithms, including data size, stability requirements, and memory constraints, while also comparing the performance of various algorithms like Quick Sort, Merge Sort, and Bubble Sort. Additionally, it highlights the importance of sorting for efficient searching and outlines specific scenarios where certain algorithms are preferred.

Uploaded by

tommyassefa95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Here's a summary of the key points related to sorting algorithms, time complexity,

space complexity, and other relevant factors:

Comparison-Based vs. Non-Comparison-Based Sorting:

Comparison-Based: Sorts elements by comparing them pairwise (e.g.,


Quick Sort, Merge Sort, Heap Sort, Bubble Sort, Selection Sort). Lower
bound time complexity is O(n log n) for efficient versions and O(n²) for
inefficient ones.

Non-Comparison-Based: Uses element properties like digit values or


frequency counts (e.g., Counting Sort, Radix Sort, Bucket Sort). Can
achieve O(n) or O(n + k) time complexity but works only on specific data
types (integers, fixed-length strings).

Impact of Sorting on Searching: Sorting enables faster searching using Binary


Search (O(log n)), whereas unsorted data requires Linear Search (O(n)).

Factors for Selecting a Sorting Algorithm:


Data Size and Distribution:

Small datasets: Insertion Sort or Selection Sort may be sufficient.

Large datasets: Merge Sort or Quick Sort (O(n log n)) are
preferred.

Stability Requirements:

If preserving the relative order of equal elements matters, use


stable sorting algorithms (Merge Sort, Insertion Sort, Counting
Sort).

Memory Constraints:

In-place sorting (Quick Sort, Heap Sort, Insertion Sort) use O(1)
or O(log n) extra space.

External sorting (Merge Sort, Counting Sort) require additional


memory O(n).
Time Complexity Considerations:

Best for general cases: Quick Sort and Merge Sort (O(n log n)).

Nearly sorted data: Insertion Sort (O(n)).

Small value ranges: Counting Sort (O(n + k)).

Performance Comparison: The document provides a general performance


example of sorting 1 million elements using Quick Sort, Merge Sort, and
Bubble Sort.

Stable vs. Unstable Sorting Algorithms:

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.

Radix Sort: Achieves sorting without directly comparing elements.

Role of Partitioning in Quick Sort: Good partitioning results in a balanced


recursion tree (O(log n) depth) with overall complexity O(n log n). Poor
partitioning results in a worst case O(n²) time complexity.

Summary Table of Sorting Algorithms (from document information):

Algori Time Time Time Space Stab In- Notes


thm Comple Comple Comple Comple le? Pla
xity xity xity xity ce?
(Best) (Avera (Worst)
ge)
Simple
,but
ineffici
Bubbl
O(n) O(n²) O(n²) O(1) Yes Yes ent for
e Sort
large
dataset
s
Efficie
nt for
Inserti small
on O(n) O(n²) O(n²) O(1) Yes Yes and
Sort nearly
sorted
data
Simple
, but
general
Selecti
ly less
on O(n²) O(n²) O(n²) O(1) No Yes
efficie
Sort
nt than
Inserti
on Sort
Efficie
nt,
stable,
Merge O(n log O(n log O(n log but
O(n) Yes No
Sort n) n) n) require
s extra
memor
y
Quick O(n log O(n log O(n²) O(log No Yes Efficie
Sort n) n) n) nt on
averag
e, but
worst-
case
can be
quadrat
ic
Efficie
nt,
guarant
eed
O(n
log n),
Heap O(n log O(n log O(n log
O(1) No Yes but not
Sort n) n) n)
as fast
as
Quick
Sort on
averag
e
Very
efficie
nt for
Counti
O(n + O(n + O(n + integer
ng O(n) Yes No
k) k) k) s with
Sort
small
value
ranges
Good
for
integer
s,
Radix O(n +
O(nk) O(nk) O(nk) Yes No based
Sort k)
on the
numbe
r of
digits

Key:

n = number of elements to sort

k = range of input values (e.g., max value - min value)

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.

2.The document states that non-comparison-based sorting algorithms


typically:
(a) Have a time complexity lower bound of O(n log n).
(b) Rely on element properties instead of direct comparisons.
(c) Work well with any data type.
(d) Are always less efficient than comparison-based sorts.
Correct Answer: (b) Rely on element properties instead of direct comparisons.
Explanation: The document describes non-comparison sorts as using element
properties like digit values or frequency counts.

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.

Factors in Algorithm Selection

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.

5.If maintaining the relative order of equal elements is important, the


document recommends using a:
(a) Non-stable sorting algorithm.
(b) Unstable sorting algorithm.
(c) Stable sorting algorithm.
(d) In-place sorting algorithm.
Correct Answer: (c) Stable sorting algorithm.
Explanation: The document defines stable sorting as maintaining the relative
order of equal elements.

6.According to the provided text, which sorting algorithm's choice is


impacted the most in a memory constraint environment?
(a) Quick Sort
(b) Selection Sort
(c) Insertion Sort
(d) Merge Sort
Correct Answer: (d) Merge Sort
Explanation: Merge Sort requires O(n) extra memory, while the others can be
implemented in-place.

7.For general-purpose sorting, especially when comparisons are


meaningful (e.g., sorting strings), the document suggests:
(a) Comparison-based sorting algorithms.
(b) Non-comparison-based sorting algorithms.
(c) Always using Bubble Sort.
(d) Using only in-place sorting algorithms.
Correct Answer: (a) Comparison-based sorting algorithms.
Explanation: The document mentions that comparison-based sorting is used
for general-purpose sorting where comparisons are meaningful.

8.According to the document, what data characteristic makes Counting


Sort a potentially good choice?
(a) The data is nearly sorted.
(b) The data consists of strings.
(c) The data has a small value range.
(d) The data is floating point number.
Correct Answer: (c) The data has a small value range.
Explanation: The document states that Counting Sort is good for small value
ranges and runs in O(n+k) time.

Specific Algorithms

9.According to the document, which of the following accurately describes


the runtime complexity of Bubble Sort?
(a) O(n) in all cases
(b) O(n log n) in the average case
(c) O(n²) on almost sorted array
(d) O(n²) in both average and worst cases.
Correct Answer: (d) O(n²) in both average and worst cases.
Explanation: The document states Bubble Sort has O(n²) complexity.

10.The document mentions an optimization for Bubble Sort that improves


performance when:
(a) The input data is randomly distributed.
(b) The input data contains a small number of elements.
(c) The input data is already sorted.
(d) The input contains floating-point numbers.
Correct Answer: (c) The input data is already sorted.
Explanation: The optimized Bubble Sort uses a flag to terminate early if no
swaps occur.

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.

12.According to the document, why is Insertion Sort often preferred over


Bubble Sort?
(a) Insertion Sort always has a better worst-case time complexity.
(b) Insertion Sort typically performs fewer comparisons and swaps.
(c) Bubble Sort has a lower memory requirement.
(d) Bubble Sort is easier to implement.
Correct Answer: (b) Insertion Sort typically performs fewer comparisons and
swaps.
Explanation: The document highlights Insertion Sort's advantage in
performing fewer swaps.

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.

16.According to the document, what strategy makes Quick Sort considered


efficient in despite it having O(n²) worst-case complexity?
(a) It's effective use of recursive algorithms.
(b) Smaller constant factors and it performs well on average, especially with a
good pivot selection strategy.
(c) No need to do any partitioning of data.
(d) It has O(1) auxiliary space.
Correct Answer: (b) Smaller constant factors and it performs well on average,
especially with a good pivot selection strategy.
Explanation: The documents specifies that the average case for quicksort is
O(n log n).

Time and Space Complexity


17.What does O(n) indicate about an algorithm's time complexity?
(a) The algorithm's runtime remains constant regardless of input size.
(b) The algorithm's runtime doubles with each increase in input size.
(c) The algorithm's runtime increases linearly with input size.
(d) The algorithm is highly efficient.
Correct Answer: (c) The algorithm's runtime increases linearly with input size.
Explanation: O(n) means the runtime grows proportionally to the size of the
input.

18.What does it mean for a sorting algorithm to be "in-place"?


(a) It requires additional memory proportional to the input size.
(b) It sorts the data without requiring significant extra memory beyond the input
itself.
(c) It is a highly efficient algorithm.
(d) It is a stable sorting algorithm.
Correct Answer: (b) It sorts the data without requiring significant extra
memory beyond the input itself.
Explanation: In-place algorithms modify the input array directly.

19.Which of the following time complexities generally indicates the least


efficient algorithm for very large inputs?
(a) O(n log n)
(b) O(n)
(c) O(log n)
(d) O(n²)
Correct Answer: (d) O(n²)
Explanation: Quadratic time complexity O(n²) grows much faster than the
other options.

Algorithm Properties

20.What is meant by the "stability" of a sorting algorithm?


(a) The algorithm's ability to handle different data types.
(b) The algorithm's consistent performance across various inputs.
(c) The algorithm's ability to maintain the relative order of equal elements.
(d) The algorithm's resistance to errors.
Correct Answer: (c) The algorithm's ability to maintain the relative order of
equal elements.
Explanation: Stability is about preserving the original order of equal-valued
elements.
21.Which sorting algorithm from the document best exemplifies an "in-
place" sorting approach?
(a) Merge Sort
(b) Counting Sort
(c) Bubble Sort
(d) Radix Sort
Correct Answer: (c) Bubble Sort
Explanation: Bubble Sort sorts the elements in place, without requiring any
extra space.

Sorting and Searching

22.The document indicates that using Binary Search requires:


(a) A sorted dataset.
(b) An unsorted dataset.
(c) A graph-structured dataset.
(d) A tree-structured dataset.
Correct Answer: (a) A sorted dataset.
Explanation: Binary search can only be used with data that is already sorted.

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?

Sorting records of students by age then alphabetical name.


(b) Using Radix Sort.
(c) The use case of sorting integers.
(d) Using Counting Sort.
Correct Answer: (c) The use case of sorting integers.
Explanation: Stable sorts maintain the same order for equal elements, meaning
in use cases where you have values that should be organized by an additional
comparison you need to use a stable sort. If all values are unique the relative
order does not matter, and stable vs unstable are the same.
Analyzing Algorithms

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.

Advanced Topics (From Last Page)

27.According to the document, Quick Sort is efficient in practice despite its


O(n²) worst-case because:
(a) Its average-case complexity is O(n²).
(b) Its average-case complexity is O(n log n) and the worst-case is rare.
(c) Its average-case complexity is O(1) and optimized with other pivoting
systems.
(d) Its space-case is O(n log n) as well.
Correct Answer: (b) Its average-case complexity is O(n log n) and the worst-
case is rare.
Explanation: Even though its worse-case can be O(n²), in general it runs with a
time complexity of O(n log n).

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.

30.What is a key advantage of optimized Bubble Sort according to the


document?

Time complexity is always O(n log n).


(b) Time complexity is O(1) for sorted input.
(c) Best-case performance is O(n) for sorted or nearly sorted input.
(d) Space complexity of O(n) in all cases.
Correct Answer: (c) Best-case performance is O(n) for sorted or nearly sorted
input.
Explanation: Using a flag to determine if all elements are already sorted makes
the time complexity of O(n).

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.

33.You need to sort a large dataset where it is critical to maintain the


original order of identical elements. Based on the document, which
algorithm is best choice?
(a) Quick Sort.
(b) Selection Sort.
(c) Bubble Sort.
(d) Heap Sort.
Correct Answer: (c) Bubble Sort
Explanation: Bubble Sort does not rearrange elements that are the same so it is
a stable sort, the other sorts are unstable and will move the data around.

Putting it all together


34. The general sorting algorithm question states Binary Search improves
what complexity?

Increases Complexity from O(log n) to O(n).


(b) Decreases Complexity from O(n) to O(log n).
(c) Increases Complexity from O(n) to O(log n).
(d) Does not improve complexity.

**Correct Answer:** (b) Decreases Complexity from


O(n) to O(log n).
**Explanation:** States that Binary Search has a time
complexity of O(log n) and improves lookup speed.

36.The general sorting algorithm question states comparison based


algorithms have what minimum bound for efficient algorithms?
have a minimum bound of O(n).
(b) have a minimum bound of O(n²).
(c) have a minimum bound of O(log n).
(d) have a minimum bound of O(n log n).

**Correct Answer:** (d) have a minimum bound of


O(n log n).
**Explanation:** States that O(n log n) for efficient
algorithms (Quick Sort, Merge Sort).

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?

use Counting Sort (O(n + k)).


(b) use Insertion Sort (O(n)).
(c) use Merge Sort (O(n log n)).
(d) use Quick Sort (O(n log n)).

**Correct Answer:** (b) use Insertion Sort


(O(n)).
**Explanation:** States that "For nearly sorted data:
Insertion Sort (O(n))."

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. According to the document, what keyword is used to define a


structure in C++?
(a) class
(b) object
(c) struct
(d) type
Correct Answer: (c) struct
Explanation: The text explicitly states, "Structure are defined
using the struct keyword."
2. According to the document, structures are considered:
(a) A way to define custom primitive types.
(b) Aggregate data types built using elements of primitive data
types.
(c) A type of self-referential linked list.
(d) A secure form of data storage.
Correct Answer: (b) Aggregate data types built using elements of
primitive data types.
Explanation: The definition given at the beginning of Section 3.1
is "Structures are aggregate data types built using elements of
primitive data types."
3. How are structure members (like hour, minute, and second in
the Time structure example) accessed when using a structure
variable (like timeObject)?
(a) Using the -> operator.
(b) Using the . operator.
(c) Using the * operator.
(d) Using the :: operator.
Correct Answer: (b) Using the . operator.
Explanation: The document states "The Dot operator (.): to access
data members of structure variables." The example cout <<
timeObject.hour; demonstrates this.
4. According to the document, how are structure members
accessed when using a pointer variable that points to a
structure (like timeptr)?
(a) Using the . operator.
(b) Using the :: operator.
(c) Using the -> operator.
(d) Using the * operator.
Correct Answer: (c) Using the -> operator.
Explanation: The document says "The Arrow operator (->): to
access data members of pointer variables pointing to the structure."
The example cout << timeptr->hour; demonstrates this.
5. What is the relationship between timeptr->hour and
(*timeptr).hour according to the document?
(a) They are equivalent ways to access the structure member.
(b) timeptr->hour is used for accessing const members.
(c) (*timeptr).hour is used for accessing static members.
(d) timeptr->hour is invalid syntax.
Correct Answer: (a) They are equivalent ways to access the
structure member.
Explanation: The document includes the "TIP: timeptr->hour is
the same as (*timeptr).hour."

Singly Linked Lists (3.2)

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,

You might also like