Professional Documents
Culture Documents
Lect 8 - 2024
Lect 8 - 2024
aft
Foundations of
Data Structures and Algorithms
Lect 8
Sameera Muhamed Salam
Dept of CSIS, BITS Pilani, Hyderabad Campus
Dr
Linear Time Sorting Algorithms
In-place Algorithm
Algorithm that does not need an extra space and produces an output in the same
memory that contains the data by transforming the input ‘in-place’. However, a small
constant extra space used for variables is allowed.
▶ Runs in linear time when the input is drawn from a uniform distribution.
▶ Counting sort assumes that the input consists of integers in a small range, where
as, bucket sort assumes that the input is generated by a random process that
distributes elements uniformly over the interval [0, 1).
▶ The idea of bucket sort is to divide the interval [0, 1) into n equal-sized subin-
tervals, or buckets
▶ Distribute the n input numbers into the buckets.
▶ To produce the output,
▶ Sort the numbers in each bucket
▶ Go through the buckets in order, listing the elements in each.
▶ INPUT: An array A of n ≥ 1.
▶ OUTPUT: Sorted array A
Figure: [Ref:GeeksforGeeks]
Figure: [Ref:Programiz]
▶ Digit by digit sorting
▶ Given n d-digit numbers in which each digit can take on up to k possible values,
RADIX-Sort correctly sorts these numbers in Θ(d(n + k)) time.
BITS F232 Sameera M S 10
Introduction to Linked List
▶ Disadvantages of Arrays?
▶ A linked list is a data structure in which the objects are arranged in a linear order.
▶ The order in a linked list is determined by a pointer in each object.
▶ Provide a simple, flexible representation for dynamic sets
▶ Insertion
▶ at beginning
▶ at end
▶ at any position
▶ Deletion
▶ from beginning
▶ from end
▶ from any position
▶ Traversal
▶ Searching