Lesson Objectives Aims

Slides:



Advertisements
Similar presentations
Stack & Queues COP 3502.
Advertisements

CS252: Systems Programming Ninghui Li Program Interview Questions.
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
Fall 2007CS 2251 Iterators and Tree Traversals. Fall 2007CS 2252 Binary Trees In a binary tree, each node has at most two subtrees A set of nodes T is.
CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L12 (Chapter 20) Lists, Stacks,
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Lists ADT (brief intro):  Abstract Data Type  A DESCRIPTION of a data type  The data type can be anything: lists, sets, trees, stacks, etc.  What.
Stacks and Queues Introduction to Computing Science and Programming I.
Connecting with Computer Science, 2e Chapter 8 Data Structures.
ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
Information and Computer Sciences University of Hawaii, Manoa
Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.
CS102 – Data Structures Lists, Stacks, Queues, Trees & HashTables. David Davenport.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Queues, Stacks and Heaps. Queue List structure using the FIFO process Nodes are removed form the front and added to the back ABDC FrontBack.
Heaps and basic data structures David Kauchak cs161 Summer 2009.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
DATA STRUCURES II CSC QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain.
Week 15 – Monday.  What did we talk about last time?  Tries.
Data Structures Intro2CS – week Stack ADT (Abstract Data Type) A container with 3 basic actions: – push(item) – pop() – is_empty() Semantics: –
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Review Array Array Elements Accessing array elements
ADT description Implementations
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
Week 4 - Friday CS221.
Sorted Linked List Same objective as a linked list, but it should be sorted Sorting can be custom according to the type of nodes Offers speedups over non-sorted.
12 C Data Structures.
Chapter 15 Lists Objectives
CS 1114: Implementing Search
Lesson Objectives Aims – Know about…
Problems with Linked List (as we’ve seen so far…)
Stacks and Queues.
Queues Queues Queues.
Week 15 – Monday CS221.
October 30th – Priority QUeues
Stack and Queue APURBO DATTA.
Cse 373 April 14th – TreEs pt 2.
Hashing Exercises.
Tonga Institute of Higher Education
Chapter 17 Object-Oriented Data Structures
CMSC 341 Lecture 5 Stacks, Queues
structures and their relationships." - Linus Torvalds
Data Structures – Stacks and Queus
ITEC 2620M Introduction to Data Structures
Lesson 6. Types Equality and Identity. Collections.
Queues: Implemented using Arrays
Stacks and Queues CSE 373 Data Structures.
Trees CMSC 202, Version 5/02.
Stacks: Implemented using Linked Lists
CMSC 202 Trees.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Stacks and Queues CSE 373 Data Structures.
CSE 373 Data Structures Lecture 6
Stacks and Queues.
Using a Queue Chapter 8 introduces the queue data type.
EE 312 Final Exam Review.
Using a Queue Chapter 8 introduces the queue data type.
CS 367 – Introduction to Data Structures
CSE 373 Data Structures Lecture 6
Queues: Implemented using Linked Lists
structures and their relationships." - Linus Torvalds
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
CS 2308 Final Exam Review.
CS2005 Week 8 Lectures Maps & Binary Trees.
Presentation transcript:

Lesson Objectives Aims Understand algorithms for the following data structures: Stack Queue Tree Depth first traversal Breadth first traversal Linked List

This lesson Tough though it sounds, you are going to need to learn the code for a lot of algorithms You’re going to need to be able to write and recognise that code. It WILL be in your exam – wait until we look at the past papers for proof of that. If you don’t do the tasks in this lesson you will find this incredibly difficult and depressing in equal measure.

Notes CS is about NOT re-inventing the wheel. There is a folder in shared called “Princeton University Notes” These are EXCELLENT resources – they contain diagrams, explanations, examples and CODE (in Java, suck it up) which are INVALUABLE to you. Were there enough caps there for emphasis??

A stack is a FILO data structure Stacks A stack is a FILO data structure Imagine a pile of plates – which one can you get next (realistically?) Stacks support two main operations Push – put something on the top of the stack Pop – get the first item from the top of the stack

Stacks Stacks are incredibly useful when we want to remember the order we did something in or return to a previous state: CPU states (interrupts) Undo (in a program) Reversal of a list of items

Task Implement a Stack class in VB which makes a stack of strings. It must have the following methods: Push Pop GetStackSize (returns the number of elements in the stack) IsFull (returns true or false) IsEmpty (returns true or false) The constructor should set the maximum size of the stack. Print your code and an example of it working and add it to your notes.

Queue A queue is a FIFO data structure New data is added to the end or “tail” of the queue Data is removed from the front or “head” of the queue As with stacks, we use a pointer to keep track of where the head and tail of the queue are.

Queue Like a stack, queues are of finite size (usually) and therefore must be checked for their empty/full states when adding or removing data.

Task Implement a Queue class in VB which accepts a queue of Integers. It must have the following methods: Enqueue Dequeue IsFull (returns true or false) IsEmpty (returns true or false) The constructor should set the maximum size of the queue. If you use arrays, think about how you will use the empty elements – MOD? Print your code and an example of it working and add it to your notes.

A linked list is formed from Nodes. A node contains: The data A pointer to the next node In reality, when you code it, the node may also contain an ID of some sort (if your language doesn’t support pointers, how else are you going to link the list?!)

Linked lists

Bound by the size of the memory or allocation for nodes Linked lists Dynamic Bound by the size of the memory or allocation for nodes Can remove a node by simply changing the pointer Could be expanded by: Creating links for different purposes Double linked lists??

Task Code a linked list of strings in VB VB does not have pointers! So… You will need to create a STRUCTURE which contains the data and a pointer. I’d also suggest it contains an ID? Or you could use the index of an array to be the pointers? Your class should contain: Add node Remove node Fetch nodes (show the list)

Tree A tree is a data structure made up of “Nodes” A node is simply a point in the tree which holds: Some data A pointer to the left node A pointer to the right node A pointer may be: Another node Null (it doesn’t exist)

Terminology (all are nodes (the same thing)): What does it look like? Terminology (all are nodes (the same thing)): ROOT – The top node in the tree. All trees have one (and only one) root node. LEAF – A single node which isn’t the root, but has no children. PARENT – A node which isn’t the root, but does have one or more children CHILD – A node connected to a parent node.

Tree Vs Binary Tree Most tree data structures are implemented as “Binary Trees” These are identical, except for one important feature Each node may have a maximum of 2 children – a left and a right node.

Task I am not going to ask you to implement a tree BUT, I am going to ask you to type in (not download and run) the code linked on the next slide You STILL need to understand the code It is also an excellent introduction to recursion and makes a lot of sense.

Trees A really good resource https://www.codeproject.com/articles/4647/a-simple-binary-tree-implementation-with-vb-net

Traversal Trees are often used because they: Automatically sort data Make sense for AI: Decisions Following trains of thought Potential moves in a game etc. They can be “traversed” (searched) in multiple ways. Find out about Depth first and breadth first (fairly obvious) and add to your notes. You will have already covered one if you tried the code and tested it.

Review/Success Criteria You should know: The main data structures in computer science How to recognise a data structure from its code How to code each data structure in VB and, by default, pseudo code