CSE 5010 DATA STRUCTURES AND ALGORITHMS INTRODUCTION Anjana Wijesinghe MSc in IT (Reading) (SLIIT) , BSc (Hons) (WUSL) OBJECTIVES • Be familiar with problem-solving. • Be able to develop (and implement) algorithms. • Be able to trace algorithms. • Be able to select appropriate data structures and algorithms for given problems. 2 PREREQUISITES • Variables and expressions. • Methods (functions or procedures ). • Decision structures( like if-statements and switch-statements. • Iteration structures (for-loops and while-loops). • Classes and objects 3 OUTLINE Introduction Data Structures Algorithms 4 01 INTRODUCTION 01 WHAT IS DATA? Data A collection of facts from which a conclusion may be drawn. e.g. Data: Temperature 35°C; Conclusion: It is hot. Types of data Textual: For example, your name (Aruna) Numeric: For example, your ID (090254) Audio: For example, your voice Video: For example, your voice and picture 6 DATA TYPES & DATA STRUCTURES Applications/programs read data, store data temporarily, process it and finally output results. What is data? Numbers, Characters, etc. Data Application/ Data Program 7 DATA TYPES & DATA STRUCTURES CONT. Data is classified into data types. e.g. char, float, int, etc. A data type is (i) a domain of allowed values and (ii) a set of operations on these values. Compiler signals an error if the wrong operation is performed on data of a certain type. For example, char x,y,z; z = x*y is not allowed. Data Type Domain Operations boolean 0,1 and, or, =, etc. char ASCII =, <>, <, etc. integer -maxint to +maxint +, _, =, ==, <>, <, etc. 8 DATA STRUCTURES 02 02 WHAT ARE DATA STRUCTURES? Data structures are ways to store and organize data to facilitate access and modifications. •Purpose: To manage and organize data efficiently. •Types: Linear (e.g., arrays, linked lists) and Non-linear (e.g., trees, graphs). •Importance: They form the foundation for designing efficient algorithms. 11 TYPES OF DATA STRUCTURES Array Linked List Tree Queue Stack 12 DATA STRUCTURE OPERATIONS Navigating • Accessing each data element exactly once so that certain items in the data may be processed Searching • Finding the location of the data element (key) in the structure Insertion • Adding a new data element to the structure 13 DATA STRUCTURE OPERATIONS CONT. Deletion • Removing a data element from the structure Sorting • Arrange the data elements in a logical order (ascending/descending) Merging • Combining data elements from two or more data structures into one 14 COMMON DATA STRUCTURES Linear Data Structures: • Array: Fixed-size sequence of elements of the same type. • Linked List: Sequence of elements, where each element points to the next. • Stack: LIFO (Last In, First Out) structure. • Queue: FIFO (First In, First Out) structure. 15 COMMON DATA STRUCTURES CONT. Non-linear Data Structures: • Tree: Hierarchical structure with nodes. • Graph: Set of nodes connected by edges. • Heap: A special tree-based structure. • Hash Table: Stores key-value pairs for efficient lookup. 16 ALGORITHMS 03 03 WHAT IS ALGORITHM? A step-by-step procedure or formula for solving a problem. •Purpose: To perform operations on data structures. •Characteristics: Correctness, efficiency, and clarity. •Importance: Efficient algorithms save time and resources. 18 COMMON ALGORITHM TYPES Sorting Algorithms: •Bubble Sort: Simple comparison-based sort. •Quick Sort: Divide-and-conquer algorithm. •Merge Sort: Divide-and-conquer algorithm that merges sorted arrays. 19 COMMON ALGORITHM TYPES CONT. Searching Algorithms: •Linear Search: Sequential search through elements. •Binary Search: Efficient search in sorted arrays. 20 COMMON ALGORITHM TYPES CONT. Graph Algorithms: •Dijkstra’s Algorithm: Shortest path in weighted graphs. •Depth-First Search (DFS): Traversal of nodes in a depthward motion. •Breadth-First Search (BFS): Traversal of nodes level by level. 21 SUMMARY Data Structures and Algorithms are fundamental concepts in computer science for efficiently organizing, managing, and processing data. Data structures, including linear (arrays, linked lists) and non-linear (trees, graphs), are key for efficient data storage and retrieval. Algorithms, such as sorting, searching, and graph algorithms, are step-by-step procedures for problem-solving. 22 THANK YOU!