Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Fundamentals

Similar presentations


Presentation on theme: "Programming Fundamentals"— Presentation transcript:

1 Programming Fundamentals
Session III Master a Skill / Learn for Life

2 Session Outline Data Structures Algorithms
Chapter 1 - Structures and Arrays Chapter 2 - Sets and Linked List Chapter 3 - Collections and Dictionaries Chapter 4 - Stack, Queues, and Deques Chapter 5 - Graphs and Trees Algorithms Chapter 1 - Sorting Algorithm Chapter 2 - Searching Algorithms Chapter 3 - String Searching Chapter 4 - Data Compression Algorithms Chapter 5 - Encryption Algorithm 11/10/2018 Copyright © Carl M. Burnett

3 Data Structures Chapter 1 - Structures and Arrays
Chapter 2 - Sets and Linked Lists Chapter 3 - Collections and Dictionaries Chapter 4 - Stacks, Queues, Disques Chapter 5 - Graphs and Trees 11/10/2018 Copyright © Carl M. Burnett

4 Structures and Arrays Structure – Record = Database record Array:
Series or list of variables in computer memory All share the same name Each has a different subscript Subscript (or index): Position number of an item in an array Subscripts are always a sequence of integers 11/10/2018 Copyright © Carl M. Burnett

5 Dim NameArray(15) as String
Defining an Array Variable Name Array Size – Number of Items to Store Type of Data – Integer or String Dim NameArray(15) as String 11/10/2018 Copyright © Carl M. Burnett

6 How Arrays Occupy Computer Memory
Each item has same name and same data type Element: an item in the array Array elements are contiguous in memory Size of the array: number of elements it will hold 25 someVal[0] 36 someVal[1] 47 someVal[2] 15 aNumber 11/10/2018 Copyright © Carl M. Burnett

7 How Arrays Occupy Computer Memory
Subscript is placed in parentheses or square brackets following the array name (language-dependent) Zero-based array: First subscript is 0 Highest subscript value is 1 less than the array size Arrays make programs more efficient and professional 11/10/2018 Copyright © Carl M. Burnett

8 Defining Size Bounds Default Bounds Lower Bound - First Element
Upper Bound – Last Element Default Bounds C and Java = Starts with 0 (Zero-Based Array) Other Language = Start with 1 (One-based Array) 11/10/2018 Copyright © Carl M. Burnett

9 Dim LotteryNumbers(5) as Integer
Defining Size 1 2 3 4 Zero-Based Array 1 2 3 4 5 One-Based Array Dim LotteryNumbers(5) as Integer 11/10/2018 Copyright © Carl M. Burnett

10 Dim LotteryNumbers(33..37) as Integer
Defining Bounds Dim LotteryNumbers(33..37) as Integer 33 34 35 36 37 11/10/2018 Copyright © Carl M. Burnett

11 Array Declaration and Initialization
Programming Language DIM COUNT(30) BASIC, Visual Basic int count(30); C#, C++ int() count = new int(30); Java COUNT OCCURS 30 TIMES PICTURE 9999. COBOL Array count (1…30) of integer; Pascal Array elements do not have to be declared individually Put the array size in square brackets in the declaration 11/10/2018 Copyright © Carl M. Burnett

12 Array Declaration and Initialization
Array elements should be initialized Initialization loop: loop structure that provides initial values to an array Use the loop control variable as the array subscript 11/10/2018 Copyright © Carl M. Burnett

13 Array Declaration and Initialization
Basic Dim LotteryNumbers(5) as Integer For I = 1 to 5 LotteryNumbers(1) = 0 Next I C++ Int lotterynumbers[] = (0, 0, 0, 0, 0); 11/10/2018 Copyright © Carl M. Burnett

14 Storing Data in Array The Array Name Array Element Basic
Dim myarray(5) as Integer myarray(1) = 357 C++ Int myarray[5]; myarray[0] = 357; Int myarray[5]; myarray[0] = 47; myarray[3] = 91; myarray[1] = 6; 11/10/2018 Copyright © Carl M. Burnett

15 Retrieving Data Basic Dim Names(3) as String
Names(1) = “George Washington” Names(2) = “John Adams” Names(3) = “Thomas Jefferson” Print Names (2) This prints the name John Adams on screen. 11/10/2018 Copyright © Carl M. Burnett

16 Multi-Dimensional Arrays
Sometime known as a Data Grid BigArray (1,1) BigArray (1,2) BigArray (2,1) BigArray (2,2) BigArray (3,1) BigArray (3,2) BigArray (4,1) BigArray (4,2) Basic Dim BigArray(4,2) as String Dim BigArray(2,4,3,8) as String C++ string BigArray[4][2]; string BigArray[2][4][3][8]; 11/10/2018 Copyright © Carl M. Burnett

17 Multi-Dimensional Arrays
Storing and Getting Data Dim BigArray(4,2) as String BigArray(4,1) = “Grover Cleveland” Print BigArray(4,1) This prints the name Grover Cleveland on screen. 11/10/2018 Copyright © Carl M. Burnett

18 Array Drawbacks Large Arrays take up more space
Arrays can hold only one data type Searching and sorting is difficult Inserting and removing data is cumbersome 11/10/2018 Copyright © Carl M. Burnett

19 Sets and Linked Lists Arrays stores integers.
You may need to create resizable (dynamic) arrays. Arrays stores a special Variant data type - both numbers and text. Many programming languages allow you to create other types of data structures. Two popular alternatives to arrays are: Sets Linked Lists 11/10/2018 Copyright © Carl M. Burnett

20 Sets Advantages No definition of fixed size.
An array to hold seven separate variables like this: Dim Day(6) as String Day(0) = "Monday" Day(1) = "Tuesday" Day(2) = "Wednesday" Day(3) = "Thursday" Day(4) = "Friday" Day(5) = "Saturday" Day(6) = "Sunday" From set import sets days = Set ([‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’, ‘Sunday’]) Advantages No definition of fixed size. No ID of index number for data Can use mixed data types 11/10/2018 Copyright © Carl M. Burnett

21 Linked Lists It is a data structure Group of nodes
Represent a sequence. A linear collection of data elements Pointer - Points to the next node by means of a pointer. Variables Variables hold data Pointer A pointer points to another node 11/10/2018 Copyright © Carl M. Burnett

22 Linked Lists Advantages Disadvantages
dynamic data structure - can grow and be pruned, allocating and deallocating memory Insertion and deletion node operations are easily implemented in a linked list. Dynamic data structures such as stacks and queues can be implemented using a linked list. There is no need to define an initial size for a Linked list. Items can be added or removed from the middle of list. Disadvantages They use more memory than arrays Nodes must be read in order - sequential access. Nodes are stored incontiguously - greatly increasing the access time required. Difficulties in reverse traversing. 11/10/2018 Copyright © Carl M. Burnett

23 Collections A grouping of some variable number of data items
Shared significance to the problem being solved Need to be operated upon together in some controlled fashion. Like a resizable array. Can hold different data types. Collections include: Lists Sets Multisets Trees graphs Implementations include: C++: known as "container“ Java: implemented in the Java collections framework; Python: some built-in, others implemented in the collections library. 11/10/2018 Copyright © Carl M. Burnett

24 Dictionaries An associative array, map, symbol table.
Abstract data type Composed of a collection of (key, value) pairs. Operations associated with this data type allow: the addition of a pair to the collection the removal of a pair from the collection the modification of an existing pair the lookup of a value associated with a particular key 11/10/2018 Copyright © Carl M. Burnett

25 Dictionaries Language support
Dictionaries - Smalltalk, Objective-C, .NET,[13] Python, REALbasic, Swift, and VBA. Hashes - Perl, Ruby and Seed7 Maps - C++, Java, Go, Clojure, Scala, OCaml, Haskell, Hash tables - Common Lisp and Windows PowerShell Associative Arrays - PHP Objects – JavaScript, JSON (All objects behave as associative arrays with string-valued keys. 11/10/2018 Copyright © Carl M. Burnett

26 Stacks 11/10/2018 Copyright © Carl M. Burnett

27 Queues & Deques 11/10/2018 Copyright © Carl M. Burnett

28 Graphs Data structure: Vertices or Nodes or Points
Connections - set of unordered pairs of these vertices 11/10/2018 Copyright © Carl M. Burnett

29 Graphs Abstract Data Type Undirected graph Directed graph
5 2 3 9 Directed graph 6 Weighted graph 8 3 1 7 11/10/2018 Copyright © Carl M. Burnett

30 Trees Simulates a hierarchical tree structure A root value
Subtrees of children with a parent node Represented as a set of linked nodes. 11/10/2018 Copyright © Carl M. Burnett

31 Trees Edge - The connection between one node and another.
Path - A sequence of nodes and edges connecting a node with a descendant. Level - The level of a node is defined by 1 + (the number of connections between the node and the root). Height of node - The height of a node is the number of edges on the longest path between that node and a leaf. Height of tree - The height of a tree is the height of its root node. Depth - The depth of a node is the number of edges from the tree's root node to the node. Forest - A forest is a set of n ≥ 0 disjoint trees. Root - The top node in a tree. Child - A node directly connected to another node when moving away from the Root. Parent - The converse notion of a child. Siblings - A group of nodes with the same parent. Descendant - A node reachable by repeated proceeding from parent to child. Ancestor - A node reachable by repeated proceeding from child to parent. Leaf (External node) - A node with no children. Branch (Internal node) - A node with at least one child. Degree - The number of sub trees of a node. 11/10/2018 Copyright © Carl M. Burnett

32 Algorithms Sorting Algorithms Searching Algorithms
String Searching Algorithms Data Compression Algorithms Encryption Algorithms 11/10/2018 Copyright © Carl M. Burnett

33 Sorting Algorithms Comparison of Different Sorting Algorithms
Average Best Worst Bubble Sort O(n^2) Selection Sort Insertion Sort O(n) Heap Sort O(n*log(n)) Merge Sort Quick Sort 11/10/2018 Copyright © Carl M. Burnett

34 Searching Algorithms Category of Searching Algorithms
Uninformed (Brute-Force) Informed (Heuristic) 11/10/2018 Copyright © Carl M. Burnett

35 Sequential Search Algorithms
Uninformed Algorithm Backward or Forward Block Binary Interpolation 11/10/2018 Copyright © Carl M. Burnett

36 Informed Searching Indexes Adversarial Search Alpha-bets Pruning
Clustered Index Unclustered Index Adversarial Search Alpha-bets Pruning 11/10/2018 Copyright © Carl M. Burnett

37 String Searching Algorithms
Sequential Text Boyer-Moore Algorithm Rabin-Karp Algorithm Shift Or Algorithm Regular Expressions Multiple Character Patterns Alternate Patterns Phonetically 11/10/2018 Copyright © Carl M. Burnett

38 Data Compression Algorithms
Lossless Data Compression Run-Length Encoding (RLE) Burrow-Wheeler Algorithm Dictionary Encoding LZ77 Algorithm LZW Algorithm Lossy Data Compression 11/10/2018 Copyright © Carl M. Burnett

39 Encryption Algorithms
Stream Ciphers Block Ciphers Electronic Code Book (ECB) Cipher-block Chaining (CBC) Symmetrical Encryption Asymmetrical Encryption Hash Functions 11/10/2018 Copyright © Carl M. Burnett

40 Student Exercise Continue to work on your Getting Dressed Program. Identify and create a data dictionary for all the data types used in your process. These include: Data Variables Arrays Collections Classes Objects Metadata 11/10/2018 Copyright © Carl M. Burnett

41 Next – Web Programming & Web Programming Languages
Session Review Data Structures Chapter 1 - Structures and Arrays Chapter 2 - Sets and Linked List Chapter 3 - Collections and Dictionaries Chapter 4 - Stack, Queues, and Deques Chapter 5 – Graphs and Trees Algorithms Chapter 1 - Sorting Algorithm Chapter 2 - Searching Algorithms Chapter 3 - String Searching Chapter 4 - Data Compression Algorithms Chapter 5 - Encryption Algorithm Next – Web Programming & Web Programming Languages 11/10/2018 Copyright © Carl M. Burnett


Download ppt "Programming Fundamentals"

Similar presentations


Ads by Google