introduction to data structures fall 2008 dr. david a. gaitros [email protected]

19
Introduction to Data Structures Fall 2008 Dr. David A. Gaitros [email protected] .edu

Upload: ruby-mccarthy

Post on 31-Dec-2015

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Introduction to

Data StructuresFall 2008

Dr. David A. [email protected]

Page 2: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Introduction

Data structures form the basis for efficient programming methods and data manipulation for today’s computer scientists. They (data structures) are based upon mathematical concepts such as queues, trees, vectors, hash tables, sets etc.

“Tree structures represented explicitly in computer memory were described for the first time in applications to algebraic formula manipulation by Grace M. Hopper circa 1951” The Art of Computer Programming, Fundamental Aglorithms, Vol 1, Donald Knuth, Addison Wesley 1969

Page 3: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Data Structures

• Vectors (Arrays)• Stacks• Queues• Deques• Single Linked Lists• Double Linked Lists• Circular Linked Lists• Binary Trees• Balanced Binary Trees• Other Tree structures

Page 4: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Vectors

[0] All

[1] good

[2] men

[3] must

[4] come

[5] to

[6] the

[7] aid

[8] of

[9] their

[10] party

[11] .

Page 5: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Vectors

• Usually simple arrays• All items stored are of the same

type as in most data structurs.• Simplest type of data structure• Random access to any item• Insertions and deletions cause us

to move on average half the data at any given time.

Page 6: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Stacks

C

+

B

(

+

A

A + (B/C)

)

Push

Stack Pointer

Page 7: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Stacks

• FIFO ( First in First out) – Think of any time where you stack one

item on top of another.

• Two basic operations– Push ( put something on top of the stack)– Pop ( take something off of the stack and

use it. Once it is popped, it is no longer on the stack. )

• We range of use in computers and mathematics.

• The stack pointer tells us the top of the stack.

Page 8: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Queues

Tom

Dick

Mary

Jane

Harry

Pat

Head

Tail

Page 9: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Queues• FIFO ( First in First out)• Think of a line at a fast food

restaurant. The first person in line is the first to get served.

• Always has a pointer to the head and tail. – New items are added to the tail. – When an item is used, it is taken

from the head.

• Two primary operations– enqueue: Add an item to the queue– dequeue: Remove an item from the

queue

Page 10: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Deques

RR Car 1

RR Car 2

RR Car 3

RR Car 4

RR Car 5

RR Car 6

RR Car 7

RR Car 8

Car X Car Y

Car W Car Z

Page 11: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Deque (pronounce deck)

• The classic definition of a Deque is a double ended queue– Insertions and deletions can be

done at both ends of the structure. – Think of how you can add and take

away railroad cars at both the front and end of the train.

Page 12: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Linked List

A linked list is usually the data structure used to implement an ordered list, queue, stack, deque, tree, etc.

The definition if a collection of data items forming a record (or node) linked together by pointers that can specify the location of a specific record.

Page 13: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

struct example

struct Student_Record {

string Last_Name;

string First_Name;

string FSUSN;

int age;

int height_CM;

int weight_Kilograms:

struct Student_Record * Next;

};

// As seen, the link Next can point to

// another structure of the same type.

Page 14: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Single Linked List

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Head

Tail

Page 15: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Double Linked List

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Head

Tail

Prev

Prev

Prev

Prev

Prev

Prev

Prev

Prev

Page 16: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Circular Linked List

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Node Data Next

Head

Page 17: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Binary Tree

Node Data RightLeft

Node Data NextPrev Node Data NextPrev

Node Data NextPrev Node Data NextPrev

Root

Page 18: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Balanced Binary Tree

A balanced binary tree tries to have as many nodes on the right as there are on the left. Makes searches behave morepredictably.

Page 19: Introduction to Data Structures Fall 2008 Dr. David A. Gaitros dgaitros@admin.fsu.edu

Other Tree Structure

• Directed graphs• Multi-node trees• Unordered Trees• Free Trees (no definite structure)