Scientific Computing
Total Page:16
File Type:pdf, Size:1020Kb
Scientific Computing (PHYS 2109/Ast 3100 H) I. Scientific Software Development SciNet HPC Consortium University of Toronto Winter 2014/2015 Lecture 8: DATA STRUCTURES I Basic Types I structures I linked List, Stacks/Queues I binary Trees I Hash tables (maps) Basic Types in C++ \Primitive" types * boolean: bool * integer type: [unsigned] short, int, long, long long * floating point type: float, double, long double, std::complex<float>, ... * character or string of characters: char, char*, std::string \Composite" types / \Abstract" Data Structures * array, pointer * class, structure, enumerated type, union Structures Classes/Objects Recall Erik's StoneWt example: Starting Point... Pointers Classes/Objects Recall Erik's StoneWt example: Starting Point... Structures Pointers Starting Point... Structures Pointers Classes/Objects Recall Erik's StoneWt example: pmovie->title ≡ (*pmovie).title 6= *pmovie.title ∼ *(pmovie.title) ≡ (*pmovie).title 6= *pmovie.title ∼ *(pmovie.title) pmovie->title 6= *pmovie.title ∼ *(pmovie.title) pmovie->title ≡ (*pmovie).title pmovie->title ≡ (*pmovie).title 6= *pmovie.title ∼ *(pmovie.title) Structure w/pointer: Pointer to a structure: Ptr to a structure w/ptr: List Structures: Structure w/pointer: Ptr to a structure w/ptr: List Structures: Pointer to a structure: Ptr to a structure w/ptr: List Structure w/pointer: Structures: Pointer to a structure: List Structure w/pointer: Structures: Pointer to a structure: Ptr to a structure w/ptr: Structure w/pointer: Structures: Pointer to a structure: Ptr to a structure w/ptr: List H Queue H Stack I lifo I fifo H Other examples: double linked lists, circular lists, double-ended queues, ... Linear Data Structures Lists / Stacks / Queues H Linked Lists H Queue I fifo H Other examples: double linked lists, circular lists, double-ended queues, ... Linear Data Structures Lists / Stacks / Queues H Linked Lists H Stack I lifo H Other examples: double linked lists, circular lists, double-ended queues, ... Linear Data Structures Lists / Stacks / Queues H Queue H Linked Lists H Stack I lifo I fifo Linear Data Structures Lists / Stacks / Queues H Queue H Linked Lists H Stack I lifo I fifo H Other examples: double linked lists, circular lists, double-ended queues, ... stack { implementation, from scratch stack { implementation, from scratch stack { implementation, from scratch stack/queue { implementation, using the C++ STL The C++ Standard Template Library generic collection of class templates and algorithms H Container class templates: I std::deque, double-ended queue I std::forward list, singly linked list I std::list, doubly linked list I std::stack<int> myStack; I std::map/multimap, sorted associative array and multimap I Functions (stack: top, push, pop, size) I std::queue, single-ended queue (std::priority queue) I Alogrithms I std::stack, stack I Modifiers I std::unordered map/multimap, unordered map/multimap, hash tables I std::vector, resizable array Binary Trees ± abstract data structure, such each node has at most two \children" « linked abstract data structure composed of nodes « each node contains a field and one or more pointers to other nodes « recursive structures « a linear list is trivially a tree « graph theory Hash Table (map) ± abstract data structure used to implement an associative array « map keys to values « uses a hash function to compute an index into an array of buckets or slots, from which the correct value can be found « aka dictionary or map Data Structures & Algorithms.