160 likes | 388 Views
Data Structures. 1- Course Syllabus. 2- Introduction about Data Structures. First: what is data structures?. A data structure is an arrangement of data in a computer’s memory (or sometimes on a disk).
E N D
Data Structures 1- Course Syllabus. 2- Introduction about Data Structures.
A data structure is an arrangement of data in a computer’s memory (or sometimes on a disk). • Examples of data structures include linked lists, stacks, binarytrees, and hash tables, among others. • Also, it is a object oriented programming Data Structures
Data structures are very useful in the construction of a program or a system, especially if the program has to manage huge amounts of data efficiently, such as large databases, airline system , students enrollment system and others. • It explains the way of organizing data or elements in a computer memory Are Data structures important ???
Algorithms manipulate the data in these structures in various ways, such as inserting a new data item, searching for a particular item, or sorting the items. • You can think of an algorithm as a recipe: a list of detailed instructions for carrying out an activity. Algorithms
Abstract Data Type (ADT) • Before a program is written we should have a fairy good idea of how to accomplish the task being implemented by this program. • It is important to specify each task in terms of input and output. • Behavior of the program is more important than the gears of the mechanism accomplishing it. • Ex. If an item needed in to accomplish some tasks, the item is specified in terms of operations performed on it rather than in terms of its inner structure.
ADT • These operations may act upon this item, for example: • Modifying it, searching for some details in it, or sorting something in it. • 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.
ADT • An item specified in terms of operations is called an abstract data type. • Abstract Data Type (ADT): is a set of items and fundamental operations on this set. • Abstraction? Anything that hides details & provides only the essentials. • Examples: an integer 165 = 1.102+6.101+5.100, procedures/subprograms, etc. • Abstract Data Types (ADTs) are Simple or structured data types whose implementation details are hidden… • An abstract data type is not a part of a program, because a program written in a programing language requires the definition of a data structure, not only the operations on data structure. • An object oriented language( OOL) such as C++ has direct link to abstract data types by implementing them as a class.
ADT: Example ADT String1 Operations: Assume that there is a string S. 1.Procedure Append (c: char) Requires: length(S) < 80. Results: c is appended to the right end of S. 2. Procedure Remove (c: char) Requires: length(S) > 0. Results: The rightmost character of S is removed and placed in c, S’s length decreases by 1.
3. ProcedureMakeEmpty () Results: all characters are removed. 4. Procedure Concatenate (R: String) Results: String R is concatenated to the right of string S, result placed into S. 5. Procedure Reverse () 6. Procedure Length (L: int) 7. Procedure Equal (S: String, flag: boolean) 8. ProcedureGetChar (inti)
In C++ the class construct is used to declare new data types. • In C++ operations are implemented as function members of classes or methods.
ADT String class String1 { private: char[] str; intsize; puplic: String1 () { size = -1; str = new char[80]; } ~String1(){} void Append (char c) { size++; str[size] = c; } Representation Implementation
ADT String char Remove (){ char c = str[size]; size--; return(c); } char GetChar(inti){ return(str[i]); } void MakeEmpty (){ size = -1; } intLength (){ return(size); } void Concatenate (String1 s){ for (inti = 0; i<=s.Length(); i++) { char c = s.GetChar(i); Append(c); } } boolean Equal (String1 s){ } void Reverse () { } }
An abstract data type is not a part of a program, because a program written in a programing language requires the definition of a data structure, not only the operations on data structure. • An object oriented language( OOL) such as C++ has direct link to abstract data types by implementing them as a class.