Arrays © 2014 Goodrich, Tamassia, Goldwasser Arrays Vectors

Slides:



Advertisements
Similar presentations
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Advertisements

Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
HST 952 Computing for Biomedical Scientists Lecture 9.
CS 307 Fundamentals of Computer Science 1 Lists and ArrayList many slides taken from Mike Scott, UT Austin.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Doubly Linked Lists1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
Lecture 5 of Computer Science II Arrays Instructor: Mr.Ahmed Al Astal.
Arrays & Linked Lists Last Update: Aug 21, 2014EECS2011: Arrays & Linked Lists1.
DREW ALVAREZ AND CORDIE GOODRICH ARRAYS AND ARRAY LISTS.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
© 2014 Goodrich, Tamassia, Goldwasser Singly Linked Lists1 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
© 2004 Goodrich, Tamassia Vectors1 Vectors and Array Lists.
Array Lists1 © 2010 Goodrich, Tamassia. Array Lists2 The Array List ADT  The Array List ADT extends the notion of array by storing a sequence of arbitrary.
Arrays1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich,
Heaps © 2010 Goodrich, Tamassia. Heaps2 Priority Queue ADT  A priority queue (PQ) stores a collection of entries  Typically, an entry is a.
The Container Class A Collection of Data. What is a Container Class?  A class that can contain a collection of items  A list or bag of items of the.
Lists1 © 2010 Goodrich, Tamassia. Position ADT  The Position ADT models the notion of place within a data structure where a single object is stored 
Chapter 6. Character String Types It is one in which the values consists of sequences of characters. How to Define a variable contain a string? In a programming.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Sorting With Priority Queue In-place Extra O(N) space
Lists and Iterators 5/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Lecture 5 of Computer Science II
Binary Search Trees < > =
Vectors 5/31/2018 9:25 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Ch7. List and Iterator ADTs
Sequences 6/3/2018 9:11 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Doubly Linked Lists 6/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Array, Strings and Vectors
Linked Lists Linked Lists 1 Sequences Sequences 07/25/16 10:31
Priority Queues © 2010 Goodrich, Tamassia Priority Queues 1
Heaps 8/2/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Introduction to Programming Lecture 5
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Queues 11/9/2018 6:32 PM Queues.
Object Oriented Programming COP3330 / CGS5409
Ch7. List and Iterator ADTs
Lists and Iterators 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Vectors 11/29/2018 6:45 PM Vectors 11/29/2018 6:45 PM Vectors.
Chapter 8 Arrays Objectives
" A list is only as strong as its weakest link. " - Donald Knuth
Array-Based Sequences
ArrayList Collections.
Tree Representation Heap.
© 2013 Goodrich, Tamassia, Goldwasser
And the list goes on and on and on….
Stacks 12/7/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Doubly Linked Lists or Two-way Linked Lists
CS2013 Lecture 4 John Hurley Cal State LA.
Object Oriented Programming in java
Arrays .
Cs212: Data Structures Computer Science Department Lecture 2: Arrays.
Problem Understanding
Recall What is a Data Structure Very Fundamental Data Structures
Python Primer 1: Types and Operators
Objectives In this chapter, you will: - Learn about records (structs) - Examine operations on a struct - Manipulate data using a struct - Learn about the.
Adaptable Priority Queues
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Chapter 8 Arrays Objectives
1 Lecture 10 CS2013.
Vectors 4/26/2019 8:32 AM Vectors 4/26/2019 8:32 AM Vectors.
Computing Spans Given an an array X, the span S[i] of X[i] is
Array-Based Lists & Pointers
CS2013 Lecture 7 John Hurley Cal State LA.
STL List.
Data Structures and Algorithm Analysis Priority Queues (Heaps)
Abstract Data Types Abstraction is to distill a system to its most fundamental parts. Applying the abstraction paradigm to the design of data structures.
STL List.
Problem Understanding
Presentation transcript:

Arrays © 2014 Goodrich, Tamassia, Goldwasser Arrays Vectors 7/23/2019 4:40 PM Arrays © 2014 Goodrich, Tamassia, Goldwasser Arrays

Array Definition An array is a sequenced collection of variables all of the same type. Each variable, or cell, in an array has an index, which uniquely refers to the value stored in that cell. The cells of an array, A, are numbered 0, 1, 2, and so on. Each value stored in an array is often called an element of that array. A 1 2 i n © 2014 Goodrich, Tamassia, Goldwasser Arrays

Array Length and Capacity Since the length of an array determines the maximum number of things that can be stored in the array ---capacity. In Java, the length of an array named a can be accessed using the syntax a.length. numbered 0, 1, 2, and so on, up through a.length−1, the cell with index k can be accessed with syntax a[k]. a 1 2 k n © 2014 Goodrich, Tamassia, Goldwasser Arrays

Declaring Arrays The first way to create an array: The elementType elementType arrayName[size]; The elementType base type or class name, arrayName Valid identifier © 2014 Goodrich, Tamassia, Goldwasser Arrays

Arrays of Characters or Object/struct References An array can store primitive elements, such as characters. An array can also store references to structs. © 2014 Goodrich, Tamassia, Goldwasser Arrays

Adding an Entry To add an entry e into array board at index i, we need to make room for it by shifting forward the n - i entries board[i], …, board[n – 1] board 1 2 i n board 1 2 i n board e 1 2 i n © 2014 Goodrich, Tamassia, Goldwasser Arrays

Removing an Entry To remove the entry e at index i, we need to fill the hole left by e by shifting backward the n - i - 1 elements board[i + 1], …, board[n – 1] board e 1 2 i n board 1 2 i n board 1 2 i n © 2014 Goodrich, Tamassia, Goldwasser Arrays

Disadvantages of arrays? © 2014 Goodrich, Tamassia, Goldwasser Arrays

Disadvantages of arrays? Need to know the maximum size before hand If elements need to be kept in order Inserting/deleting an element requires moving (lots of) elements Can there be a faster way? © 2014 Goodrich, Tamassia, Goldwasser Arrays