Вы находитесь на странице: 1из 16

Data Structures

Lecture By
Dr. V. Srinivasa Rao
M. Tech . Ph .D

1
Organization of Data Structures

2
Objective of Data Structures is a
ways of efficiently organizing and
manipulating data in main memory.

In File structures , equivalent


techniques for organization and
manipulation of data in secondary
storage.

3
4
Applications

• arithmetic expression evaluation

• data compression (Huffman coding)

• image segmentation, image compression

• backtrack searching

• finding the best path to route in a network

• geometric problems (e.g. rectangle area)


5
Index generation for a document
Index contains the list of all the words appearing in a
document, with the line numbers in which they appear.

Typical index for a book looks:

Data structure binary search tree, hash table 6


 Spelling checker

 Given a text file T, identify all the misspelled words in


T.

Idea: build a hash table H of all the words in a dictionary,


and search for each word of the text T in the table H.
For each misspelled word, suggest the correct
spelling.
(hashing, strings, vectors)

7
DEFINITION

A Computer stores information in a way best suited


to conserve the memory space and provide for
easy access or recall. The arrangement used for
storing information depends upon processing.
The methods to store information in the
computer collectively called data structures.

(or)
Execution of a program on a computer requires data
that is stored at memory locations. It is often
useful to arrange these locations in a
convenient manner. Such arrangement is called a
data structure.
8
The Data Structures are primarily of two types

9
Abstract vs. concrete data structures

 Abstract data structure (sometimes called ADT ->


Abstract Data Type) is a collection of data with a set of
operations supported to manipulate the structure
 Examples:
• stack, queue insert, delete
• priority queue insert, deleteMin
• Dictionary insert, search, delete
 Concrete data structures are the implementations of
abstract data structures:
• Arrays, linked lists, trees, heaps, hash table
 A recurring theme: Find the best mapping between
abstract and concrete data structures.
10
Definition

A STACK is a ordered collection of items in to


which new times may be inserted and from which items
may be deleted at one end called the TOP of the
STACK. The definition of the STACK provides insertion
and deletion of item, so that a STACK is really
dynamic constantly changing object.

A data structure in which elements are added


and removed from only one end; a “ last in , first out ”
(LIFO) structure.

11
Some Stack Applications
• Implementing recursive call
• Expression evaluation
– Infix to postfix
– Postfix evaluation
• Maze problem
• Breadth First Search

12
an application of stack: stack frame of function call

fp: a pointer to current stack frame old frame pointer fp


return address
al

local variables
fp old frame pointer

main return address

system stack before a1 is invoked system stack after a1 is invoked


(a) (b)

13
Applications of Stacks
• Direct applications
– Page-visited history in a Web browser
– Undo sequence in a text editor
– Chain of method calls in the Java Virtual Machine
– Validate XML
• Indirect applications
– Auxiliary data structure for algorithms
– Component of other data structures

14
Problems that Use Stacks
 The runtime stack used by a
process (running program)
to keep track of methods in
progress
 Search problems
 Undo, redo, back, forward

15
Method Stack in the JVM
• The Java Virtual Machine (JVM) main() {
keeps track of the chain of active
int i = 5;
methods with a stack
foo(i); bar
• When a method is called, the JVM
} PC = 1
pushes on the stack a frame
m=6
containing foo(int j) {
– Local variables and return value int k; foo
– Program counter, keeping track of
the statement being executed
k = j+1; PC = 3
bar(k); j=5
• When a method ends, its frame is k=6
popped from the stack and control }
is passed to the method on top of bar(int m) { main
the stack … PC = 2
• Allows for recursion } i=5

16

Вам также может понравиться