Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Data Representation Methods - Algorithms and Applications in Java - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Algorithms and Applications in Java which includes Greedy Method, Divide and Conquer, Dynamic Programming, Backtracking, Branch and Bound, Integer Programming, Neural Networks, Genetic Algorithms, Tabu Search etc.Key important points are: Data Representation Methods, Simulated Pointer, Linear List, Array Representation, One-Dimensional Array, Right to Left Mapping, Wrap Around Mapping, Representation Used in Text, Data Type

Typology: Slides

2012/2013

Uploaded on 03/27/2013

agarkar
agarkar 🇮🇳

4.3

(26)

380 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Representation Methods
array --- Chapter 5
linked --- Chapter 6
simulated pointer --- Chapter 7
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Data Representation Methods - Algorithms and Applications in Java - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Data Representation Methods

array --- Chapter 5

linked --- Chapter 6

simulated pointer --- Chapter 7

Linear List Array Representation

use a one-dimensional array element[]

a b c d e

L = (a, b, c, d, e)

Store element i of list in element[i].

Mapping That Skips Every Other

Position

a b c d e

Wrap Around Mapping

d e a b c

Add/Remove An Element

a b c d e

size = 5

a g b c d e

size = 6

add(1,g)

Data Type Of Array element[]

Data type of list elements is unknown.

Define element[] to be of data type Object.

Cannot put elements of primitive data types

(int, float, double, char, etc.) into our linear

lists.

Increasing Array Length Length of array element[] is 6. a b c d e f newArray = new Object[15]; First create a new and larger array

Increasing Array Length Now copy elements from old array to new one. a b c d e f a b c d e f

Altogether Now

// create a new array of proper length and data type

Object [] newArray = new Object [newLength];

// copy all elements from old array into new one

System.arraycopy(element, 0, newArray, 0,

element.length);

// rename array

element = newArray;

public static Object [] changeLength(Object [] a, int newLength) { Object [] newArray = new Object [newLength]; System.arrayCopy(…); return newArray; } Integer [] a = new Integer [10]; …. a = (Integer []) changeLength(a, 100); // erroneous

Space Complexity newArray = new char[7]; space needed = 2 * newLength – 1 = 2 * maxListSize – 1 element[6] a b c d e f

Array Doubling Double the array length. a b c d e f newArray = new char[12]; a b c d e f Time for n adds goes up by Theta(n). Space needed = 1.5newLength. Space needed <= 3maxListSize – 3

How Big Should The New Array Be? Resizing by an additive constant c requires at most (maxListSize – 1) + (maxListSize – 1 + c) = 2 * (maxListSize – 1) + c space. Resizing by any constant factor new length = c * old length requires at most (1+c) * (maxListSize -1) space_._

What Does Java Do?

java.util.Vector … array doubling

java.util.ArrayList … c = 1.

dataStructures.ArrayLinearList of text … c = 2