Data Struct 2
Data Struct 2
Dinesh Satre
[email protected]
Unit II: Linear Data Structures, searching and sorting
● An array as a data structure is defined as a set of pairs (index, value) such that with
each index, a value is associated.
○ index—indicates the location of an element in an array
○ value—indicates the actual value of that data element
LINEAR DATA STRUCTURE USING ARRAYS
● Index allows the direct addressing (or accessing) of
any element of an array.
● This statement will allocate a memory space to store 20 integer elements, and the
name assigned to the array is Array_A.
LINEAR DATA STRUCTURE USING ARRAYS
● Size of array: The maximum number of elements that would be stored in an array is
the size of that array. It is also the length of that array. Arrays are static data structures
because once the size of an array is defined, it cannot be changed after compilation.
For the array Name, the size is 20.
● Base Address: The base address of an array is the memory location where the first
element of an array is stored. It is decided at the time of execution of a program. The
value of this base address varies at every program execution as it is decided at the
run-time. It cannot be decided or defined even by a programmer.
LINEAR DATA STRUCTURE USING ARRAYS
● Data type of an array: The data type of an array indicates the data type of elements
stored in that array.
● Access() takes an array and an index as input, and returns either the appropriate value
or an error.
● Domain: A domain is the intended set of values that any array may use either as an
index or as a value.
● We can say that a domain of an array is a collection of fixed, homogeneous elements that may be atomic
or structured.
● The restriction is that all the elements should be homogeneous.
● Arrays use a set of indices or subscript values that have one-to-one correspondence with the positive
integer values.
MEMORY REPRESENTATION AND ADDRESS CALCULATION
● During compilation, the appropriate number of locations is allocated for the array.
● The index, address, and values are shown in Fig. for an array of six real numbers.
Operations on Array
● Inserting an Element into an Array
● Deleting an Element
Inserting an Element into an Array
● To insert an element at the ith position in an array of size N, all the elements originally
at positions i, i + 1, i + 2, ..., N - 1 will be shifted to i + 1, i + 2, i + 3, ..., N,
respectively so that each element gets shifted to the right by one position.
Inserting an Element into an Array
● Consider the following array:
= Base address + (ith row * Number of Columns * Size of element) + (jth Column
* Size of element)
= Base address + (jth column * Number of rows * Size of element) + (ith row * Size of
element)
● The element of array A with subscripts k1, k2, ..., kn is denoted by A[k1][k2]...[kn].
n-Dimensional Arrays
● Consider the three-dimensional array A[2][3][4].
● There are 2 X 3 X 4 = 24 elements in array A.
Q&A
• 1. Which of the following best describes an array?
A. Traversal
B. Insertion
C. Deletion
D. Hashing
Q&A
• 4. Arrays are considered as which type of Abstract Data Type (ADT)?
A. Linear ADT
B. Non-linear ADT
C. Hierarchical ADT
D. Graph-based ADT
Q&A
• 5. What happens when an element is inserted into the middle of an array?
A. O(1)
B. O(log n)
C. O(n)
D. O(n log n)
Q&A
• 7. In memory, array elements are stored:
A. Base_Address + i * sizeof(datatype)
B. Base_Address + i
C. i + sizeof(datatype)
D. Base_Address * i
Q&A
• 9. Which of the following best describes a two-dimensional array?
A. A list of arrays
B. A linear sequence
C. A tree structure
D. A hash table
Q&A
10. If int A[3][4]; is declared in C, how many elements does the array have?
A. 3
B. 4
C. 7
D. 12
Q&A
• 11. In a row-major storage of a 2D array, which element comes first in memory?
● The representation of a matrix for operations on it should be efficient so that the space
and time requirement is less.
• In many situations, the matrix size is very large but most of the elements in it are 0s
(less important or irrelevant data).
● A triple (i, j, value) can easily represent the non-zero elements of the matrix.
+ =
A= + B= =
Sparse Matrix Addition
• Do the addition of sparse matrices
Sparse Matrix Addition
Sparse Matrix Addition
Sparse Matrix Addition
Transpose of Sparse Matrix
• In the conventional approach, by interchanging rows and columns, we get the
transpose of the matrix as the elements at position [i][j] and [j][i] are swapped
• Let m and n be the number of rows and columns for matrix A.
• The transpose of A can be obtained using the following code.
• We can notice that entries in BT are not sorted row and column wise; we need to sort
them further.
Simple Transpose
• Let A be a matrix of size m X n with T non-zero elements and let B be its transpose.
• One of the easiest ways is to search for each column (column = 0 to n - 1) and
sequentially place each column as a row in the transposed matrix B by placing the
interchanged entries as row, column, and value
Simple Transpose
Simple Transpose
• In Algorithm, we first take the first row of matrix A as (m,
n, t) and store it as (n, m, t) in matrix B.
• The second array RowStartPos is used to store the starting address of each column,
which will be a row in the corresponding transposed matrix.
Freq RowStartPos
0 0 0 1
1 1 1 1
2 3 2 2
3 1 3 5
4 1 4 6
Q&A
• What defines a sparse matrix?
• a) O(n)
• b) O(m + n)
• c) O(n²)
• d) O(1)
Q&A
• What is the main difference between simple transpose and fast transpose of a
sparse matrix?
• a) Simple transpose uses extra space, while fast transpose does not
• b) Fast transpose is more efficient in terms of time complexity
• c) Simple transpose is used for dense matrices only
• d) There is no difference; they are the same
Q&A
• In the fast transpose algorithm, what is the purpose of the 'index' array?
• The fields, which are used to distinguish records, are known as keys.
• While searching, we are asked to find the record which contains information along with
the target key. When we think of a telephone directory, the search is usually by name.
Searching
• If the key is unique and if it determines a record uniquely, it is called a primary key.
For example, telephone number is a primary key
• As any field of a record may serve as the key for a particular application, keys may not
always be unique. For example, if we use ‘name’ as the key for a telephone directory,
there may be one or more persons with the same name.
• The search algorithm searches a target value in the list until the target key is found or
can conclude that it is not found
Search techniques
• Depending on the way data is scanned for searching a particular record, the search
techniques are categorized as follows:
○ 1. Sequential search
○ 2. Binary search
○ 3. Fibonacci search
○ 4. Index sequential search
• The performance of a searching algorithm can be computed by counting the number of
comparisons to find a given value.
Sequential Search/Linear Search
• The easiest search technique is a sequential search.
• This is a technique that must be used when records are stored without any consideration
given to order, or when the storage medium lacks any type of direct access facility.
○ For example, magnetic tape and linked list are sequential storage media where the
data may or may not be ordered.
Sequential Search/Linear Search
• Let us assume that we have a sequential file F, and we wish to retrieve a record with a
certain key value k.
○ If F has n records, then key retrieval is by examining the key values in the order
until the correct record is located.
• Such a search is known as sequential search
• A sequential search begins with the first available record and proceeds to the next
available record repeatedly until we find the target key or conclude that it is not found.
• The function SeqSearch() returns the location of the element if found or returns -1 if the
element is not found.
Sequential Search/Linear Search
• Let us compute the amount of time the sequential search needs to search for a target
data.
• We must compute the number of times the comparisons of keys is done.
• The number of comparisons depends on where the target data is stored in the search
list.
• If the target data is placed at the first location, we get it in just one comparison.
• Similarly, i comparisons are required if the target data is at the ith location and n
comparisons, if it is at the nth location.
Sequential Search/Linear Search
• In binary search, as we have divided the list to be searched every time into two lists and
the search is done in only one of the lists.
• In binary search algorithm, to search for a particular element, it is first compared with
the element at the middle position, and if it is found, the search is successful, else if the
middle position value is greater than the target, the search will continue in the first half
of the list; otherwise, the target will be searched in the second half of the list.
Binary Search
Binary Search
Binary Search
Binary Search
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14]
x = 10
Low = 1
High = 14
Mid = (1+14)/2 = 7
Binary Search
• Therefore,
• –a = 1
• –b = 2
Binary Search
d
• If f (n) ∈ Ө(n ) where d ≥ 0
• Then, d = 0, since f(n) = 1
• According to master theorem,
• Therefore,
d
• Since, a = b
Pros and Cons of Binary Search
Pros
2. Not suitable for storage structures that do not support direct access to data, for
example,magnetic tape and linked list
• The Fibonacci series has 0 and 1 as the first two terms, and each successive term is the
sum of the previous two terms.
• Step 1 − As the first step, find the immediate Fibonacci number that is greater than or
equal to the size of the input array. Then, also hold the two preceding numbers of the
selected Fibonacci number, that is, we hold Fm, Fm-1, Fm-2 numbers from the
Fibonacci Series.
• Step 2 − Initialize the offset value as -1, as we are considering the entire array as the
searching range in the beginning.
Fibonacci search
• The detailed procedure of the searching is seen below
○ Compare the key element to be found with the element at index i = [min(offset+Fm-2,n-1)]. If a
match is found, return the index.
○ If the key element is found to be lesser value than this element, we reduce the range of the input
from 0 to the index of this element. The Fibonacci numbers are also updated with Fm = Fm-2.
○ But if the key element is greater than the element at this index, we remove the elements before
this element from the search range. The Fibonacci numbers are updated as Fm = Fm-1.
The offset value is set to the index of this element.
Fibonacci search
• The detailed procedure of the searching is seen below
• Step 4 − As there are two 1s in the Fibonacci series, there arises a case where your two
preceding numbers will become 1. So if Fm-1 becomes 1, there is only one element left
in the array to be searched. We compare the key element with that element and return
the 1st index. Otherwise, the algorithm returns an unsuccessful search.
Example
• Suppose we have a sorted array of elements {12, 14, 16, 17, 20, 24, 31, 43, 50, 62} and
need to identify the location of element 24 in it using Fibonacci Search.
Example
• Suppose we have a sorted array of elements {12, 14, 16, 17, 20, 24, 31, 43, 50, 62} and
need to identify the location of element 24 in it using Fibonacci Search.
• Step 1
• The size of the input array is 10. The smallest Fibonacci number greater than 10 is 13.
• Therefore, Fm = 13, Fm-1 = 8, Fm-2 = 5.
• We initialize offset = -1
Example
• Suppose we have a sorted array of elements {12, 14, 16, 17, 20, 24, 31, 43, 50, 62} and
need to identify the location of element 24 in it using Fibonacci Search.
• Step 2
• In the first iteration, compare it with the element at index = minimum (offset + F m-2, n
1) = minimum (-1 + 5, 9) = minimum (4, 9) = 4.
Example
• Suppose we have a sorted array of elements {12, 14, 16, 17, 20, 24, 31, 43, 50, 62} and
need to identify the location of element 24 in it using Fibonacci Search.
• Step 3
• In the second iteration, update the offset value and the Fibonacci numbers.
• Since the key is greater, the offset value will become the index of the element, i.e. 4.
Fibonacci numbers are updated as Fm = Fm-1 = 8.
• Fm-1 = 5, Fm-2 = 3.
Example
• Suppose we have a sorted array of elements {12, 14, 16, 17, 20, 24, 31, 43, 50, 62} and
need to identify the location of element 24 in it using Fibonacci Search.
• Now, compare it with the element at index = minimum (offset + Fm-2, n 1) = minimum
(4 + 3, 9) = minimum (7, 9) = 7.
Example
• Suppose we have a sorted array of elements {12, 14, 16, 17, 20, 24, 31, 43, 50, 62} and
need to identify the location of element 24 in it using Fibonacci Search.
• Step 4
• We discard the elements after the 7th index, so n = 7 and offset value remains 4.
• Fibonacci numbers are pushed two steps backward, i.e. Fm = Fm-2 = 3.
• Fm-1 = 2, Fm-2 = 1.
Example
• Suppose we have a sorted array of elements {12, 14, 16, 17, 20, 24, 31, 43, 50, 62} and
need to identify the location of element 24 in it using Fibonacci Search.
• Now, compare it with the element at index = minimum (offset + Fm-2, n 1) = minimum
(4 + 1, 6) = minimum (5, 7) = 5.
Example-2
• Search for 81 using Fibonacci search in the list {6, 14, 23, 36, 55, 67, 76, 78, 81, 89},
where n = 10.
• Step 1
• The size of the input array is 10. The smallest Fibonacci number greater than 10 is 13.
• Therefore, Fm = 13, Fm-1 = 8, Fm-2 = 5.
• We initialize offset = -1
Example-2
• Search for 81 using Fibonacci search in the list {6, 14, 23, 36, 55, 67, 76, 78, 81, 89},
where n = 10.
• Step 2
• In the first iteration, compare it with the element at index = minimum (offset + F m-2, n
1) = minimum (-1 + 5, 9) = minimum (4, 9) = 4.
0 1 2 3 4 5 6 7 8 9
6 14 23 36 55 67 76 78 81 89
Example-2
• Search for 81 using Fibonacci search in the list {6, 14, 23, 36, 55, 67, 76, 78, 81, 89},
where n = 10.
• Step 3
• In the second iteration, update the offset value and the Fibonacci numbers.
• Since the key is greater, the offset value will become the index of the element, i.e. 4.
Fibonacci numbers are updated as Fm = Fm-1 = 8.
• Fm-1 = 5, Fm-2 = 3.
Example-2
• Search for 81 using Fibonacci search in the list {6, 14, 23, 36, 55, 67, 76, 78, 81, 89},
where n = 10.
• Now, compare it with the element at index = minimum (offset + Fm-2, n 1) = minimum
(4 + 3, 9) = minimum (7, 9) = 7.
0 1 2 3 4 5 6 7 8 9
6 14 23 36 55 67 76 78 81 89
Example-2
• Search for 81 using Fibonacci search in the list {6, 14, 23, 36, 55, 67, 76, 78, 81, 89},
where n = 10.
• Step 4
• In the third iteration, update the offset value and the Fibonacci numbers.
• Since the key is greater, the offset value will become the index of the element, i.e. 7.
Fibonacci numbers are updated as Fm = Fm-1 = 5.
• Fm-1 = 3, Fm-2 = 2.
Example-2
• Search for 81 using Fibonacci search in the list {6, 14, 23, 36, 55, 67, 76, 78, 81, 89},
where n = 10.
• Now, compare it with the element at index = minimum (offset + Fm-2, n-1) = minimum
(7 + 2, 9) = minimum (9, 9) = 9.
0 1 2 3 4 5 6 7 8 9
6 14 23 36 55 67 76 78 81 89
Example-2
• Search for 81 using Fibonacci search in the list {6, 14, 23, 36, 55, 67, 76, 78, 81, 89},
where n = 10.
• Step 5
• We discard the elements after the 9th index, so n = 9 and offset value remains 7.
• Fibonacci numbers are pushed two steps backward, i.e. Fm = Fm-2 = 3.
• Fm-1 = 2, Fm-2 = 1.
Example-2
• Search for 81 using Fibonacci search in the list {6, 14, 23, 36, 55, 67, 76, 78, 81, 89},
where n = 10.
• Now, compare it with the element at index = minimum (offset + Fm-2, n-1) = minimum
(7 + 1, 9) = minimum (8, 8) = 8.
0 1 2 3 4 5 6 7 8 9
6 14 23 36 55 67 76 78 81 89
Algorithm
Time Complexity of Fibonacci Search
• When we solve a recurrence relation Fn = Fn−1 + Fn−2 for Fibonacci numbers, we get
the solution as Fn = (1/sqrt(5)) * [((1 + sqrt(5))/2)n + ((1 + sqrt(5))/2)n].
Con
• File index is a data structure similar to a list of keys and their location or reference to
the location of the record associated with the key.
• An index file can be used to effectively overcome the problem associated with
sequential files and to speed up the key search.
• Only a subset of data records,evenly spaced along the data file, is indexed to mark the
intervals of data records
Indexed Sequential Search
• A key search then proceeds as follows:
○ the search key is compared with the index to find the highest index key
preceding the search, and a linear search is performed from the current record
until the search key is matched or until the record pointed by the next index entry
is reached.
○ In spite of the double file access (index + data) needed by this kind of search, the
decrease in access time with respect to a sequential file is significant.
Indexed Sequential Search
• Consider the data file as in Table
Indexed Sequential Search
Indexed Sequential Search
• Searching a record from this index file involves the following issues:
1. The index file is ordered, so the searching can be done using the binary search method.
3. The record position is used to access the details of that record from the data file.
Example
• Consider a sorted array of integers: arr = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}. We want
to search for the element 8.
• Create an Index: Divide the array into blocks and create an index that stores the
starting element and its corresponding index for each block. For this example, let's
create blocks of 3 elements.
0 1 2 3 4 5 6 7 8 9
6 7 8 9 10 11 12 13 14 15
Example
• Consider a sorted array of integers: arr = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}. We want
to search for the element 8.
Index Key
0 6
1 9
2 12
3 15
0 1 2 3 4 5 6 7 8 9
6 7 8 9 10 11 12 13 14 15
Example
• Consider a sorted array of integers: arr = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15}. We want
to search for the element 8.
Index Key
• Compare the target element (8) with the elements in the index
0 6
• 8 is not less than index[0] (which is 6).
1 9
• 8 is less than index[1] (which is 9).
2 12
3 15
0 1 2 3 4 5 6 7 8 9
6 7 8 9 10 11 12 13 14 15
Example
• Consider a sorted array of integers: arr = {6, 7, 8, 9, 10, 11, 12, Index Key
13, 14, 15}. We want to search for the element 8. 0 6
1 9
• Perform a sequential search within the identified block (from
2 12
index 0 to 2) in the original array.
3 15
0 1 2 3 4 5 6 7 8 9
6 7 8 9 10 11 12 13 14 15
Q&A
• What is the time complexity of Binary Search in the worst case?
A) O(1)
B) O(n)
C) O(log n)
D) O(n log n)
Q&A
• Binary Search can only be applied to:
A) Unsorted arrays
B) Linked lists
C) Sorted arrays
D) Hash tables
Q&A
• Which of the following is not a requirement for Binary Search to work correctly?
A) The list must be sorted
B) Random access to elements
C) Array must contain unique elements
D) Array indexing support
Q&A
• Fibonacci Search divides the array using:
A) Middle element
B) Golden ratio
C) Fibonacci numbers
D) Prime numbers
Q&A
• What is the worst-case time complexity of Fibonacci Search?
A) O(1)
B) O(n)
C) O(log n)
D) O(n log n)
Q&A
• Indexed Sequential Search is a combination of:
A) Binary Search and Linear Search
B) Hashing and Linear Search
C) Indexing and Sequential Search
D) Fibonacci and Interpolation Search
Q&A
• The index in Indexed Sequential Search typically stores:
A) Every element of the main list
B) Only the first and last elements
C) Keys and their addresses
D) All records
Sorting
• Sorting is the operation of arranging the records of a table according to the key value of
each record, or it can be defined as the process of converting an unordered set of
elements to an ordered set.
• A table or a file is an ordered sequence of records r[1], r[2], …, r[n], each containing a
key k[1], k[2], … , k[n]. This key is usually one of the fields of the entire record. The
table is said to be sorted on the key if i < j implies that k[i] precedes k[j] in some
ordering on the keys.
General Sort Concepts
• Stability :-A sorting algorithm is said to be stable if it preserves the order for all records
with duplicate keys; that means, if for all records i and j is such that k[i] is equal to k[j]
and if r[i] precedes to r[j] in the unsorted table, then r[i] precedes to r[j] in the sorted
table too.
• Bubble sort, selection sort, and insertion sort are the stable sort methods.
General Sort Concepts
• Consider the following unsorted sequence of marks to be sorted in descending order.
Efficiency
• Each sorting method may be analysed depending on the amount of time necessary for
running the program and the amount of space required for the program.
• The amount of time for running a program is proportional to the number of key
comparisons and the movement of records or the movement of pointers to records.
• Sort efficiency is a measure of the relative efficiency of a sort.
• It is usually an estimate of the number of comparisons and data movement required to
sort the data.
Passes
• Sorting algorithms are divided into two categories: internal and external
sorts.
• Internal Sorting:- Any sort algorithm that uses main memory exclusively
during the sorting is called as an internal sort algorithm. This assumes
high-speed and random access to all data members. Internal sorting is
faster than external sorting.
• External Sorting :- Any sort algorithm that uses external memory, such
as tape or disk, during the sorting is called as an external sort algorithm.
Merge sort uses external memory
Types of Sorting
• The simplest implementation of this requires two list structures: the source list and the
list into which the sorted items are inserted.
Insertion Sort
• Let us consider a list L = {3, 6, 9, 14}. Given this sorted list, we need to insert a new
element 5 in it.
○ 5. Insert 5 to get 3, 5, 6, 9, 14
Example
Example
Example
Example
Example-2
Algorithm
Analysis of Insertion Sort
• Although the insertion sort is almost always better than the bubble sort, the time
required in both the methods is approximately the same, that is, it is proportional to n2
(n - 1) + (n - 2) + …. + 1 = (n - 1) * n/2
• which is O(n2).
Selection Sort
• This algorithms construct the sorted sequence, one element at a time, by adding
elements to the sorted sequence in order.
• At each step, the next element to be added to the sorted sequence is selected
from the remaining elements.
• Because the elements are added to the sorted sequence in order, they are always
added at one end.
• This makes the selection sorting different from the insertion sorting.
• In insertion sorting, the elements are added to the sorted sequence in an arbitrary
order.
• Therefore, the position in the sorted sequence at which each subsequent element
is inserted is arbitrary.
Selection Sort
• In this method, we sort a set of unsorted elements in two steps.
• In the first step, find the smallest element in the structure.
• In the second step, swap the smallest element with the element at the first
position.
• Then, find the next smallest element and swap with the element at the second
position.
• Repeat these steps until all elements get arranged at proper positions.
Example
Example-2
Analysis of Selection Sort
• During the first pass, (n - 1) comparisons are made. In the second pass, (n - 2)
comparisons are made. In general, for the ith pass, (n - i) comparisons are required
A[pivot] = 13
Example
• Let us first find the elements larger than the pivot, that is, 13. In addition, let us find
the last element not larger than the pivot. These elements are in positions 2 and 9. Let
us swap those.
Example
• Let us again start scanning from both the directions
Example
• Let us repeat the steps to get the following sequence:
• Here, the lower and upper bounds have crossed. So let us now swap the pivot-with
element 12.
Example
• Here, we get two partitions as represented in the following sequence:
• Recursively applying similar steps to each sub-list on the right and left side of the
pivot, we get,
Algorithm
Analysis of Quick Sort
• Now, let us see the efficiency of quick sort. On the first pass, every element in the
array is compared to the pivot, so there are n comparisons.
• The array is then divided into two parts each of size (n/2).
• We assume that the array is divided into approximately one-half each time.
• For each of these sub-arrays, (n/2) comparisons are made and four sub-arrays of size
(n/4) are formed.
• So at each level, the number of sub-arrays doubles.
• It will take log2n divisions if we are dividing the array approximately one-half each
time.
• Therefore, quick sort is O(nlog2n) on the average.
Virutual Lab
• https://www.cs.usfca.edu/~galles/visualization/ComparisonSort.html
• https://ds1-iiith.vlabs.ac.in/exp/quick-sort/quick-sort/partition.html
• https://www.hackerearth.com/practice/algorithms/sorting/quick-sort/visualize/
• https://opendsa-server.cs.vt.edu/embed/quicksortAV
• https://visualgo.net/en/sorting
•
Merge Sort
• The most common algorithm used in external sorting is the merge sort.
• Merging is the process of combining two or more sorted files into the third sorted file.
• We can use a technique of merging two sorted lists.
• Divide and conquer is a general algorithm design paradigm that is used for merge sort
Merge Sort
• Merge sort has three steps to sort an input sequence S with n elements:
• 1. Divide—partition S into two sequences S1 and S2 of about n/2 elements each
• 2. Recur—recursively sort S1 and S2
• 3. Conquer—merge S1 and S2 into a sorted sequence
• A file (or sub-file) is divided into two files, f1 and f2. These two files are then
compared, one pair of records at a time, and merged
Example
• The operation of the algorithm on the list 8, 3, 2, 9, 7, 1, 5, 4 is illustrated as
Algorithm
Algorithm
Time Complexity
• Which sorting algorithm is not efficient for large datasets due to its O(n²)
time complexity in worst case?
• A. Merge Sort
B. Quick Sort
C. Insertion Sort
D. Heap Sort
Q&A
• A. O(n)
B. O(log n)
C. O(n log n)
D. O(n²)
Q&A
• A. O(n)
B. O(n log n)
C. O(n²)
D. O(log n)
Q&A
• A. Backtracking
B. Divide and Conquer
C. Greedy
D. Dynamic Programming
Q&A
• A. Data is small
B. Data fits into RAM
C. Data is too large to fit into main memory
D. Data is sorted already