0% found this document useful (0 votes)
6 views

Introduction To Data Structures and Algorithms

data structures

Uploaded by

aumar moctar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
6 views

Introduction To Data Structures and Algorithms

data structures

Uploaded by

aumar moctar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 5
9722721, 1:28 AME 68240: Data Svuctures & Algorthms | CS240 -- Lecture Notes: Introduction to Data Structures and Algorithms Daisy Tang Back To Lectures Notes This lecture gives a big picture of data structures and algorithms. It is adapted from Dr. Chung Lee's notes and Chapters from our textbook and reference book. Overview ‘Data Element borin < so cea, Data Structure: ‘piace Seen Jesplermertation -Algerithm Restricted Access Linear < ‘Simple Unrestricted Access Date Element Organization Corpeund ‘Tree Non ln Graph ie rain Data Structures, ADTs, and Algorithms Why data structures’ Ultimate goal -- to write efficient programs. In order to do that, one needs to organize the data in such a way that it can be accessed and manipulated efficiently. What are data structures? There are many definitions available + A data structure is an aggregation of data components that together constitute a meaningful whole. A data structure is a way of arranging data in a computer's memory or other disk storage. * A data structure is a collection of data, organized so that items can be stored and retrieved by some fixed techniques. Example: Suppose you are hired to create a database of names with all company's management and employees. ‘You can make a list. You can also make a tree, hitpsswwwccpp.edu/~fangicourses/CS24Oecturesintro.him 18 92221, 11:28AM 68240: Data Sutures & Algorthms | a Aaron Manager Charles ve George Employee Jack Employee Janet ve John President 5 2 se ‘There are several common data structures: arrays, linked lists, queues, stacks, binary trees, hash tables, ete. These data structures can be classified as either linear or nonlinear data structures, based on how the data is, conceptually organized or aggregated. Linear structures. The array, list, queue, and stack belong to this category. Each of them is a collection that stores its entries in a linear sequence, and in which entries may be added or removed at will. They differ in the restrictions they place on how these entries may be added, removed, or accessed, ‘The common restrictions include FIFO and LIFO, Non-linear structures. Trees and graphs are classical non-linear structures. Data entries are not arranged in a sequence, but with different rules. are abstract data types (ADT)? The abstract view of a television: + Ability to change channels, adjust the volume + TV displays the show we want to watch ‘+ Don't care: who made the TV, or how circuit inside was constructed Remember the goal of software development? Robustness, adaptability, and reusability. Out of this effort to write better code arose a new metaphor for using and building data structures: abstract data type, which highlights the notion of abstraciness. When we say "data type", we often refer to the primitive data types built into a language, such as integer, real, character, and boolean. An integer, is most likely implemented or represented in four bytes in the computer. However, when we use integers, we do not worry at all about its internal representation, or how these operations are implemented by the compiler in machine code. Additionally, we know that, even when we run our program on a different machine, the behavior of an integer does not change, even though its internal representation may change. What we know is that we can use primitive data types via their operational interfaces -'#',"“,"™" and for integers. The primitive data types were abstract entries. hitpsswwwccpp.edu/~fangicourses/CS24Oecturesintro.him 26 ov22ias, 14.28 AM 8240: Data Sructues & Algonthns Applying the idea of abstraction to data structures, we have ADT for data structures. On the one hand, an ADT makes a clean separation between interface and implementation, the user only sees the interface and therefore does not need to tamper with the implementation, On the other hand, if the implementation of an ADT changes, the code that uses the ADT does not break, since the interface remains the same. Thus, the abstraction makes the code more robust and easy to maintain. Moreover, once an ADT is built, it may be used multiple times in various contexts. For example, the list ADT may be used directly in application code, or may be used to build another ADT, such as a stack. We will learn more on the next ADT lecture, How do I choose the right data structures? When writing a program, one of the first steps is determining or choosing the data structures. What are the “right” data structures for the program? ‘The interface of operations supported by a data structure is one factor to consider when choosing between several available data structures. Another important factor is the efficiency of the data structure: how much space does the data structure occupy, and what are the running times of the ‘operations in its interface? We will look at a specific example later. What is an algorithm? There are many definition of algorithms. An algorithm is a procedure, a finite set of well-defined instructions, for solving a problem which, given an initial state, will terminate in a defined end-state. The computational complexity and efficient implementation of the algorithm are important in computing, and this depends on suitable data structures. ‘There are many different ways to express an algorithm, including natural language, pseudocode, flowcharts, and programming languages. Natural language expressions of algorithms tend to be verbose and ambiguous, and are rarely used for complex or technical algorithms. Pseudocode and flowcharts are structured ways to express algorithms that avoid many of the ambiguities common in natural language statements, while remaining independent of a particular implementation language. Programming languages are primarily intended for expressing algorithms in a form that can be executed by a computer, but are often used as a way to define or document algorithms Requirements of an algorithm: unambiguous, finite, feasible (effective), with input/output. Program efficiency: time vs. space. It is interesting to know how much of a particular resource (such as time or storage) is required for a given algorithm. Methods have been developed for the analysis of algorithms to obtain such quantitative answers, such as the big O notation. For example, the time needed for traversing an array of n slots is proportional to n, and we say the time is in the order of O(n). However, a 1g the ith clement in an array takes only constant time, which is independent of the size of the array, thus is in the order of OU), ‘The Phases of Software Development The development process includes the following steps (not necessarily in order): Specification of the task Design of a solution Implementation (coding) of the solution s of the solution Testing and debugging Maintenance ge Specification: hitpsswwwccpp.edu/~fangicourses/CS24Oecturesintro.him as 920, 11:28 AM 8240; Data Sructures& Algor A specification is a precise description of the problem, Customers usually have an abstract idea of what they want as an end result, but not what software should do. Software engineers at this point should help them to rewrite incomplete, ambiguous, or even contradictory requirements in order to have a clear specification. This phase is also known as requirement analysis. De in techniques: Design of a solution involves: user interface design, selection of data structures, and formulating algorithms. There are many design techniques available. One good technique for designing an algorithm is to break down the task at hand into a few subtasks, then decompose each subtask into smaller subtasks, until the subtask is trivial to be solved (divide-and-conquer). Implementation Implementation is to write actual code to carry out the design. Analysis Time analysis vs. space analysis. Worst-case, average-case and best-case analyses. Usually we use the frequency count to compare algorithms. Consider the following three programs: reaiatitmtis La EL) Pesan grant) cere a Test ig Testing is used to make software free of syntax and logic errors. To serve as good test data, your test inputs need two properties: 1. You must know what output a correct program should produce for each test input (normal values). 2. The test inputs should include those inputs that are most likely to cause errors (abnormal and boundary values). ‘A boundary value of a problem is an input that is one step away from a different kind of behavior. For example, a text box is supposed to accept values in range of 1 to 100. Test cases include: * Values in between I and 100 (normal) © 0,1, 2,99, 100, 101 (boundary) ‘* Negative values and extremely large values (abnormal) Fully exercising code: make sure that each line of your code is executed at least once by some of your test data, If there is part of your code that is sometimes skipped altogether, make sure there is at least one test input that actually does not skip this part of your code Maintenance htps:iwwwcopp.edul-langicourses/CS240nectur 46 922921, 11:28AM 68240: Data Svuctures & Algorthms | Rules and policies are always changing (for example, tax rate), so make sure changes and enhancements are up to date. Exercise Suppose you write a program that accepts a single line as input and then outputs a message telling whether or not the line contains the letter A and whether or not it contains more than three A's. What is a good set of test inputs? Last updated: Sept. 2012 hitpsswwwccpp.edu/~fangicourses/CS24Oecturesintro.him 58

You might also like