Data Structures Marie desJardins

advertisement
Data Structures
IS 101Y/CMSC 101
Computational Thinking and Design
Thursday, October 3, 2013
Marie desJardins
University of Maryland, Baltimore County
Quiz
 Individual quiz: 5 minutes
 Team quiz: 5 minutes
Data Structures
 Definition:
 A particular way of storing and organizing data in a
computer so that it can be used efficiently
 Examples
 Variable – a single data element - the simplest data





structure
Array – an ordered list of data elements
Tree – stay tuned
Graph – ditto
Priority, FIFO and LIFO queues – sorted arrays
Tuple – a defined collection of related data elements
Trees
 A set of nodes and edges
 An edge between two nodes indicates there is some sort
of relationship between them
 No circular relationships
 Has a “root” node and “leaf” nodes
 Examples
 Telephone tree
 Family tree
 Functional decomposition
Tree Exercise
 Use a tree to alphabetize yourselves
 Who is the root of your tree?
 Who are the leaves?
Graphs
 A set of nodes and edges
 An edge between two nodes indicates there is some sort
of relationship between them
 No circular relationships
 Examples
 Maps
 Social networks
 Semantic networks
Semantic Network
 A graph where the nodes represent concepts and the
edges represent relationships between those concepts
 Used to organize complex information
 Examples
 Ontologies – includes terms and definitions in a particular
domain, e.g. medicine, architecture
 Brainstorming – some techniques use a semantic network
as a way to capture the results of the brainstorming
 The human brain?
Recursion
 A structure or process that is defined self-referentially
 Recursive definition of a list of items:
 A list is either:
 an empty list (no items) or
 a single item followed by a list
 Recursive definition of an algorithm for searching for a particular item
in a list:
 Find the middle item in the list
 If that’s the item you’re looking for
 You’re done
 Else
 Search the first half of the list
 Search the second half of the list
Semester Game
 What information needs to be stored?
 How might you organize it?
 By week?
 By choice?
 By outcome?
 Could you use a tree?
 Could you use a graph?
Data Design for the Semester
Game
 For each week, what do you need to keep track of?
Similarly, for Crash
 For each “floating animal”, what do we need to keep
track of?
 image – the picture of the animal
 xpos – the current X position of the picture
 ypos – the current Y position of the picture
 xdir – the current horizontal direction and speed
 ydir – the current vertical direction and speed
 times – how long the picture has been on the screen
 Solution: we’re using an array for each of these data
items (see CrashBasics.pde)
NOTICE:
Important
Project Hint
Coming up!!!
Data Design for the Semester
Game
 Crash, conceptually, is a very similar problem to the
Semester Game
 The same approach (using arrays) that we used in
CrashBasics can be used for the Semester Game.
Download