This document provides an introduction to the course "Introduction to Data Structures and Algorithms". The course objectives are for students to learn basic static and dynamic data structures, analyze algorithms in terms of time and memory complexity, and understand the advantages and disadvantages of different algorithms and data structures. The document then discusses what algorithms are, their key characteristics, and why understanding algorithms and data structures is important for solving computational problems efficiently. It also defines what data structures are and why they are needed to organize large amounts of data.
• Course Name:Introduction to Data Structures and Algorithms • Course Code: CSM 1232 • Course Level: Year One, Semester Two • Credit Unit: 3
2.
Course Objectives Upon successfullycompleting this course, students should be able to: i. define basic static and dynamic data structures and relevant standard algorithms for them. ii. demonstrate advantages and disadvantages of specific algorithms and data structures. iii. evaluate algorithms and data structures in terms of time and memory complexity of basic operations.
3.
MUNI UNIVERSITY T r an s f o r m i n g L i v e s INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS Chapter 1: The Role of Algorithms in Computing MUKIMBA FIONA Main Reference Book. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to algorithms , 3rd Edition. Cambridge, Mass: MIT Press.
Motivation: What isan Algorithm • A set of steps or instructions for completing a task. Examples a recipe Your morning routine directions to your home • What is the task in each of the above examples? • In Computer Science, An algorithm is a set of steps a program takes to finish a task. ie. Any correct code is an algorithm.
6.
Defining an Algorithm •an Algorithm follows a certain set of guidelines and we use the same set of steps to solve the problem every time we face it. • The first step of defining an algorithm is to define the problem that we are trying to solve. • The algorithm should have a clear problem statement • An Algorithm should be correct and efficient.
7.
Formal definition • Informally,an algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output. • An algorithm is thus a sequence of computational steps that transform the input into the output. We can also view an algorithm as a tool for solving a well-specified computational problem. • The statement of the problem specifies in general terms the desired input/output relationship. The algorithm describes a specific computational procedure for achieving that input/output relationship.
8.
Characteristics of anAlgorithm • Not all procedures can be called an algorithm. An algorithm should have the following characteristics − • Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their inputs/outputs should be clear and must lead to only one meaning. • Input − An algorithm should have 0 or more well-defined inputs. • Output − An algorithm should have 1 or more well-defined outputs, and should match the desired output. • Finiteness − Algorithms must terminate after a finite number of steps. • Feasibility − Should be feasible with the available resources.
9.
Why you needto understand Algorithms • Over time, particular algorithms have been developed for some problems. • It is important to know these solutions • So we don’t repeat • So we can build on • So we can know where and when to apply them • To understand the solution, you need to understand the problem well
10.
Understanding the problem 1.Look at the Problem 2. Break it into distinct steps 3. From the distinct steps, identify the best data structure and the algorithm for the task • This concept is called algorithmic thinking
11.
Why you needAlgorithmic thinking • Deeper understanding of complexity issues in programming • Better sense of how your code will perform in different contexts • Ability to look at a task and break it into smaller sub tasks and then choose the most efficient strategy for each sub task.
12.
Algorithms as atechnology • Suppose computers were infinitely fast and computer memory was free. • Would you have any reason to study algorithms? • Why? • To demonstrate that your solution method terminates and does so with the correct answer. • Algorithms are indeed a technology that keeps being improved on as more research discoveries are made.
13.
Algorithms and othertechnologies • Consider a travel routing website • Total system performance depends on choosing efficient algorithms as much as other technologies e.g – advanced computer architectures and fabrication technologies, – easy-to-use, intuitive, graphical user interfaces (GUIs), – object-oriented systems, – integrated Web technologies, and – Fast networking, both wired and wireless.
14.
What is aData Structure? • Data Structure is a systematic way to organize data in order to use it efficiently. Following terms are the foundation terms of a data structure. • any method that's designed to organize information in an efficient, understandable way.
15.
Foundation terms ofa data structure. • Interface − Each data structure has an interface. Interface represents the set of operations that a data structure supports. An interface only provides the list of supported operations, type of parameters they can accept and return type of these operations. • Implementation − Implementation provides the internal representation of a data structure. Implementation also provides the definition of the algorithms used in the operations of the data structure.
16.
Characteristics of aData Structure • Correctness − Data structure implementation should implement its interface correctly. • Time Complexity − Running time or the execution time of operations of data structure must be as small as possible. • Space Complexity − Memory usage of a data structure operation should be as little as possible.
17.
Need for DataStructures • As applications are getting complex and data rich, there are three common problems that applications face now-a-days. • Data Search − Consider an inventory of 1 million(106) items of a store. If the application is to search an item, it has to search an item in 1 million(106) items every time slowing down the search. As data grows, search will become slower. • Processor speed − Processor speed although being very high, falls limited if the data grows to billion records. • Multiple requests − As thousands of users can search data simultaneously on a web server, even the fast server fails while searching the data. To solve the above-mentioned problems, data structures come to rescue. Data can be organized in a data structure in such a way that all items may not be required to be searched, and the required data can be searched almost instantly.
18.
Need for DataStructures- cont • They allow you to store and manipulate large amounts of data without running into any problems. • Data structures are important because they determine how efficiently your devices will function. • They also indicate whether or not your program will work correctly
19.
Data Structures -Algorithms Basics • As already seen, an algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output. • Algorithms are generally created independent of underlying languages, i.e. an algorithm can be implemented in more than one programming language. • From the data structure point of view, following are some important categories of algorithms − • Search − Algorithm to search an item in a data structure. • Sort − Algorithm to sort items in a certain order. • Insert − Algorithm to insert item in a data structure. • Update − Algorithm to update an existing item in a data structure. • Delete − Algorithm to delete an existing item from a data structure.
20.
Execution Time Cases •There are three cases which are usually used to compare various data structure's execution time in a relative manner. • Worst Case − This is the scenario where a particular data structure operation takes maximum time it can take. If an operation's worst case time is ƒ(n) then this operation will not take more than ƒ(n) time where ƒ(n) represents function of n. • Average Case − This is the scenario depicting the average execution time of an operation of a data structure. If an operation takes ƒ(n) time in execution, then m operations will take mƒ(n) time. • Best Case − This is the scenario depicting the least possible execution time of an operation of a data structure. If an operation takes ƒ(n) time in execution, then the actual operation may take time as the random number which would be maximum as ƒ(n).