Download presentation
Presentation is loading. Please wait.
Published byVincent Campbell Modified over 9 years ago
1
1 CS 350 Data Structures Chaminade University of Honolulu
2
2 Introduction Why Data Structures? What Is Data Structure? Program Efficiency Example: Banking Application Example: City Database Abstract Data Type
3
3 Why Data Structures? Main function of computers is to perform calculations—fast, and efficiently. Complex jobs require intensive calculations How do you make computers work efficiently? Hardware Software Software solution Algorithms Algorithms depend on data structures
4
4 What Is a Data Structure? In a general sense, any data representation is a data structure. E.g., integer, string Specifically, data structure is an organization for a collection of data items. You choose appropriate data structure for efficient processing of data.
5
5 Data Structure and Algorithm Different data structures can be used for processing data—searching, sorting, modifying, etc. But the choice of data structure, and accompanying algorithm can make the difference between a fast program (sec, min) and a long program (hrs, days).
6
6 Program Efficiency A program is said to be efficient if it solves a problem without wasting computing resources of: Space Time The cost of a (program) solution is the amount of resources that the solution consumes.
7
7 Example: Banking Application Typical Operations Open accounts (far less often than access) Close accounts (far less often than access) Access account to Add money Access account to Withdraw money
8
8 Banking Application (cont.) Teller and ATM transactions are expected to take short time (minutes). Opening or closing an account can take longer time (perhaps up to an hour).
9
9 Banking Application (cont.) Kind of data structure for this application: Must be highly efficient for search of account May be less efficient for deletion of account May be moderately efficient for insertion of account
10
10 Banking Application (cont.) Hash Table Meets these requirements Allow for extremely fast records search. Also supports efficient insertion of new records. Deletions can also be supported efficiently. (But too many deletions lead to performance degradation–requiring the hash table to be reorganized.)
11
11 Example: City Database Database system for city information Search by particular value--e.g., ZIP code, street name, building name-- (exact match) Search by range of values--e.g., population, income level—(range query)
12
12 City Database (cont.) The database must answer queries quickly For an exact-match query, fast operation (seconds) For a range queries, the entire operation may be allowed to take longer (minutes)
13
13 City Database (cont.) The hash table is inappropriate because it cannot perform efficient range queries The B+ tree supports large databases for: Insertion Deletion Range queries If the database is created once and then never changed, simple linear lists may be more appropriate.
14
14 Selecting a Data Structure Selection Criteria for a Data Structure 1. Analyze the problem to determine the resource constraints a solution must meet. 2. Determine the basic operations that must be supported. Quantify the resource constraints for each operation. 3. Select the data structure that best meets these requirements.
15
15 Data Structure Philosophy Each problem has constraints on available space and time. Only after a careful analysis of problem characteristics can we know the best data structure for the task. Bank example: Start account: a few minutes Transactions: a few seconds Close account: overnight
16
16 Goals of this Course Reinforce the concept that costs and benefits exist for every data structure Choice of data structure is important for complex processing Learn commonly used data structures Programmer's basic data structure “toolkit” Understand how to measure the cost of a data structure or program. Algorithm analysis
17
17 Abstract Data Type Abstract Data Type (ADT): specification for a data type solely in terms of a set of values a set of operations on that data type
18
18 Abstract Data Type (cont.) Humans handle complexity in hierarchy of abstraction E.g., dog runs, barks, eats dog runs with legs barks with lungs, mouth eats with mouth, stomac E.g., list insert item, remove item, search list data in array insert item into array remove item by overwriting use binary search algorith
19
19 Abstract Data Type (cont.) ADT provides a set of (high-level) operations as an interface to the outside world Data Structure and algorithm provides the (low-level) implementation of the abstract operations
20
20 Abstract Data Type (cont) Information Hiding Principle of hiding the design and implementation details of data structure Encapsulation Way to achieve information hidng. Often used synonymously with information hiding itself.
21
21 ADT and Data Structure Data Structure the physical implementation of an ADT. Each operation in the ADT is implemented by one or more subroutines in the implementation. In a OO language, an ADT and its implementation together make up a class. Data Structure: usually refers to an organization for data in main memory. File Structure: an organization for data on external storage, such as a disk drive.
22
22 Data Type ADT: Type Operations Data Items: Logical Form Data Items: Physical Form Data Structure: Storage Space Subroutines
23
23 Programs A computer program is a concrete representation of an algorithm in some programming language. Naturally, there are many programs that are instances of the same algorithms, since any modern programming language can be used to implement any algorithm.
24
24 To Summarize: A problem is a function or a mapping of inputs to outputs. An algorithm is a recipe for solving a problem whose steps are concrete and ambiguous. A program is an instantiation of an algorithm in a computer programming language.
25
25 Your Turn Imagine that you are a shipping clerk for a large company. You have just been handed about 1000 invoices, each of which is a single sheet of paper with a unique large number in the upper right corner. The invoices must be sorted by this number, in order from lowest to highest. Write down as many different approaches to sorting the invoices as you can think of. You can recruit your friend to help you.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.