Top Banner
using Java 2015 Data Structure Prepared by: Mahmoud Rafeek Al-farra in Java 2. Introduction to data structure
20

2 introduction to data structure

Jan 15, 2017

Download

Education

Mahmoud Alfarra
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 2  introduction to data structure

using Java

2015

Data Structure Prepared by: Mahmoud Rafeek Al-farra

in Java

2. Introduction to data structure

Page 2: 2  introduction to data structure

mfarra.cst.ps www.fb.com/MahmoudRFarra

Contents

Big - Oh notation

Generic programming

Collection Classes

Applications of data structure

What is data structure ?

Page 3: 2  introduction to data structure

What is data structure ?mfarra.cst.ps www.fb.com/MahmoudRFarra

Data Structure: Abstract way to organize information. A collection of basic data types.

Algorithm: Abstract way to perform computation tasks.

Page 4: 2  introduction to data structure

What is data structure ?mfarra.cst.ps www.fb.com/MahmoudRFarra

Classification of data structure:

Data Structure

StructureLinear

Non-Linear

Memory Allocation

Static

Dynamic

Page 5: 2  introduction to data structure

Linear data structuremfarra.cst.ps www.fb.com/MahmoudRFarra

Linked List

Stack

Queue

Page 6: 2  introduction to data structure

Non-Linear data structuremfarra.cst.ps www.fb.com/MahmoudRFarra

Tree

Graph

Heap

Page 7: 2  introduction to data structure

Static memory allocationmfarra.cst.ps www.fb.com/MahmoudRFarra

Static memory allocation means the program must obtain its space before the execution and can not obtain more while or after execution.

Example: array data structure

Page 8: 2  introduction to data structure

Dynamic memory allocationmfarra.cst.ps www.fb.com/MahmoudRFarra

The dynamic memory allocation is the ability for a program to obtain more memory space at execution time to hold new nodes and to release space no longer needed.

Dynamic data structures as: Array lists, Vectors Linked Lists Stacks, Queues Trees, Heaps

Page 9: 2  introduction to data structure

Applications of data structuremfarra.cst.ps www.fb.com/MahmoudRFarra

Priority Queue: in banks, restaurants, … Hash Tables: in banks for combining two or more

accounts for matching Social Security Numbers. Family Tree Country Map Queue of tasks Order of operations in computer

Page 10: 2  introduction to data structure

Generic programmingmfarra.cst.ps www.fb.com/MahmoudRFarra

Generic programming refers to writing code that will work for many types of data.

Generics let you parameterize types. With this capability, you can define a class or a

method with generic types that the compiler can replace with concrete types.

Page 11: 2  introduction to data structure

Generic programmingmfarra.cst.ps www.fb.com/MahmoudRFarra

For example: Java defines a generic ArrayList class for

storing the elements of a generic type. From this generic class, you can create an

ArrayList object for holding strings and an ArrayList object for holding numbers.

Here, strings and numbers are concrete types that replace the generic type.

Page 12: 2  introduction to data structure

Collectionsmfarra.cst.ps www.fb.com/MahmoudRFarra

A Collection is a data type that is capable of holding a group of items.

The Collection interface defines the common operations for lists, vectors, stacks, queues, priority queues, and sets.

In Java, Collection classes can be implemented as a class, along with methods to add, remove, and examine items.

Think about a bag

Page 13: 2  introduction to data structure

Collection Classesmfarra.cst.ps www.fb.com/MahmoudRFarra

A bag can be put in its initial state, which is an empty bag.

Numbers can be added into the bag. You may check how many occurrences of a

certain number are in the bag. Numbers can be removed from the bag. You can check how many numbers are in the bag.

All the interfaces and classes defined in the Java Collections Framework are grouped in the java.util package.

Page 14: 2  introduction to data structure

Collection Classesmfarra.cst.ps www.fb.com/MahmoudRFarra

Examples

Collection classes in Java

Array List

Stack

Queue

List

Linked List

Heap

Sets store a group of nonduplicate elements. Lists store an ordered collection of elements. Stacks store objects that are processed in a last-in, first-out fashion. Queues store objects that are processed in a first-in, first-out fashion. PriorityQueues store objects that are processed in the order of their

priorities.

Page 15: 2  introduction to data structure

Collection Classesmfarra.cst.ps www.fb.com/MahmoudRFarra

Page 16: 2  introduction to data structure

Collection Testmfarra.cst.ps www.fb.com/MahmoudRFarra

import java.util.*;public class TestCollection {public static void main(String[] args) {ArrayList<String> collection1 = new ArrayList<>();collection1.add("New York");collection1.add("Atlanta");System.out.println("A list of cities in collection1:");System.out.println(collection1);System.out.println("\nIs Dallas in collection1? "+

collection1.contains("Dallas"));collection1.remove("Dallas");System.out.println("\n" + collection1.size() + " cities are in collection1

now");Collection<String> collection2 = new ArrayList<>();collection2.add("Seattle");collection2.add("Portland");System.out.println("\nA list of cities in collection2:");System.out.println(collection2);

Page 17: 2  introduction to data structure

Collection Testmfarra.cst.ps www.fb.com/MahmoudRFarra

The Collection interface contains the methods for manipulating the elements in a collection.

Page 18: 2  introduction to data structure

Big - Oh notation mfarra.cst.ps www.fb.com/MahmoudRFarra

We might be satisfied with evaluating the performance

or complexity of data structures by precisely counting

the number of statements executed or objects

referenced.

We adopt special notation to define upper bounds and lower bounds on functions.

In CS, usually the functions we are bounding are running times, memory requirements.

Page 19: 2  introduction to data structure

Big - Oh notation mfarra.cst.ps www.fb.com/MahmoudRFarra

Page 20: 2  introduction to data structure

using Java

2015

FB: M a h m o u d R F a r r aYouTube: M a h m o u d R F a r SlidesShare: mralfarra

Thank you