You are on page 1of 17

Data Structure

Lebanese University – Faculty of Engineering III

Introduction
Dr. Ali El Masri

1
Part A

2
Program

Stack space à

Time à

Example of a Stack: Subprogram calls


Example of a Queue: Processes waiting their turn to be execute

4
Example of a Tree: Evaluating arithmetic expression

5
Example of a Tree: File Systems

6
Example of a Tree: File Systems
7
Example of a Graph: Flight routes among airports

8
Example of a Graph: Computer networks
9
Example of a (1) Graph: Social media – Facebook and (2) Digraph: Social media – Twitter
10
Part B

11
• A data structure is a scheme for organizing data in the memory of a computer

• 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

• Examples: Commonly used data structures include lists, arrays, stacks, queues, heaps, trees, and graphs

• How to choose a data structure? It depends on your application (as seen in the previous slides)

12
Abstraction
• Anything that hides details & provides only the essentials

• Examples:
• An integer 165 = 1.102+6.101+5.100
• Procedures/Subprograms (a C++ function)

Abstract Data Type (ADT):

• Simple or structured data type whose implementation details are hidden

• While designing an ADT, a designer has to deal with two types of questions:

• What values are in the domain? What operations can be performed on the values of a particular data type?

• How is the data type represented? How are the operations implemented?

13
Specifications:
• ADTs specification answers the “what” questions
• Specifications are written first

Implementations:
• Answers the “how” questions
• Done after specification

Users and Implementers:


• Users of an ADT need only to know the specification (no implementation details) ß advantage

• Programmer (Implementer) who implements ADT is concerned with specification, representation, and
implementation.

• Example:
• A Stack ADT can be applied based on an array or a linked list (totally different implementations)
• The same main function (program) can be used in both case (the Stack use does not depend on its
implementation)

14
• The Queue ADT stores arbitrary objects

• Insertions and deletions follow the first-in first-out scheme

• Insertions are at the rear of the queue and removals are at the front of the queue

• Main queue operations:


• enqueue(object): inserts an element at the end of the queue
• object dequeue(): removes and returns the element at the front of the queue

• Auxiliary queue operations:


• object front(): returns the element at the front without removing it
• int size(): returns the number of elements stored
• bool isEmpty(): indicates whether no elements are stored

• Exceptions
• Attempting the execution of dequeue or front on an empty queue throws an EmptyQueueException

These are the specifications (what)


It is up to the programmer (implementer) to decide how to implement them 15
Part C

16
• Data Structures and Algorithms in C++, 4th Edition, Adam Drozdek

• Data Structures & Algorithm Analysis in C++, 4th Edition, by M.A. Weiss

• Data Structures and Algorithms in C++, 2nd Edition, by M.T. Goodrich, R. Tamassia, and D.M. Mount

• Data Structures and Algorithms in Java, 6th Edition, by M.T. Goodrich and R. Tamassia

• Data Structures and Program Design in C++, 1st Edition, by R.L. Kruse and A.J. Ryba

17

You might also like