Data Structures & Algorithms (DSA) Lecture 1 - Intro PDF

Summary

This lecture introduces the fundamental concepts of data structures and algorithms (DSA), focusing on pre-requisites like C++ and asymptotic notations. It covers different categories of data structures, their operations, and the importance of choosing the right data structure for a given problem.

Full Transcript

Data Structures & Algorithms (DSA) Intro Pre-Requisites Basics of C++ OOP using C++ Variables, functions, Class, objects, template pointers, …. class, friend...

Data Structures & Algorithms (DSA) Intro Pre-Requisites Basics of C++ OOP using C++ Variables, functions, Class, objects, template pointers, …. class, friend function, … Asympotatic notations You need to acquaint yourself with Big-O notation, as it plays a pivotal role in evaluating the efficiency of algorithms and data structures. Dr. Mahmoud Alnamoly Degrees ◆ 15 Mid ◆ 15 Practical ( Projects + Practical ) ◆ 10 Oral COURSE TIMELINE Static Array Linked List WEEK 2 WEEK 4 WEEK 1 WEEK 3 Introduction to Dynamic Array Data structure and algorithm Dr. Mahmoud Alnamoly COURSE TIMELINE Queue Binary Search Tree WEEK 6 WEEK 8 WEEK 5 WEEK 7 Stack Tree Dr. Mahmoud Alnamoly COURSE TIMELINE Heap Strings WEEK 10 WEEK 12 WEEK 9 WEEK 11 Hash Table Graph Dr. Mahmoud Alnamoly Rules Dr. Mahmoud Alnamoly Objective Understand the fundamental concepts, types and importance of data structures in programming and algorithms analysis. Dr. Mahmoud Alnamoly Before we proceed … Problem Algorithm Program Dr. Mahmoud Alnamoly Dr. Mahmoud Alnamoly Problem -> program Dr. Mahmoud Alnamoly 01 Complexity Analysis Asympotatic Notaion Dr. Mahmoud Alnamoly Dr. Mahmoud Alnamoly Search for a specific item Dr. Mahmoud Alnamoly Dr. Mahmoud Alnamoly Dr. Mahmoud Alnamoly How to calculate time complexity T(N) of your algorithm ? Dr. Mahmoud Alnamoly Method 1:- Frequency count method Dr. Mahmoud Alnamoly Dr. Mahmoud Alnamoly Method 2:- Asymptomatic Time 𝑇 𝑁 = 𝐎(𝟏) Dr. Mahmoud Alnamoly 𝑇 𝑁 = 𝐎(𝑛) 𝑇 𝑁 = 𝐎(𝑛2 ) Dr. Mahmoud Alnamoly 𝑇 𝑁 = 𝐎(𝑛) Dr. Mahmoud Alnamoly Method 2:- Asymptomatic Time Using Equations 𝑙𝑔𝑛 ෍ 2𝑖 = 𝑂(2𝑛 − 1) 𝑖=1 𝑙𝑔𝑛 ෍ 𝑎𝑛𝑦 𝑓(𝑛) = 𝑂(𝑙𝑔𝑛 ∗ 𝑓(𝑛)) 𝑖=1 𝑛 ෍ 𝑎𝑛𝑦 𝑓(𝑛) = 𝑂(𝑛 ∗ 𝑓(𝑛)) 𝑖=1 Dr. Mahmoud Alnamoly Example 7 𝑇 𝑁 = 𝐎(𝑛) Example 8 𝑇 𝑁 = 𝐎(𝑛) Dr. Mahmoud Alnamoly Example 9 𝑇 𝑁 = 𝐎(𝑙𝑜𝑔𝟐 𝑛) Example 10 𝑇 𝑁 = 𝐎(𝑙𝑜𝑔𝟐 𝑛) Dr. Mahmoud Alnamoly Example 11 𝑇 𝑁 = 𝐎(𝑛2 ) Dr. Mahmoud Alnamoly Example 12 𝑇 𝑁 = 𝐎(𝑛2 + 𝑙𝑜𝑔3 𝑛) Example 13 𝑇 𝑁 = 𝐎(𝑛 𝑙𝑜𝑔3 𝑛) Dr. Mahmoud Alnamoly Example 14 𝑇 𝑁 = 𝐎(𝑙𝑜𝑔3 𝟐 𝑛) Example 15 𝑇 𝑁 = 𝐎( ? ? ) Dr. Mahmoud Alnamoly Data Structure ? Dr. Mahmoud Alnamoly Data Structure A data structure is a scheme for organizing data in the memory of a computer for efficient storage and efficient manipulation. The idea is to reduce the space and time complexities of different tasks. Dr. Mahmoud Alnamoly Algorithm, Program, Data Structure Before a program is written, we should have a good idea of how to accomplish the task being implemented by this program. But, we should be more concerned with what the program should do, not how it should or could be done. Behavior of the program is more important than the mechanism accomplishing it. We should know what are the operations of my program? These operations for example, modifying, searching for some details, or storing something. After these operations are specified, the implementation of the program may start. The implementation decides which data structure should be used to make execution most efficient in terms of time and space. The best data structure for a problem is the one that allows the computer program to solve the problem efficiently in terms of the required storage and Dr.time. Mahmoud Alnamoly WHY ? Dr. Mahmoud Alnamoly Why study data structure ? Understanding data structures will boost your problem-solving skills and enhance your programming thinking ability. Let's break this down: Efficiency Efficient software or applications are every programmer's goal. By using the appropriate data structure, you can drastically improve the efficiency of your code. Problem-solving Skills: Once you master data structures, you'll find it much easier to solve complex problems. It'll be like having a well-organized toolbox, where you know exactly what tool to use and when. Career Advancement: Regardless of the programming language you work with, data structures are fundamental to computer science. A strong understanding of data structures can Dr. significantly Mahmoud Alnamoly improve your career prospects. Let's visualize this concept further. Consider a library filled with books. Without any particular structure or arrangement, finding a book in this library would be a challenging task. But, if we arrange these books by genre, author, or title, it becomes much easier to locate a specific book. This is the essence of data structures - they help us manage, organize, and use data more effectively. Dr. Mahmoud Alnamoly DS TYPES ? Dr. Mahmoud Alnamoly Dr. Mahmoud Alnamoly Data Structures Types Basically, data structures are divided into : Linear data structure The data items are arranged in sequential order, one after the other, Implementation is easy. Non-linear data structure The data items are arranged in non-sequential order (hierarchical manner), Implementation is difficulty. Dr. Mahmoud Alnamoly Data Structures Types Basically, data structures are divided into : Static data structure ❑ In Static data structure the size of the structure is fixed. ❑ The content of the data structure can be modified but without changing the memory space allocated to it. Dynamic data structure ❑ In Dynamic data structure the size of the structure in not fixed and can be modified during the operations performed on it. ❑ Dynamic data structures are designed to facilitate change of data structures in the run time. Dr. Mahmoud Alnamoly Data Structures Types Basically, data structures are divided into : Homogeneous data structure All the elements in Homogeneous data structure are the same such as array Non-Homogeneous data structure The elements in Non-Homogeneous data structure may or may not be the same such as structures Dr. Mahmoud Alnamoly Motivations Dr. Mahmoud Alnamoly Motivations Data Structure: 1. Array 2. Stack 3. Queue 4. Linked list 5. Tree 6. Graph 7. Hashing Dr. Mahmoud Alnamoly 3 Notes ◆ Choosing the right data structure depends on the type of data you're working with and the operations you need to perform. ◆ The choice of a data structure can significantly impact the performance, scalability, and maintainability of a software system. ◆ We can build any data structure with a specific characteristic and operations. ◆ ADT comes first, and the implementation of the required data structure comes next. Dr. Mahmoud Alnamoly ADT Dr. Mahmoud Alnamoly Abstract Data Type Abstract data type defines a data type in terms of a type and a set of operations on that type. An abstract data type (ADT) is the way we look at a data structure, focusing on what it does and ignoring how it does its job. Note:- ADT definition does not specify how the data type is implemented. Data structure is the physical implementation of an ADT. Dr. Mahmoud Alnamoly Dr. Mahmoud Alnamoly 7 Choosing the Right Data Structure: Selecting the appropriate data structure requires a deep understanding of your data and the operations you intend to perform. Here's a step-by-step guide: 1. Analyze Your Data: Start by understanding the nature of the data you’ll be working with. Is it structured or unstructured? Does it have unique characteristics like order, duplications, or relationships? 2. Identify Operations: Determine the primary operations your application needs to perform on the data, such as searching, insertion, deletion, and Dr. traversal. Mahmoud Alnamoly 8 Choosing the Right Data Structure: 3.Time Complexity: Evaluate the time complexity of the chosen data structure for your operations. Opt for structures that offer the most efficient algorithms for your use case. 4. Space Complexity: Assess the memory requirements of your data structure. Ensure it's suitable for the available hardware and scalability needs. 5. Scalability: Think about the potential growth of your data. Choose a data structure that can handle increasing data volumes without significant performance degradation. Dr. Mahmoud Alnamoly 9 Choosing the Right Data Structure: 6. Built-In Libraries: In many programming languages, there are built-in libraries that provide optimized data structures for common use cases. Utilize these libraries to save development time and ensure efficiency. 7. Testing and Benchmarking: Finally, thoroughly test your chosen data structure under realistic conditions to ensure it meets your performance expectations. Benchmarking can help identify bottlenecks and fine-tune your choice. ◆ Dr. Mahmoud Alnamoly 50 Static Array >>> Next Lecture Dr. Mahmoud Alnamoly

Use Quizgecko on...
Browser
Browser