Introduction to Data Structure and Algorithms Chuan-kai Yang
Data Structures Basic Data Types Stack Queue Linked-List Array Heap, Priority Queue Binary Search Tree Hash Table
Basic Data Types Character (Byte, Octet) Boolean Integer Float, double Signed or Unsigned Boolean Integer Long or short Float, double String
Stack Interfaces (Allowed Operations) Push Pop If a stack is not full, this adds one element on the top of a stack Pop If a stack is not empty, this removes one element from the top of a stack FILO (First In Last Out)
Queue Interfaces Enqueue Dequeue FIFO (First In First Out) If a queue is not full, add one element at the tail of a queue Dequeue If a queue is not empty, remove one element from the head of a queue FIFO (First In First Out)
Linked-List Singly-linked lists Doubly-linked lists Circular-linked lists Search, Insert, Delete
Array 1 2 3 4 5 6 7 8 9 1 10 9 6 7 5 3 2 9
Heap Max_Extract, Insert, Delete
Binary Search Tree Search, Insert, Delete, Successor, Predecessor
Hash Table
Hash Table – Chaining
Hash Table – Open Addressing
Algorithms What is algorithm? Time Complexity & Space Complexity Growth of Functions Recurrence relation Sorting Searching Graph Algorithm Computational Geometry
What is Algorithms Algorithm: Any well-defined computation procedure that takes some value, or set of values, as input and produces some value, or set of values, as output. Or: tool for solving well specific computational problem. Example: Sorting problem Input: A sequence of n numbers Output: A permutation of the input sequence such that .
Time & Space Complexity Time complexity Time to run an algorithm Worst-Case, Best-Case, Average-Case Space complexity (Memory) Capacity to run an algorithm
Growth of Functions Log < polynomial < exponential Constant time: c Logarithmic time: log(n) Linear time: cn Quadratic time: cn2 Exponential time: cn
Recurrence Relation merge_sort(A, p, q) { merge_sort(A, p, (p+q)/2); merge_sort(A, (p+q)/2+1, q); merge(A, p, q); } T(n)=2T(n/2)+O(n)
Sorting Insertion Sort Selection Sort Quick Sort Counting Sort
Searching Method Finding what? Linear Search Binary Search Hash Search If a data structure has some element Finding the n-th smallest element Finding the successor/predecessor
Graph Algorithm Minimal Spanning Tree Shortest Path Euler Path/Cycle Hamiltonian path/Cycle Travelling salesman
Minimal Spanning Tree
Shortest Path
Euler Path/Cycle
Hamiltonian Path/Cycle
Traveling-Salesman Problem
Computational Geometry Line-segment intersection Convex hull Voronoi diagram
Convex Hull
Voronoi Diagram