Copyright © Wondershare Software
Introduction to Data Structures
Prepared by:
Eng. Ahmed & Mohamed Taha
Copyright © Wondershare SoftwareCompany Logo
Agenda
Data Structures and Algorithms.
Characteristics of Data Structures.
Abstract Data Types.
General form of any Data structure
Copyright © Wondershare SoftwareCompany Logo
Data Structures
A data structure is an arrangement of data in a computer's memory or even disk storage.
An example of several common data structures are: arrays linked lists Queues Stacks binary trees hash tables.
Algorithms, on the other hand, are used to manipulate the data contained in these data structures such as searching and sorting algorithms.
Copyright © Wondershare SoftwareCompany Logo
Algorithms
Many algorithms apply directly to a specific data structures. When working with certain data structures you need to know how to insert new data, search for a specified item, and deleting a specific item.
Commonly used algorithms are useful for:
Searching for a particular data item (or record).
Sorting the data. There are many ways to sort data. Simple sorting, Advanced sorting
Iterating through all the items in a data structure. (Visiting each item in turn so as to display it or perform some other action on these items)
Copyright © Wondershare SoftwareCompany Logo
Characteristics of Data Structures
Disadvantages Advantages Data Structure
Slow searchSlow deletes
Fixed size
Quick insertsFast access if index known
Array1
Slow insertsSlow deletes
Fixed size
Faster search than unsorted array
Ordered Array2
Slow access to other itemsLast-in, first-out LIFO
accessStack
3
Slow access to other items First-in, first-out FIFO access
Queue4
Slow search Quick insertsQuick deletes
Linked List 5
Deletion algorithm is complex
Quick searchQuick insertsQuick deletes
(If the tree remains balanced)
Binary Tree
6
Copyright © Wondershare SoftwareCompany Logo
Characteristics of Data Structures
Disadvantages Advantages Data Structure
Complex to implement
Quick searchQuick insertsQuick deletes
(Tree always remains balanced)
Red-Black Tree
7
Complex to implement
Quick searchQuick insertsQuick deletes
(Tree always remains balanced)
(Similar trees good for disk storage)
2-3-4 Tree
8
Slow deletesAccess slow if key is not known
Inefficient memory usage
Very fast access if key is known
Quick inserts
Hash Table9
Slow access to other itemsQuick insertsQuick deletes
Access to largest itemHeap
10
Some algorithms are slow and very complex
Best models real-world situations
Graph11
Cont.
Copyright © Wondershare SoftwareCompany Logo
A red-black Tree
A red-black tree is a binary search tree where each node has a color attribute, the value of which is either(red or black).
In addition to the ordinary requirements imposed on binary search trees, the following additional requirements apply to red-black trees:
1.A node is either red or black.
2.The root is black. (This rule is sometimes omitted from other definitions. Since the root can always be changed from red to black but not necessarily vice-versa this rule has little effect on analysis.)
3.All leaves are black.
4.Both children of every red node are black.
5.Every simple path from a given node to any of its descendant leaves contains the same number of black nodes.
Copyright © Wondershare SoftwareCompany Logo
A red-black Tree Example Cont.
Copyright © Wondershare SoftwareCompany Logo
Abstract Data Types (ADT)
An Abstract Data Type (ADT) is more a way of looking at a data structure: focusing on what it does and ignoring how it does its job.
A stack or a queue is an example of an ADT. It is important to understand that both stacks and queues can be implemented using an array.
It is also possible to implement stacks and queues using a linked list. This demonstrates the "abstract" nature of stacks and queues: how they can be considered separately from their implementation.
To best describe the term Abstract Data Type, it is best to break the term down into "data type" and then "abstract".
data type: a data item with certain characteristics and the permissible operations on that data. An “int”, for example, can contain any whole-number value. It can also be used with the operators +, -, *, and /. understanding the type means understanding what operations can be performed on it.
Abstract: The word abstract in our context stands for "considered apart from the detailed specifications or implementation“. Consider for example the stack class. The end user knows that push() and pop() (amoung other similar methods) exist and how they work. The user doesn't and shouldn't have to know how push() and pop() work, or whether data is stored in an array, a linked list, or some other data structure like a tree.
Copyright © Wondershare SoftwareCompany Logo
General form of any Data structure
Data structure operations
Insert item function
Delete item function
Search for an item function
Copyright © Wondershare Software
Thank you!