Data Structures and Algorithms in Java. Second Year Software Engineering

Similar documents
DATA STRUCTURES CHAPTER 1

About this exam review

Chapter-8 DATA TYPES. Introduction. Variable:

Data Structures and Algorithms in Java

Code No: R Set No. 1

Introduction to Programming Using Java (98-388)

Computer Science II Data Structures

Datatypes, Variables, and Operations

Programming. Syntax and Semantics

Chapter 10. Class & Objects in JAVA. By: Deepak Bhinde PGT Com.Sc.

Algorithms & Data Structures

The smallest element is the first one removed. (You could also define a largest-first-out priority queue)

Values, Variables, Types & Arithmetic Expressions. Agenda

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

ADTs, Arrays, Linked Lists

COMPUTER ORGANIZATION & ARCHITECTURE

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

CSC Java Programming, Fall Java Data Types and Control Constructs

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

Abstract Data Types. Different Views of Data:

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Chapter 4 Loops. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

CMPT 125: Lecture 3 Data and Expressions

Programming II (CS300)

JAVA OPERATORS GENERAL

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Object-Oriented Programming Concepts

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

3. Simple Types, Variables, and Constants

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java

Binghamton University. CS-140 Fall Data Types in Java

CompuScholar, Inc. Alignment to Nevada "Computer Science" Course Standards

Searching & Sorting in Java Shell Sort

VALLIAMMAI ENGINEERING COLLEGE

UNIT-4 (COMPILER DESIGN)

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Chapter 3: Operators, Expressions and Type Conversion

CMPSCI 250: Introduction to Computation. Lecture #14: Induction and Recursion (Still More Induction) David Mix Barrington 14 March 2013

CS2102, B11 Exam 1. Name:

Chapter 9 Introduction to Arrays. Fundamentals of Java

TOPICS TO COVER:-- Array declaration and use.

CSE 230 Computer Science II (Data Structure) Introduction

Data types Expressions Variables Assignment. COMP1400 Week 2

[ DATA STRUCTURES] to Data Structures

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

CS 231 Data Structures and Algorithms, Fall 2016

JAVA MOCK TEST JAVA MOCK TEST II

Programming II (CS300)

ISA 563 : Fundamentals of Systems Programming

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

VARIABLES AND TYPES CITS1001

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

Chapter 8: Data Abstractions

StudyHub+ 1. StudyHub: AP Java. Semester One Final Review

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Programming in OOP/C++

CS 206 Introduction to Computer Science II

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012

Basic data types. Building blocks of computation

C# MOCK TEST C# MOCK TEST I

Short Notes of CS201

Programming with Java

Computer Science 210: Data Structures

Chapter 1 Getting Started

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages

Data Types Literals, Variables & Constants

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Software Systems Development Unit AS1: Introduction to Object Oriented Development

Introduction to Computer Science Midterm 3 Fall, Points

COE318 Lecture Notes Week 4 (Sept 26, 2011)

CS201 - Introduction to Programming Glossary By

C# and Java. C# and Java are both modern object-oriented languages

An Informal Introduction to MemCom

Name: After line 1: After line 3: After line 5: After line 8: After line 11:

Introducing Hashing. Chapter 21. Copyright 2012 by Pearson Education, Inc. All rights reserved

Procedural programming with C

JAVA GUI PROGRAMMING REVISION TOUR III

ESc101 : Fundamental of Computing

Week 6. Data structures

JAVA WRAPPER CLASSES

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Motivation was to facilitate development of systems software, especially OS development.

Data Structure. Recitation III

1007 Imperative Programming Part II

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Reg. No. : Question Paper Code : 27157

ECE 122. Engineering Problem Solving with Java

DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N.

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT. Object Oriented Programming

Operators and Expressions

Objectives of CS 230. Java portability. Why ADTs? 8/18/14

Software Practice 1 Basic Grammar

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Transcription:

Data Structures and Algorithms in Java Second Year Software Engineering

Introduction Computer: is a programmable machine that can store, retrieve and process data. Data: The representation of information in a manner suitable for communication or analysis by humans or machines. Data is classified into data types. e.g. char, float, int, etc. Data type: is a domain of allowed values and a set of operations on these values. Data Type Domain Operations boolean True, False &&,, =, etc. char ASCII =, >, <, etc. byte -2 7 to +2 7-1 +, -, =, = =,!, <, etc. short -2 15 to +2 15-1 +, -, =, = =,!, <, etc. 2

Data Types What is the output of the following code? Why? byte b=128; System.out.println( +b); Primitive data types: these data types also known as simple or atomic types, in which elements are single, non-decomposable data items. Primitive data types for representing basic information ( int age, double balance). Java primitive data types are: boolean, char, byte, short, int, long, float and double. 3

Data Types Cont. More complex structure can be constructed by combining primitive data types. A point in x-y plane by two integers. A list of scores for students on an assignment. Composite type(non-primitive): a data type whose elements are composed of multiple data items. Primitive types are partially defined by describing their domain of values, while composite types are partially defined by the relationship among their constituent values. Primitive types are defined by describing permitted operations, while composite types, the main operation of interest is accessing the elements. 4

Data Types Cont. Typically, there are structured and unstructured composite types. A structured data type is one in which the components are organized with respect to each other. The organization determines the method used to access individual components. An array is a structured data type whose components are accessed by their position. An unstructured data type is one in which the components are not organized with respect to each other. Classes and interfaces are examples of unstructured data type. 5

Data Types Cont. Non-primitive data types also known as objects, they can be constructed in Java language by a mechanism which is called reference variable, since they reference a memory location. From a defined class new object is created by new operator and returns a reference to that object. A new object of a certain type must be created by using of the new operator followed by a constructor for that type of object. A constructor is a special kind of method that is used to initialize newly created objects. 6

Data Types Cont. Point p; // declare the variable p to be of type of Point. p=new Point (); //create a new Point object and returns a reference to it, then then assigns the reference to the new object to the variable p. Number classes in Java provide to store numbers as objects. Byte b=new Byte(8); Short s=10; A sequence of characters forms a String object. String s=new String( Data Structure ); String s= Data Structure ; The use of new operator to: Allocate the object s memory space. Using the object's constructor to initialize this space. Assign the address of this space to reference variable. 7

Data Types Cont. Reference variable can be viewed as a pointer to some object. The reference variable like a holder for a remote control, and contains the object reference. 8

Data Types Cont. class TV { } int Brightness; int Contrast; int Color; // The Default Constructor of the TV Object TV() { } Brightness=0; Contrast=0; Color=0; Many references can point to the same object. i.e. many remote controls work on the same device. TV remote1=new TV(); TV remote2=remote1; //declare the variable remote2 to be of type of TV, then assigns remote2 to reference the same object as remote1. 9

Data Types Cont. Dot operator (".") is used to access and/or change the state of object. Changing the state of object by one object reference variable, the state changes to all references to it. System.out.println(""+remote1.Color); // 0 System.out.println(""+remote2.Color); // 0 remote1.color=10; System.out.println(""+remote1.Color); // 10 System.out.println(""+remote2.Color); // 0 or 10? remote2.color=25; System.out.println(""+remote2.Color); // 25 System.out.println(""+remote1.Color); // 10 or 25? 10

Concepts of Data Structure In a general sense, any data representation is a data structure. Example: An integer. More typically, a data structure is meant to be an organization for a collection of data items. Data structures include arrays, linked lists, stacks, binary trees, etc. Any organization for a collection of records can be manipulated by algorithms in various ways. The choice of data structure and algorithm can make the difference between a program running in a few seconds or many days. Rarely is one data structure better than another in all situations. 11

Data Structure Selection and Requirements 1. Analyze the problem to determine the resource constraints a solution must meet. 2. Determine the basic operations that must be supported. 3. Select the data structure that best meets these requirements. A data structure requires: n n n space for each data item it stores. time to perform each basic operation. programming effort. 12

Data Structures and Algorithms Usability Data structures and algorithms are good for real-world data storage, programmer s tools and modeling. In real world data storage, suppose you want to create a computer program for an index-card then: How would you store the data in your computer s memory? Would your method works for a hundred file cards? A thousand? A million? Would your method permit quick insertion of new cards and deletion of old ones? Would it allow for fast searching for a specified card? Suppose you wanted to arrange the cards in alphabetical order. How would you sort them? Some times data storage structures are accessed by program itself. 13

Data Structures and Algorithms Usability Cont. Programmer uses such structures as tools to facilitate some other operation. Stacks, queues, and priority queues are often used in this way. The graph is the most important data structure that is used in real world modeling. Airline routes representation between cities. 14

Data Structures and Algorithms Usability Cont. Tasks in a project. Connections in an electric circuit. 15

Data Structure Classification 16

Characteristics of Data Structures Data Structure Avantages Disadvantages Array Ordered array Quick insertion, very fast access if index known. Quicker search than unsorted array. Slow search, slow deletion, fixed size. Slow insertion and deletion, fixed size. Stack Provides last-in, first-out access. Slow access to other items. Queue Provides first-in, first-out access. Slow access to other items. Linked list Binary tree Quick insertion, quick deletion. Quick search, insertion, deletion (if tree remains balanced). Slow search. Deletion algorithm is complex. 17

Algorithms Problem: is a task to be performed Algorithm: is a way or a method in which the problem is solved. The algorithm gives us a recipe for solving the problem by performing a series of steps, where each step is completely understood and doable. Many algorithms can be used for solving a specific problem, i.e. the problem of sorting can be solved by many algorithms such as: Insertion sort Bubble sort Selection sort Shellsort Mergesort Others 18

Example Problem: find y = x to the power of 2 üalgorithm1: Multiply X by X üalgorithm2: add X to itself, X times ØProgram1: y=x*x; ØProgram1: for (int i = 0; i<x; i++) y +=x; Which one is better? Why? 19

Algorithm Properties An algorithm possesses the following properties: It must be correct. It must be composed of a series of concrete steps. There can be no ambiguity as to which step will be performed next. It must be composed of a finite number of steps. It must be terminated. 20

To Summarize: Data Structure is a particular way of storing and organizing data in a computer. So that it can be used efficiently. An algorithm is a recipe for solving a problem whose steps are concrete and clear. A program is an instantiation of an algorithm in a computer programming language. 21

22