Full Transcript

# Lecture 14 ## Data Types ### Primitive Data Types * **Integers**: Whole numbers (positive, negative, or zero) * Examples: `-3, -2, -1, 0, 1, 2, 3` * **Floating-point numbers**: Numbers with a decimal point. * Examples: `3.14, -2.5, 0.0` * **Characters**: Single letter...

# Lecture 14 ## Data Types ### Primitive Data Types * **Integers**: Whole numbers (positive, negative, or zero) * Examples: `-3, -2, -1, 0, 1, 2, 3` * **Floating-point numbers**: Numbers with a decimal point. * Examples: `3.14, -2.5, 0.0` * **Characters**: Single letters, symbols, or digits. * Examples: `'A', 'z', '5', '$'` * **Booleans**: Represent truth values. * Values: `True or False` ### Non-Primitive Data Types * **Arrays**: Collection of elements of the same data type. * Example: `[1, 2, 3, 4, 5]` * **Strings**: Sequence of characters. * Example: `"Hello, World!"` * **Lists**: Ordered collection of items, which can be of different data types. * Example: `[1, "apple", 3.14]` * **Dictionaries**: Collection of key-value pairs. * Example: `{"name": "Alice", "age": 30}` ## Data Structures ### Linear Data Structures * **Arrays**: Elements are stored in contiguous memory locations. * Operations: Access, search, insert, delete * **Linked Lists**: Elements are linked using pointers. * Types: Singly, Doubly, Circular * Operations: Access, search, insert, delete * **Stacks**: Follows LIFO (Last In, First Out) principle. * Operations: Push, Pop, Peek * **Queues**: Follows FIFO (First In, First Out) principle. * Operations: Enqueue, Dequeue ### Non-Linear Data Structures * **Trees**: Hierarchical data structure. * Types: Binary Tree, Binary Search Tree * Operations: Insert, Delete, Search, Traverse * **Graphs**: Collection of nodes (vertices) and edges. * Types: Directed, Undirected * Representations: Adjacency Matrix, Adjacency List * Operations: Add Vertex, Add Edge, Remove Vertex, Remove Edge, Traverse ## Abstract Data Types (ADTs) * **Definition**: A high-level description of a data type that specifies the operations that can be performed on it, without specifying how the data type is implemented. * **Examples**: * List ADT: Specifies operations like insert, delete, search, etc., without specifying whether the list is implemented as an array or a linked list. * Stack ADT: Specifies operations like push, pop, peek, etc., without specifying the underlying implementation. * Queue ADT: Specifies operations like enqueue, dequeue, etc., without specifying the underlying implementation. * **Benefits**: * Abstraction: Hides the implementation details from the user. * Modularity: Allows the implementation to be changed without affecting the user. * Reusability: ADTs can be used in different applications.