Advanced Algorithms & Data Structures: Lecturer: Karimzhan Nurlan Berlibekuly
Advanced Algorithms & Data Structures: Lecturer: Karimzhan Nurlan Berlibekuly
Advanced Algorithms & Data Structures: Lecturer: Karimzhan Nurlan Berlibekuly
ALGORITHMS &
DATA STRUCTURES
Lecture-01
Arrays and Pointer Arrays
Sort Algorithms: Selection Sort, Bubble Sort
Medians and order statistics
// General syntax
datatype *var_name;
•incremented ( ++ )
•decremented ( — )
•an integer may be added to a pointer ( + or += )
•an integer may be subtracted from a pointer ( – or -= )
2, 5, 6, 9, 19, 20, 24
Median = 9
3, 4, 7, 10, 15, 20
Median = (7 + 10)/2 = 8,5
Since the array is not sorted here, we sort
the array first, then apply above formula.
Mean and median of an unsorted array
Average salary in country
50 000, 50 000, 50 000, 50 000, 50 000, 50 000, 1 000 000, 1 000 000
Median = 50 000
Mean and median of an unsorted array
Input : a[] = {1, 3, 4, 2, 6, 5, 8, 7}
Output : Mean = 4.5
Median = 4.5
Sum of the elements is 1 + 3 + 4 + 2 + 6 +
5 + 8 + 7 = 36
Mean = 36/8 = 4.5
// Simple C++ program to find k'th smallest element Input: arr[] = {7, 10, 4, 3, 20, 15}
#include<iostream>
#include<algorithm>
k=3
using namespace std; Output: 7
// Function to return k'th smallest element in a given array Input: arr[] = {7, 10, 4, 3, 20, 15}
int kthSmallest(int arr[], int n, int k)
{ k=4
// Sort the given array Output: 10
sort(arr, arr+n);
https://www.geeksforgeeks.org
https://www.mathgoodies.com/lessons/vol8/median
https://www.dropbox.com/sh/37ktt7arr0vuoze/AADPwqRsy8lbHWbIRR5tVUnSa?dl=0