C+ fundamentals
A bit of history
The first OO language was Simula 67
Developed in the 1960s at the Norwegian Computing
Center in Oslo
Introduced objects, classes, inheritance, virtual
methods, garbage collection etc.
Designed to perform simulations
T
Chapter 8:
Class Relationships
Inheritance Revisited
Inheritance
A relationship among classes
Allows a class to derive the behavior and
structure of an existing class
2
Inheritance Revisited
Figure 8-1 Inheritance: Relationships among timepieces
3
I
332:351 Programming Methodology-II
Prof. Shantenu Jha
Office: 705 CoRE Building
Office Hours: Thu 13:00
shantenu.jha at rutgers dot edu
TA: Antons Trekalis
Office Hours: TBD
Grader: Srikanth Vishwanath
Sakai: Search for PM-II
Welcome to PM-II
What this c
Organizing Data:
The Towers of Hanoi
Figure 2-19a and b (a) The initial state; (b) move n - 1 disks from A to C
1
The Towers of Hanoi
Figure 2-19c and d (c) move one disk from A to B; (d) move n - 1 disks from C to B
2
The Towers of Hanoi
Pseudocode solu
Chapter 9:
Algorithm Efficiency and Sorting
Measuring the Efficiency of
Algorithms
Analysis of algorithms
Provides tools for contrasting the efciency of
different methods of solution
Time efciency, space efciency
Focus is on time efciency
A compa
Algebraic Expressions
Inx expressions
An operator appears between its operands
Example: a + b
Prex expressions
An operator appears before its operands
Example: + a b
Postx expressions
An operator appears after its operands
Example: a b +
Variations: Doubly Linked Lists
Each node points to both its predecessor and
its successor
precede pointer and next pointer
Contrast with cur & prev
Insertions/deletions more involved than for a
singly linked list
Often has a dummy head node
Oft
Chapter 3:
Data Abstraction: The Walls
Abstract Data Types
Modularity
Keeps the complexity of a large program
manageable by systematically controlling the
interaction of its components
Isolates errors
Eliminates redundancies
2
Abstract Data Types
Chapter 7:
Queues
The Abstract Data Type Queue
A queue
New items enter at the back, or rear, of the queue
Items leave from the front of the queue
First-in, rst-out (FIFO) property
The rst item inserted into a queue is the rst item to
leave
2
T
Applying the UML to OOA/D
Each object is represented as a box containing its name followed by a
colon and its type, all underlined.
Each object has a lifeline denoted by a vertical dashed line.
Each lifeline can have one or more activations bars (ope
Chapter 11:
Tables and Priority Queues
The ADT Table
Example of a value-oriented table
The ADT table, or dictionary
Uses a search key to identify its items
Its items are records that contain several pieces
of data
Look up information quickly
Fig
Algorithm Efficiency
What is a good solution?
Criterion
A solution is good if the total cost it incurs
over all phases of its life is minimal.
Keep in mind, efficiency is only one
aspect of a solutions cost
Note: Relative importance of various
componen
Sorting Algorithms
and their Efficiency
Chapter 11
Contents
Basic Sorting Algorithms
Faster Sorting Algorithms
A Comparison of Sorting Algorithms
Basic Sorting Algorithms
Sorting is:
A process
It organizes a collection of data
Organized into ascend
Sorted Lists and Their
Implementations
Chapter 12
Contents
Specifying the ADT Sorted List
Link-Based Implementation
Implementations That Use the
ADT List
Specifying the ADT Sorted List
The ADT sorted list maintains its
entries in sorted order.
It is
Recursion: The Mirrors
Chapters 2 and 5
Contents
Recursive Solutions
Recursion That Returns a Value
Recursion That Performs an Action
Recursion with Arrays
Organizing Data
More Examples
Recursion and Efficiency
Recursive Solutions
Recursion breaks a prob
Link Based Implementations
Chapter 4
Preliminaries
Options for implementing an ADT List
Array has a xed size
Data must be shifted during insertions and deletions
Linked list is able to grow in size as needed
Does not require the shifting of items dur
Lists
Chapter 8,9
Contents
Specifying the ADT List
Using the List Operations
An Interface Template for the ADT List
Specifying the ADT List
You reference list
items by their
position
FIGURE 8-1 A grocery list
ADT List Operations
Test whether a list is
Multiplying Rabbits
(The Fibonacci Sequence)
Facts about rabbits
Rabbits never die
A rabbit reaches sexual maturity exactly two
months after birth, that is, at the beginning of its
third month of life
Rabbits are always born in male-female pairs. A
Implementing ADTs
Figure 3-8
ADT operations provide access to a data structure
1
Implementing ADTs
Figure 3-9 Violating the wall of ADT operations
2
Why is jumping the Wall undesirable?
i.e., accessing the data structure directly
Options for implementin
Chapter 9:
Algorithm Efficiency and Sorting
Mergesort
A recursive sorting algorithm
Performance is independent of the initial order
of the array items
Strategy
Divide an array into halves
Sort each half
Merge the sorted halves into one sorted a
The ADT Binary Tree
Figure 10-9
UML diagram for the class
BinaryTree
1
The ADT Binary Tree
Building the ADT binary tree in Fig. 10-6b
tree1.setRootData(F)
tree1.attachLeft(G)
tree2.setRootData(D)
tree2.attachLeftSubtree(tree1)
tree3.setRootData(B)
tree3.
Inserting a Node into a Specified
Position of a Linked List
To insert a node between two nodes
newPtr->next = cur;
prev->next = newPtr;
Figure 4-12
Inserting a new node into a linked list
1
Inserting a Node into a Specified
Position of a Linked List
T
The ADT List Revisited
Operation Contract for the ADT List
createList()
destroyList()
isEmpty():boolean cfw_query
getLength():integer cfw_query
insert(in index:integer, in newItem:ListItemType,
out success:boolean)
remove(in index:integer, out succ
Variations: Dummy Head Nodes
Dummy head node
Always present, even when the linked list is
empty
Insertion and deletion algorithms initialize prev
to point to the dummy head node, rather than to
NULL
Eliminates special case
Figure 4-27 A dummy head
Organizing Data:
The Towers of Hanoi
Figure 2-19a and b (a) The initial state; (b) move n - 1 disks from A to C
1
The Towers of Hanoi
Figure 2-19c and d (c) move one disk from A to B; (d) move n - 1 disks from C to B
2
The Towers of Hanoi
Pseudocode solu
The Software Life Cycle
Describes the phases of software development
from conception to deployment to replacement to
deletion
Examine the phases from project conception to
deployment to end users
Beyond this development process, software needs
mainte
332:351 Programming Methodology-II
Prof. Shantenu Jha
Office: 627 CoRE Building
Office Hours: M 14:00, Tu 13:00
shantenu.jha at rutgers dot edu
TA: Parul Pandey
Tu, Wed 14:00-15:00
[email protected]
Sakai: Search for PM-II
Welcome to PM-II
What th
Multiplying Rabbits
(The Fibonacci Sequence)
Facts about rabbits
Rabbits never die
A rabbit reaches sexual maturity exactly two
months after birth, that is, at the beginning of its
third month of life
Rabbits are always born in male-female pairs. A