Data Structures and Algorithms

by Sarfraz Raza

https://sites.google.com/site/sarfrazraza

by Sarfraz

Other related course:

ITC 2017: https://sites.google.com/view/itc-ucp-2017

PF/OOP 2018: https://sites.google.com/view/pf-ucp-2018/

DM 2017: https://sites.google.com/view/ds-ucp-2017/home

DSA 2017: https://sites.google.com/view/dsa-ucp2017

Algo 2017: https://sites.google.com/view/algo-ucp-2017/home

Algo 2019: https://sites.google.com/view/algo-ucp-2019/home

Algo 2020: https://sites.google.com/view/algo-ucp-2020/home

Lecture 1 - The Story of Data Structures Begins

        • The Central Question of Data structures

        • We started with variable data structures

              • Their pros

              • Their limitation

        • We moved to static arrays

              • Their applications

                  • Sorting

                  • Searching

              • Their issues

        • Dynamic Arrays

              • Growable Array with fixed addition

                  • Its push_back function time complexity analysis

              • Vector Implementation

                  • Its push_back function time complexity analysis

              • Arraylist implementation

                  • Its push_back function time complexity analysis (exercise)

Lecture # 1 -Video Lecture

Lecture 2 - Stack Data Structures

        • Stack Data Structures

              • FIXED SIZE STACK

                  • Its ADT (multiple implementations)

                  • Push/Pop/To multiple versions

              • Applications of STACK

                  • Decimal to any base converter

              • Dynamic Stack

                  • Using Vector implementation

Lecture # 2 -Video Lecture

  • NOTE - We shifted to online lectures (due to COVID-19 corona virus), and started recording lecture for both the sections, through MicrosoftTeams. In some of the playlist you will see two videos of the same lecture content(One for Section A and other for M). Please take one of the lecture.

Lecture 3 - Stack/Queues Data Structures

        • Stack Data Structures

              1. Discussion on Parenthesis balancing problem

              2. Implementing THree Stacks Using One array

              3. Maintaining Minimum and Maximum in Stack

                  • Maintaining three stacks

                  • Maintaining one stack of augmented entry

              4. Tower of Hanoi

              5. Sorting the Stack

        • QUEUE Data Structures

              1. Circular Queue

              2. Queue Using Two Stacks

              3. Steueue

Lecture # 3 -Video Lecture

Lecture 5 - Time Complexity II (Big O, Big Omega and Theta)

Lecture # 5 -Notes

Lecture # 5 -Video Lecture (Section M and A)

Lecture 5b(Tutorial) - We did saveral examples and calculated Time Complexity (Big O, Big Omega and Theta)

Problem Set Link

Lecture # 5b -Video Lecture (Section M and A)

Lecture 6 - Expression Evaluator (Infix to Postfix Notation)

Notes from GeeksforGeeks

Lecture # 6 -Video Lecture (Section M and A)

Lecture 7 - Recursion Begins

              • SearchLAST(A[], Size, T) = -1 Size = 0

              • SearchLAST(A[], Size, T) = Size-1 if A[Size-1]==T

              • SearchLAST(A[], Size, T) = Search(A[], Size-1, T) if A[Size-1]!=T

              • Search(A[], Size, si, T) = -1 Size = si

              • Search(A[], Size, si, T) = si if A[si]==T

              • Search(A[], Size, si, T) = Search(A[], Size, si+1 T) if A[Size-1]!=T

Codes Done in class

How Recursion works???

Notes on Recursion from GeeksforGeeks

Lecture # 7 -Video Lecture

Lecture 8 - Recursion II (Advanced Recursion)

      • 1. Power Function

            • Recursive Definition

                • SlowPower(X, Y) = X * SlowPower(X, Y-1) Y!=0

                • SlowPower(X, Y) = 1 Y=0

                • The Problem of Stack Overflow

      • 2. Multiplication Using Addition

            • Recursive Definition

                • SlowMult(X, Y) = X + SlowMult(X, Y-1) Y!=0

                • SlowMult((X, Y) = 0 Y=0

                • The Problem of Stack Overflow

      • 3. FAST POWER

            • Recursive Definition

                • FASTPower(X, Y) = 1 Y=0

                • FASTPower(X, Y) = FASTPower(X, Y/2)^2 Y%2==0

                • FASTPower(X, Y) = X * FASTPower(X, Y/2)^2 Y%2!=0

      • 3. FAST Multiplication.

            • Recursive Definition

                  • Using Doubling Technique

      • 4. FAST Division

            • Recursive Definition

                  • Using Doubling Technique

      • 5. Fibonacci Numbers

            • Recursive Definition

                  • Recursive Formulation

                  • Problem with repetition of the same recursive problem

                  • Memoization

                  • Bottom Up Approach and Dynamic Programming

Codes Done in class

Notes on Recursion from GeeksforGeeks

Lecture # 8 -Video Lecture (Section A)

Lecture # 8 - Video Lecture (Section M)

Lecture 9 - Revision Session over previous homeworks

Notes-Discussion Written in class

Lecture # 9 -Video Lecture (Section A) [Not Yet Uploaded]

Lecture # 9 - Video Lecture (Section M)

Lecture 10 - The Journey of Data Structures So far... Building a Train through connections

      • Journey of Data Structures so far

          • Variables (pros and cons)

              • Why we have to leave Variables???

          • Static Arrays (pros and cons)

              • Why we have to leave static arrays???

          • Dynamic Grow-able Heap Array(pros and cons)

              • Why have to leave Grow-able Heap Array???

          • Vectors/Arraylist (pros)

              • Its analysis

              • Its applications

              • Stack/Queues Grow-able and static

          • Why Vectors have issues also???

      • Building a linked Train

          • Using Boggies/Dabbas analogy

Notes Written in class

Lecture # 10 - Video Lecture (Section M)

Lecture 10b - Linked List Data Structures

Notes Written in class (Including the code)

Lecture # 10b - Video Lecture

Lecture 12 - Linked List Data Structures (Iterators and STL list data structure)

Notes Written in class (Including the code)

Lecture # 12 - Video Lecture

Lecture 13 - Sorting Algorithms (Bubble Sort and mergeSort) using Iterators and STL list data structure Vectors and List Data Structures

Slides

Lecture # 13 - Video Lecture

Lecture 14 - Introduction to Graphs Data Structures

Notes

Lecture # 14 - Video Lecture

Lecture 16 - Graphs Traversals (DFS, BFS) and finding the paths

        • Its applications

        • Finding the shortest path in a graph

        • Finding DFSpath in Grid Graph

        • FInding BFSPath in Grid Graph

Slides

Codes I Made during class

Lecture # 16 - Video Lecture

Lecture 17 - Union Find Data Structure over Disjoint Sets

AND Segregating/Partitioning the Vector

    • Set Data Structure

        • Input: Given Input of Different Disjoint Set

        • Query 1: Find(x) == Find(y) whether both elements x and y belongs to same Set

        • Query 2: Union(x, y)

        1. Load an array (You may use STL vector, you are not allowed to use any extra vector/array). Then move all the 0’s to the left and the 1’s to the right.

        2. Load a list in an array (You may use STL vectors here, you are not allowed to use any extra memory-array-vector). Then move all the even numbers to the left and the odd numbers to the right.

        3. Load a list in an array (You may use STL vectors here, you are not allowed to use any extra memory) and a value T (which will not be in the list). Then move all the numbers smaller than 7 to the left,and all the numbers greater than 7 to the right end of the vector/array.

        4. Load a list in an array (You may use STL vectors here, you are not allowed to use any extra vectors ). Then move all the 0’s to the left and the 2’s to the right, and all the 1’s in the middle.

        5. Load a list in an array (You may use STL vectors here, you are not allowed to use any extra vectors ) and a value T (which will be in the vector). Then move all the numbers smaller than 7 to the left, in the middle all the 7’s and all the numbers greater than 7 to the right end of the array.

Slides

Codes/Notes - For Segregation/Partitioning the Vector

Lecture # 17 - Video Lecture

Lecture 18 - QuickSort AND Binary Search Tree (Traversals, Searching,

FindMax/Min, Insertion, BinarySearchTree Sort)

    • QuickSort

        • Writing Special Randomized Partition

      • Recursive QuickSort Implementation

    • The Story of Data Structures

        • Why we moved

            • Variables to Static Arrays

            • Static Arrays to Dynamic Growable Arrays

            • Dynamic Growable Arrays to Vector

            • Vector to Linked List

            • Where are we standing now???

        • Solving the issue of Binary Searching in the Linked List by Introducing

        • Binary Search Tree

            • Search (recursive and iterator)

            • FindMax/FindMin

            • LNRTraversal

                • Its Output

                • BSTAscendingSort

            • RNLTraversal

                • Its Output

                • BSTDescendingSort

Codes (TO ADD)

The Story of Data Structures

Lecture # 18 - Video Lecture

Lecture 19 - Binary Search Tree and its Traversal's Applications

      • InOrder Traversal

          • LNRTraversal

                  • Its Output

                  • BSTAscending-Sort

          • RNLTraversal

                  • Its Output

                  • BSTDescending-Sort

      • Post Order Traversal

          • LRN or RLN

                • Computing Size of the tree

                • Computing Height of the tree

                • Computing PrimeCounts

      • Pre Order Traversal

          • NLR or NRL

                • Saving the BST

                • Loading the BST

Codes (TO ADD)

The Story of Data Structures

Lecture # 19 - Video Lecture

Lecture 20 - Binary Search Tree III and its Traversal's Applications

Codes (TO ADD)

The Story of Data Structures

Lecture # 20 - Video Lecture

Lecture 21 - Revision of BST

      • Following Problems were discussed during the lecture

1. Traversal

i) In Order Traversal(LNR, RNL): Sorting

ii) Pre Prder (NLR, NRL): File Saving...

iii) Post Order (RLN, LRN)

2. PrintSpecial

3. InsertRecursive

4. InsertIterative

5. Applications of Traversal

i) Height of the tree

ii) Size of the tree

iii) Leaves nodes count

iv) SameTrees(BST & A, BST & B)

Codes (TO ADD)

The Story of Data Structures

Lecture # 21 - Video Lecture

Lecture 23 - RedBlack Tree(Properties,Proof of Height of the tree,Left and Right Rotation)

- What and why Red-Black Tree?

- Properties

- Comparison with other Data Structures.

- Implementation

- Proof Of Height of the tree.

- Rotation

-Left Rotation

-Right Rotation

-Insertion in RBT.


- Codes (TO ADD)

The Story of Data Structures

Lecture # 23 - Video Lecture

Lecture 24 - Binary Heap, AVL Tree and Heap Sort

- Priority Queue and its Application

- Adelson, Velski & Landis (AVL Tree)

- Comparison with other Data Structures.

- Implementation

-Max-Heapify

-Min-Heapify

-Heap Sort

-Complexity


- Codes (TO ADD)

The Story of Data Structures

Lecture # 24 - Video Lecture

Lecture 25 -Self Balancing Trees, AVL Red Black Trees and Balanced-Tree-Sort

- Adelson, Velski & Landis (AVL Tree)

- Balanced Property

- Implementation

-Height of AVL Tree

-Insertion in AVL Tree

-Complexity

-Comparison with Red Black Tree.



- Codes (TO ADD)

The Story of Data Structures

Lecture # 25 - Video Lecture

Lecture 26 -Priority Queue and its Applications (Huffman Coding)

- File Compression

- Huffman Coding

-Shannon signal theory

- Implementation

-File Compression and Decompression Process

-Disk Sort

-Implementation

-Complexity

-Application

-Sorting of Large File


- Codes (TO ADD)

The Story of Data Structures

Lecture # 26 - Video Lecture

Lecture 27 -Hashing

- Story of Data Structures

- Huffman Coding

-Complexity of other Data-Structures and Hashing

- Implementation of Hash Functions

-Application


- Codes (TO ADD)

The Story of Data Structures

Lecture # 27 - Video Lecture