24
Data Structure ENG. YOUSSEF ABDELHAKIM

General Data structures

Embed Size (px)

DESCRIPTION

a good introduction to the data structures .

Citation preview

Page 1: General Data structures

Data Structure

ENG. YOUSSEF ABDELHAKIM

Page 2: General Data structures

Agenda: Abstract Data Type (ADT).

What is the Data Structure ?

Data Structure examples :

Queue.

Stack.

Binary Search Tree(BST).

Lists.

Arrays.

Linked List.

Graph.

Hashing.

Page 3: General Data structures

Abstract Data Type (ADT). An ADT is fully described by a domain of

values together with a set of operations to manipulate these values.

Ex: point = {{(a,b) : a, b belongs to R, {create, translate, rotate, scale} }

Ex: set = { { a collection of well defined and distinct objects} {isEmpty, numElements, union, intersection,} }

Page 4: General Data structures

What is the Data Structure? A data structure is one way of implementing an ADT.

The way in which the data is organized affects the performance of a program for different tasks.

Computer programmers decide which data structures to use based on the nature of the data and the processes that need to be performed on that data.

An ADT can have several different data structures. A set might be implemented using a sorted dynamic

array, or using a binary search tree.

Page 5: General Data structures

Data Structure examples :Queue :A Queue is a list-like structure where elements can be inserted into only one end and removed from the other end in a First In First Out (FIFO) fashion.

A queue is a good data structure to use for storing things that need to be kept in order, such as a set of documents waiting to be printed on a network printer.

Page 6: General Data structures

Queue Applications :

Printing Job Management Packet Forwarding in Routers Message queue in Windows I/O buffer

Page 7: General Data structures

Operations on the queue : enqueue

add a new item at the rear

dequeue remove a item from the front

isEmpty check whether the queue is empty or not

isFull check whether the queue is full or not

size return the number of items in the queue

peek return the front item

Page 8: General Data structures

Stack :

A Stack is a list-like structure where elements can be inserted or removed from only one end in a Last In First Out (LIFO) fashion.

An important application we make it with stack : Undo / Redo .

Some languages, like LISP and Python, do not call for stack implementations, since push and pop functions are available for any list.

Page 9: General Data structures

Last-in First-out (LIFO)

A A

B

A

B

C

When we push entries onto the stack and then pop them out one by one, we will get the entries in reverse order.

The last one pushed in is the first one popped out! (LIFO)

A A

B

Push A, B, C

Pop C, B, A

Page 10: General Data structures

Stack Implementation :

interface Stack

{void push(Object x)Object pop()Object peek()boolean isEmpty()int size()

}

Page 11: General Data structures

Binary Search Tree (BST) :

A binary search tree is another commonly used data structure. It is organized like an upside down tree.

Each spot on the tree, called a node, holds an item of data along with a left pointer and a right pointer.

A binary tree is a good data structure to use for searching sorted data.

Page 12: General Data structures

Lists :

A list is an ordered set of data. It is often used to store objects that are to be processed sequentially.

A list can be used to create a queue.

Page 13: General Data structures

Arrays : An array is an indexed set of

variables, such as dancer[1], dancer[2], dancer[3],… It is like a set of boxes that hold things.

An array is a set ofvariables that each store an item.

Page 14: General Data structures

Arrays and Lists : You can see the difference between

arrays and lists when you delete items.

Page 15: General Data structures

Arrays and Lists In a list, the missing spot

is filled in when something is deleted but in the In array, an empty variable is left behind when something is deleted.

Page 16: General Data structures

Linked List :A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains two parts: data and link. The name of the list is the same as the name of this pointer variable.

Page 17: General Data structures

Operations on linked lists : The same operations we defined for an array can be applied to a linked list.

Searching a linked list :

Since nodes in a linked list have no names, we use two pointers, pre (for previous) and cur (for current). At the beginning of the search, the pre pointer is null and the cur pointer points to the first node. The search algorithm moves the two pointers together towards the end of the list. Figure 11.13 shows the movement of these two pointers through the list in an extreme case scenario: when the target value is larger than any value in the list.

Page 18: General Data structures

Graphs:

List, BST, and Hash-Tables are used for generic storage and search.Graphs are useful to represent relationships between data items.Examples: Modeling connectivity in computer and communicationsnetworks. Representing a road map. Modeling flow capacities in transportation networks. Modeling family relationships and business or militaryorganizations.

Page 19: General Data structures

Hashing :

Page 20: General Data structures
Page 21: General Data structures
Page 22: General Data structures
Page 23: General Data structures

Any Questions ?!

Page 24: General Data structures

Thank You