slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Abstract Data Types Sir Joseph Lindo University of the Cordilleras PowerPoint Presentation
Download Presentation
Abstract Data Types Sir Joseph Lindo University of the Cordilleras

Loading in 2 Seconds...

play fullscreen
1 / 45

Abstract Data Types Sir Joseph Lindo University of the Cordilleras - PowerPoint PPT Presentation


  • 88 Views
  • Uploaded on

Abstract Data Types Sir Joseph Lindo University of the Cordilleras. Abstract Data Types. Array (A review). Array. ADT. ADT. a contiguous block of memory, divided into a number of slots stores multiple data items of the same data type. List. Stack. Queue. Case. Abstract Data Types.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Abstract Data Types Sir Joseph Lindo University of the Cordilleras' - melinda-oliver


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

Abstract

Data

Types

Sir Joseph Lindo

University of the Cordilleras

slide2

Abstract Data Types

Array (A review)

Array

ADT

ADT

  • a contiguous block of memory, divided into a number of slots
  • stores multiple data items of the same data type

List

Stack

Queue

Case

slide3

Abstract Data Types

Abstract Data

Type

Array

ADT

ADT

  • a design tool
  • concern on the important concept or model
  • access is restricted
  • Array is an ADT?

List

Stack

Queue

Case

slide4

Abstract Data Types

Abstract Data

Type

Array

ADT

ADT

  • List
  • Stack
  • Queue

List

Stack

Queue

Case

slide5

Abstract Data Types

List

Array

  • Array List
  • Linked List
  • Doubly Linked List
  • Circular Linked list

ADT

List

List

Stack

Queue

Case

slide6

Abstract

Data

Types

-- end --

Sir Joseph Lindo

University of the Cordilleras

slide7

Abstract

Data

Types

-- end na --

Sir Joseph Lindo

University of the Cordilleras

slide8

Memory

start

Array (A review)

1D Array

a

b

c

d

1-dimensional array x = [a, b, c, d]

map into contiguous memory locations

location(x[i]) = start + i

slide9

Array (A review)

2D Array

The elements of a 2-dimensional array a declared as:

int [][]a = new int[3][4];

may be shown as a table

a[0][0] a[0][1] a[0][2] a[0][3]

a[1][0] a[1][1] a[1][2] a[1][3]

a[2][0] a[2][1] a[2][2] a[2][3]

slide10

Array (A review)

2D Array

2-dimensional array x

a, b, c, d

e, f, g, h

i, j, k, l

view 2D array as a 1D array of rows

x = [row0, row1, row 2]

row 0 = [a,b, c, d]

row 1 = [e, f, g, h]

row 2 = [i, j, k, l]

and store as 4 1D arrays

slide11

x[]

a

b

c

d

e

f

g

h

i

j

k

l

Array (A review)

2D Array to 1D

x.length = 3

x[0].length = x[1].length = x[2].length = 4

slide12

0

c

2c

3c

ic

row 0

row 1

row 2

row i

Array (A review)

Locating Element x[i][j]

assume x has r rows and c columns

each row has c elements

i rows to the left of row i

so ic elements to the left of x[i][0]

so x[i][j] is mapped to position

ic + j of the 1D array

slide13

ADT

Array is an ADT?

  • In an array any item can be accessed, while in ADT access is restricted.
  • ADT are more abstract than arrays.
slide14

List

Array List

  • The Array List ADT extends the notion of array by storing a sequence of arbitrary objects
slide15

List

Array List

  • An element can be accessed, inserted or removed by specifying its index (number of elements preceding it)
  • An exception is thrown if an incorrect index is given (e.g., a negative index)
slide16

List

Array List

  • Applications:
  • Direct applications
  • Sorted collection of objects (elementary database)
  • Indirect applications
  • Auxiliary data structure for algorithms
  • Component of other data structures
slide17

List

Array-Based Implementation

Use an array A of size N

A variable n keeps track of the size of the array list

Operation get(i) is implemented in returning A[i]

Operation set(i,o) is implemented performing t = A[i], A[i] = o, and returning t.

slide18

List

Array-Based Implementation

Insertion

In operation add(i, o), we need to make room for the new element by shifting forward the n – I elements A[i], …, A[n - 1]

slide19

List

Array-Based Implementation

Deletion

In operation remove(i), we need to fill the hole left by the removed element by shifting backward the n - i – 1 elements A[i + 1], …, A[n - 1]

slide20

List

Array-Based Implementation

Main Methods:

get(integer i): returns the element

set(integer i, object o): replace the element at index i with o and return the old element

add(integer i, object o): insert a new element o to have index i

remove(integer i): removes and returns the element at index i

slide21

List

Linked List

  • Various cells of memory are not allocated consecutively in memory.
  • Not enough to store the elements of the list.
  • 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
slide22

List

Linked List

  • Create a structure called a Node.
    • The objectfield will hold the actual list element.
    • The nextfield in the structure will hold the starting location of the next node.
    • Chain the nodes together to form a linkedlist.
slide23

List

Linked List

Picture of our list (2, 6, 7, 8, 1) stored as a linked list:

slide24

List

Linked List

Actual picture in memory:

slide25

List

Doubly-Linked List

  • Moving forward in a singly-linked list is easy; moving backwards is not so easy.
  • To avoid this we can use two pointers in a node: one to point to next node and another to point to the previous node:
slide26

List

Doubly-Linked List

slide27

List

Circular - Linked List

  • The next field in the last node in a singly-linked list is set to NULL.
  • Moving along a singly-linked list has to be done in a watchful manner.
  • Doubly-linked lists have two NULL pointers: prev in the first node and next in the last node.
  • A way around this potential hazard is to link the last node with the first node in the list to create a circularly-linked list.
slide28

List

Circular - Linked List

  • Two views of a circular linked list:
slide29

List

Josephus Problem

  • A case where circularly linked list comes in handy is the solution of the Josephus Problem.
  • Consider there are 10 persons. They would like to choose a leader.
  • The way they decide is that all 10 sit in a circle.
  • They start a count with person 1 and go in clockwise direction and skip 3. Person 4 reached is eliminated.
slide30

List

Josephus Problem

  • The count starts with the fifth and the next person to go is the fourth in count.
  • Eventually, a single person remains.
slide31

List

Josephus Problem

slide32

List

Josephus Problem

slide33

List

Josephus Problem

slide34

List

Josephus Problem

slide35

List

Josephus Problem

slide36

List

Josephus Problem

slide37

List

Josephus Problem

slide38

List

Josephus Problem

slide39

List

Josephus Problem

slide40

List

Josephus Problem

slide41

Comprehension Check

Josephus Problem

  • Given fifteen person named: Akang, Bebeng, Chito, Dingdong, Eman, Feng, Gina, Henry, Ikong, Joseph, Kekang, Lina, Neneng, Mario, Omar
  • They are arranged in the same manner as mentioned above
slide42

Comprehension Check

Josephus Problem

  • Using the circular-linked list and the Josephus problem
  • Using 5 movements
  • Answer the questions in the next slide.
  • Show the complete solution/cycle
slide43

Comprehension Check

Josephus Problem

  • Which of the persons will be selected as the leader?
  • Which of them will be the third to be eliminated?
  • Which of them will be the 10th to be eliminated?
  • Which of them will be the 7th to be eliminated?
  • Which of them will be the 13th to be eliminated?
slide44

Abstract

Data

Types

-- end --

Sir Joseph Lindo

University of the Cordilleras

slide45

Abstract

Data

Types

-- end na --

Sir Joseph Lindo

University of the Cordilleras