0% found this document useful (0 votes)
2 views18 pages

Lecture - 2

ee

Uploaded by

vinayakzutshi1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views18 pages

Lecture - 2

ee

Uploaded by

vinayakzutshi1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

COL106 - Data Structures

and Algorithms
Java Programming Language
● An object-oriented, high-level language with automatic garbage
collection that follows “Write-Once Run Anywhere” (WORA)
paradigm
○ It is not an interpreted language, but is compiled into an intermediate byte-
code – javac
○ Executed over a “virtual machine” that mediates with the underlying
hardware and the byte-code – java
Java Programming Flow
A Simple Java Program
public class Student {
public String name;
public String entryNum;
public Integer batchNum;

public static void main (String[] args) {


System.out.println(“Hello World!”);
}

}
Java – Instantiating Objects
public class Student {
public String name;
public String entryNum;
public Integer batchNum;
public static void main (String[] args) {
System.out.println(“Hello World!”);
st1 = new Student();
st1.name = “Veeru”;
st2 = new Student();
st2.name = “Basanti”;
}
}
Goals of Object-oriented Approach
● Robustness
○ We want software to be capable of handling unexpected inputs that are not
explicitly defined for its application.
● Adaptability
○ Software needs to be able to evolve over time in response to changing
conditions in its environment.
● Reusability
○ The same code should be usable as a component of different systems in
various applications.
Core Ideas of Object-Oriented Approach
● Idea 1 : Abstraction
○ We only need to know ”what” needs to be the behavior, not “how” it is
implemented
○ Abstraction is to distill a system to its most fundamental parts.

● Applying the abstraction paradigm to the design of data structures gives


rise to abstract data types (ADTs).

● Abstract Data Types (ADTs) are mathematical models of a data structure


○ Type of data stored
○ Operations supported on them and the parameters of these operations
● An ADT specifies what each operation does, but not how it does it.
● The collective set of behaviors supported by an ADT is its public interface.
Core Ideas of Object-Oriented Approach
● Idea 2 : Encapsulation
○ Reveal only the necessary information, not the internal details of an object
■ Data as well as behavior
○ It is true of many every-day objects we use

https://www.fastcompany.com/90320298/these- https://thefairyglitchmother.com/car-
https://en.comun.app/blog/como-usar-cajeros- drawing-for-kids-how-to-make-it-easy-peasy/
oddly-satisfying-photos-reveal-the-inner-workings- automaticos-de-manera-segura-consejos-y-
of-everyday-objects trucos
Core Ideas of Object-Oriented Approach
● Idea 3 : Modularity
○ A large software is divided into separate functional units
○ Each unit has a well-defined functionality (abstracted appropriately) so that
different units can be independently be developed against their functional
abstraction

Modular design of an iphone


(from trustedreviews.com)
The Course Structure
● Part I: Data-Structures as Implementations of Different Collection
ADTs
For each Collection type {
○ The Abstract Data Type (ADT) is introduced Detailed lecture
○ Different data-structure implementations are discussed plans are on the
○ Pros-Cons of the ADT and data-structure website
}
● Part II: Algorithms All announcements
For each Algo concept { and updates will be
○ Problem the algo is solving on the course
○ Available approaches and choice of data-structure website.
○ Performance analysis
} Slides will be
uploaded at regular
intervals (typically
once a week)
Abstract Data Type
● The key idea is that a (data)type is characterized by the operations
you can perform on it.

● Number : you can compare, add, subtract etc.


● String: Concatenate and substring
● Boolean is something that you can negate …

● But there is no constraint on how any of these operations have to be


done
Abstract Data Type of Bool
● Bool is an ADT that we would like to build

true: Bool What are the ways in which we can


false: Bool implement Bool?
• A single bit 0 -> false, 1 -> true ?
and: Bool x Bool → Bool
or: Bool x Bool → Bool
not: Bool → Bool
Abstract Data Type of Bool
● Bool is an ADT that we would like to build

true: Bool What are the ways in which we can


false: Bool implement Bool?

and: Bool x Bool → Bool


or: Bool x Bool → Bool
not: Bool → Bool
ADT Operator Classification
● Creator: create new objects of the type.
t : reference to
another object
(could be of
● Producer: create new objects from old objects different type)
of the type
T : reference to
the object of
the ADT we are
working with
ADT Operator Classification
● Observer: take objects of the abstract type and return objects of a
different type.
t : reference to
another object
(could be of
● Mutator: change objects’ state / value. different type)

T : reference to
the object of
the ADT we are
Not all ADTs allow “mutator” operations working with
Mutable and Immutable ADTs
A SimpleString ADT
SimpleString Implementation - 1
SimpleString Implementation - 1

You might also like