Date post: | 31-Dec-2015 |
Category: |
Documents |
Upload: | ruby-mccarthy |
View: | 216 times |
Download: | 2 times |
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
Data Structures
• Vectors (Arrays)• Stacks• Queues• Deques• Single Linked Lists• Double Linked Lists• Circular Linked Lists• Binary Trees• Balanced Binary Trees• Other Tree structures
Vectors
[0] All
[1] good
[2] men
[3] must
[4] come
[5] to
[6] the
[7] aid
[8] of
[9] their
[10] party
[11] .
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.
Stacks
C
+
B
(
+
A
A + (B/C)
)
Push
Stack Pointer
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.
Queues
Tom
Dick
Mary
Jane
Harry
Pat
Head
Tail
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
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
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.
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.
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.
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
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
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
Binary Tree
Node Data RightLeft
Node Data NextPrev Node Data NextPrev
Node Data NextPrev Node Data NextPrev
Root
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.
Other Tree Structure
• Directed graphs• Multi-node trees• Unordered Trees• Free Trees (no definite structure)