copyright © wondershare software introduction to data structures prepared by: eng. ahmed &...

11
Copyright © Wondershare Softw Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha

Upload: randell-henry

Post on 26-Dec-2015

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha

Copyright © Wondershare Software

Introduction to Data Structures

Prepared by:

Eng. Ahmed & Mohamed Taha

Page 2: 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

Page 3: Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha

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.

Page 4: Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha

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)

Page 5: Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha

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

Page 6: Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha

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.

Page 7: Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha

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.

Page 8: Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha

Copyright © Wondershare SoftwareCompany Logo

A red-black Tree Example Cont.

Page 9: Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha

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.

Page 10: Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha

Copyright © Wondershare SoftwareCompany Logo

General form of any Data structure

Data structure operations

Insert item function

Delete item function

Search for an item function

Page 11: Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha

Copyright © Wondershare Software

Thank you!