Review Pseudo Code Basic elements of Pseudo code

Slides:



Advertisements
Similar presentations
Topic Reviews For Unit ET156 – Introduction to C Programming Topic Reviews For Unit
Advertisements

You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Chapter 25 Lists, Stacks, Queues, and Priority Queues
CS Data Structures I Chapter 6 Stacks I 2 Topics ADT Stack Stack Operations Using ADT Stack Line editor Bracket checking Special-Palindromes Implementation.
Advanced Piloting Cruise Plot.
Chapter 1 The Study of Body Function Image PowerPoint
11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Determine Eligibility Chapter 4. Determine Eligibility 4-2 Objectives Search for Customer on database Enter application signed date and eligibility determination.
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
Lecture 15 Linked Lists part 2
CS16: Introduction to Data Structures & Algorithms
Chapter 7: Arrays In this chapter, you will learn about
Chapter Objectives To learn about recursive data structures and recursive methods for a LinkedList class To understand how to use recursion to solve the.
Pointers and Data Structures 1 Yinzhi Cao Modified from slides made by Prof Goce Trajcevski.
COMP171 Fall 2005 Lists.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Singly Linked Lists What is a singly-linked list? Why linked lists?
Linked Lists Chapter 4.
1111 Abstract Data Types Cpt S 223. School of EECS, WSU.
Data Structures: A Pseudocode Approach with C
Data Structures ADT List
Chapter 24 Lists, Stacks, and Queues
Main Index Contents 11 Main Index Contents Shifting blocks of elements… Shifting blocks of elements… Model of a list object… Model of a list object… Sample.
ITEC200 Week04 Lists and the Collection Interface.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
1 CSE1301 Computer Programming: Lecture 27 List Manipulation.
Data Structures Using C++
LIST PROCESSING.
Double-Linked Lists and Circular Lists
Arrays Dr. Jey Veerasamy July 31 st – August 23 rd 9:30 am to 12 noon 1.
CHP-5 LinkedList.
FIFO Queues CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
1 Joe Meehean. Ordered collection of items Not necessarily sorted 0-index (first item is item 0) Abstraction 2 Item 0 Item 1 Item 2 … Item N.
ABC Technology Project
1 DATA STRUCTURES. 2 LINKED LIST 3 PROS Dynamic in nature, so grow and shrink in size during execution Efficient memory utilization Insertion can be.
1 Designing Hash Tables Sections 5.3, 5.4, Designing a hash table 1.Hash function: establishing a key with an indexed location in a hash table.
Hash Tables.
VOORBLAD.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
Linked Lists.
The List ADT Textbook Sections
Squares and Square Root WALK. Solve each problem REVIEW:
© 2012 National Heart Foundation of Australia. Slide 2.
Chapter 5 Test Review Sections 5-1 through 5-4.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Week 1.
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
PSSA Preparation.
Foundations of Data Structures Practical Session #7 AVL Trees 2.
Data Structures Using C++ 2E
Lecture No.01 Data Structures Dr. Sohail Aslam
Dr. Engr. Sami ur Rahman Assistant Professor Department of Computer Science University of Malakand Data Structure: List.
CSC 211 Data Structures Lecture 7
CSCS-200 Data Structure and Algorithms Lecture
List data structure This is a new data structure. The List data structure is among the most generic of data structures. In daily life, we use shopping.
Data Structures & Algorithms
Lecture No.02 Data Structures Dr. Sohail Aslam
Presentation transcript:

Review Pseudo Code Basic elements of Pseudo code Basic operations of Pseudo code Flow Chart Symbols used in flow charts Examples

List List Data Structure List operations List Implementation Array Linked List

The LIST Data Structure The List is among the most generic of data structures. Real life: shopping list, groceries list, list of people to invite to dinner List of presents to get

Lists A list is collection of items that are all of the same type (grocery items, integers, names) The items, or elements of the list, are stored in some particular order It is possible to insert new elements into various positions in the list and remove any element of the list

Lists List is a set of elements in a linear order. For example, data values a1, a2, a3, a4 can be arranged in a list: (a3, a1, a2, a4) In this list, a3, is the first element, a1 is the second element, and so on The order is important here; this is not just a random collection of elements, it is an ordered collection

Lists List is a set of elements in a linear order. For example, data values a1, a2, a3, a4 can be arranged in a list: (a3, a1, a2, a4) In this list, a3, is the first element, a1 is the second element, and so on The order is important here; this is not just a random collection of elements, it is an ordered collection

List Operations Useful operations createList(): create a new list (presumably empty) copy(): set one list to be a copy of another clear(); clear a list (remove all elments) insert(X, ?): Insert element X at a particular position in the list remove(?): Remove element at some position in the list get(?): Get element at a given position update(X, ?): replace the element at a given position with X find(X): determine if the element X is in the list length(): return the length of the list.

List Operations We need to decide what is meant by “particular position”; we have used “?” for this. There are two possibilities: Use the actual index of element: insert after element 3, get element number 6. This approach is taken by arrays Use a “current” marker or pointer to refer to a particular position in the list.

List Operations We need to decide what is meant by “particular position”; we have used “?” for this. There are two possibilities: Use the actual index of element: insert after element 3, get element number 6. This approach is taken by arrays Use a “current” marker or pointer to refer to a particular position in the list.

List Operations If we use the “current” marker, the following four methods would be useful: start(): moves the “current” pointer to the first element. tail(): moves the “current” pointer to the last element. next(): move the current position forward one element back(): move the current position backward one element

Implementing Lists We have designed the interface for the List; we now must consider how to implement that interface.

Implementing Lists We have designed the interface for the List; we now must consider how to implement that interface. Implementing Lists using an array: for example, the list of integers (2, 6, 8, 7, 1) could be represented as: A 6 8 7 1 2 3 4 5 current size

List Implementation add(9); current position is 3. The new list would thus be: (2, 6, 8, 9, 7, 1) We will need to shift everything to the right of 8 one place to the right to make place for the new element ‘9’. current 3 size 5 step 1: A 6 8 7 1 2 4 current 4 size 6 step 2: A 8 7 1 2 3 5 9 notice: current points to new element

Implementing Lists next(): current 4 size 6 A 8 7 1 2 3 5 9 5

Implementing Lists There are special cases for positioning the current pointer: past the last array cell before the first cell We will have to worry about these when we write the actual code.

Implementing Lists remove(): removes the element at the current index 5 size 6 A 8 1 2 3 4 9 Step 1: current 5 size A 6 8 1 2 3 4 9 Step 2:

Implementing Lists remove(): removes the element at the current index 5 size 6 A 8 1 2 3 4 9 Step 1: current size 5 A 2 6 8 9 1 Step 2: 5 1 2 3 4 5 We fill the blank spot left by the removal of 7 by shifting the values to the right of position 5 over to the left one space.

Implementing Lists find(X): traverse the array until X is located. int find(int X) { int j; for(j=1; j < size+1; j++ ) if( A[j] == X ) break; if( j < size+1 ) { // found X current = j; // current points to where X found return 1; // 1 for true } return 0; // 0 (false) indicates not found }

Implementing Lists Other operations: get()  return A[current]; update(X)  A[current] = X; length()  return size; back()  current--; start()  current = 1; end()  current = size;

Analysis of Array Lists add we have to move every element to the right of current to make space for the new element. Worst-case is when we insert at the beginning; we have to move every element right one place. Average-case: on average we may have to move half of the elements

Analysis of Array Lists remove Worst-case: remove at the beginning, must shift all remaining elements to the left. Average-case: expect to move half of the elements. find Worst-case: may have to search the entire array Average-case: search at most half the array. Other operations are one-step.

List Using Linked Memory Various cells of memory are not allocated consecutively in memory.

List Using Linked Memory Various cells of memory are not allocated consecutively in memory. With arrays, the second element was right next to the first element.

List Using Linked Memory Various cells of memory are not allocated consecutively in memory. With arrays, the second element was right next to the first element. Now the first element must explicitly tell us where to look for the second element

List Using Linked Memory Various cells of memory are not allocated consecutively in memory. With arrays, the second element was right next to the first element. Now the first element must explicitly tell us where to look for the second element. Do this by holding the memory address of the second element

List Using Linked Memory Various cells of memory are not allocated consecutively in memory. With arrays, the second element was right next to the first element. Now the first element must explicitly tell us where to look for the second element. Do this by holding the memory address of the second element This is what we call Linked List

Summary List Data Structure List operations List Implementation Array Linked List