0% found this document useful (0 votes)
35 views22 pages

Understanding Arrays and Sorting Techniques

Uploaded by

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

Understanding Arrays and Sorting Techniques

Uploaded by

nohomaj999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

DATA STRUCTURE

PRESENTATION
ABDUL BASIT - HASSAN ZAHID KHAN
HUSNAIN ARSHAD - ABD UR REHMAN
What is an Array?
An array is a data structure that stores a fixed-size sequence
of elements of the same type. Arrays provide efficient
random access to their elements and are often used to store
collections of data.
Static vs. Dynamic Arrays
Static Array:
The size of a static array is fixed and defined at compile time.
Static vs. Dynamic Arrays
Code Example:
Static vs. Dynamic Arrays
Dynamic Array:
A dynamic array can change its size during runtime using pointers and
memory allocation (e.g., new and delete operators).
Static vs. Dynamic Arrays
CODE EXAMPLE
Array Sorting Techniques
Bubble Sorting:
Repeatedly swaps adjacent elements if they are in
the wrong order.
Time and Space Complexity:
1. Time Complexity:
Case Time Complexity
Best Case O(n)
Worst Case O(n^2)

2. Space Complexity:
Space Complexity O(1)
Array Sorting Techniques
Code Example
Array Sorting Techniques
Selection Sorting:
Selects the smallest element from the unsorted part and swaps it
with the first unsorted element.
Time and Space Complexity:
1. Time Complexity:
Case Time Complexity
Best Case O(n^2)
Worst Case O(n^2)

2. Space Complexity:
Space Complexity O(1)
Array Sorting Techniques
Code Example
Array Sorting Techniques
Insertion Sorting
Builds the sorted array one element at a time by
comparing and inserting elements into their correct positions.
Time and Space Complexity:
1. Time Complexity:
Case Time Complexity
Best Case O(n)
Worst Case O(n^2)

2. Space Complexity:
Space Complexity O(1)
Array Sorting Techniques
Code Example
Array Sorting Techniques
Merge Sorting:
Divides the array into halves, recursively sorts
each half, and merges them.
Time and Space Complexity:
1. Time Complexity:
Case Time Complexity
Best Case O(n*logn)
Worst Case O(n*logn)

2. Space Complexity:
Space Complexity O(n)
Array Sorting Techniques
Code Example
Array Sorting Techniques
Quick Sorting:
Quicksort is a sorting algorithm based on the
Divide and Conquer that picks an element as a pivot and
partitions the given array around the picked pivot by placing the
pivot in its correct position in the sorted array.
Time and Space Complexity:
1. Time Complexity:
Case Time Complexity
Best Case O(n*logn)
Worst Case O(n^2)

2. Space Complexity:
Space Complexity O(n*logn)
Array Sorting Techniques
Code Example

You might also like