You are on page 1of 15

Data Structure

Introduction to Data Structures


A data structure is a scheme for organizing data in the memory of a
computer.
Some of the more commonly used data structures include lists,
arrays, stacks, queues, trees, and graphs.
Computer programmers decide which data structures to use based
on the nature of the data and the processes that need to be
performed on that data.
Example: A
Queue
A queue is an example of commonly used simple data structure.
A queue has beginning and end, called the front and back of the
queue.

03/16/24
Data Structures

There are two built-in data structures that can be used to organize
data, or to create other data structures:
 Lists
 Arrays
Arrays and Lists
A list is an ordered set of data. It is often used to store objects that
are to be processed sequentially.

• A list can be used to create a


queue.
• An array is an indexed set of
variables, such as dancer[1],
dancer[2], dancer[3],… It is like a
set of boxes that hold things.
• A list is a set of items.
• An array is a set of variables that
each store an item.
Arrays and Lists

You can see the difference between arrays and lists when you
delete items.
In a list, the missing spot is filled in when something is deleted.
In an array, an empty variable is left behind when something is
deleted.
Record
In computer science, a record (also called struct or compound
data) is a basic data structure.
A record is a collection of fields, possibly of different data types,
typically in fixed number and sequence. The fields of a record
may also be called members, particularly in object-oriented
programming. Fields may also be called elements.

•e.g. student record

03/16/24
Linked List
In computer science, a linked list is a linear collection of data
elements, called nodes, each pointing to the next node by means of
a pointer. It is a data structure consisting of a group of nodes which
together represent a sequence. Under the simplest form, each node
is composed of data and a reference (in other words, a link) to the
next node in the sequence. This structure allows for efficient
insertion or removal of elements from any position in the sequence
during iteration. More complex variants add additional links, allowing
efficient insertion or removal from arbitrary element references.

03/16/24
Memory Representation of Linear Linked List

Let LIST is linear linked list. It needs two linear arrays for memory
representation. Let these linear arrays are INFO and LINK. INFO[K]
contains the information part and LINK[K] contains the next pointer
field of node K. A variable START is used to store the location of the
beginning of the LIST and NULL is used as next pointer which
indicates the end of LIST. It is shown below:

03/16/24
Memory Representation of Linear Linked List

03/16/24
Binary Tree

In computer science, a binary tree is a tree data structure in which


each node has at most two children, which are referred to as the left
child and the right child. A recursive definition is that a (non-empty)
binary tree is a triple (L, S, R), where L and R are binary trees or the
empty set and S is a singleton set. Some authors allow the binary tree
to be the empty set as well.

03/16/24
Representation of Binary Tree in Memory

Let T is Binary
There are two ways of representing binary tree in memory

Sequential representation
Linked representation

Sequential Representation.
Suppose T is a complete binary tree. Then only single linear array TREE
is used as follows.

03/16/24
Representation of Binary Tree in Memory
 The root R is stored in TREE[0].
 If a node n occupies TREE[K],
 then its left child in TREE[2*K]
 & right child TREE [2*K+1].
 If TREE[1]=NULL then it is empty tree.

03/16/24
Linked Representation

The linked representation uses three parallel arrays,INFO,LEFT &


RIGHT & a pointer variable ROOT.Each node N of Y will correspond
to a location K such that:

• 1) INFO[K] contains the data at node N.

• 2) LEFT[K] contains the location of left child of node N.

• 3) RIGHT[K] contains the location of right child of node N.

• ROOT will contain location of root R of T.

03/16/24
Linked Representation

A sample representation is shown in fig.

03/16/24
Any Query

03/16/24

You might also like