Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

CSC 204 ASSIGNMENT 20/08/05/123

Write short notes on the following


1. Data representation in memory
2. Run time storage management
3. Records and strings

DATA REPRESENTATION IN MEMORY


The term data structure is used to denote a particular way of organizing data for particular types
of operation. We can do this by formulating abstract mathematical models of particular classes of
data structures or data types which have common features. These are called abstract data types.
Data structures are classified as either linear or nonlinear.
1. linear: A data structure is said to be linear if its elements form a sequence, or a linear list.
There are two basic ways of representing such linear structures in memory. One way is to
have the linear relationship between the elements represented by means of sequential
memory locations. These linear structures are called arrays. The other way is to have the
linear relationship between the elements represented by means of pointers or links. These
linear structures are called linked lists.
The following operations may be performed on any linear structure.
i. Arrays ii. Lists iii. Recursion iv. Stacks v. Queues

i. Arrays: Array items are typically stored in a sequence of computer memory locations,
which can be write the items in order, separated by commas and enclosed by square
brackets. Thus, a=[1 , 4 , 17 , 3 , 90 ,79 , 4 , 6 , 81]. This array a has 9 items, and hence we
say that its size is 9. for our array a , its positions are0 , 1 ,2 , . .. , 7 , 8. The element in the
8th position is 81, and we use the notation a [8] to denote this element.
Consider LA be a linear array in the memory of the computer. As we know that the
memory of the computer is simply a sequence of addressed location as given in

ii. Lists: A linked list, or one-way list, is a linear collection of data elements, called nodes,
where the linear order is given by means of pointers. That is, each node is divided into
two parts: the first part contains the information of the element, and the second part,
called the link field or next pointer field, contains the address of the next node in the list
A list can involve virtually anything, for example, a list of integers [3,2,4,2,5], a
shopping list [apples, butter, bread, cheese], When considering lists, we can speak
20/08/05/123

about-them on different levels - on a very abstract level, on a level on which we can


depict lists and communicate as humans about them.
Let LIST be a linked list. Then LIST will be maintained in memory as follows. First of
all, LIST requires two linear arrays-we will call them here INFO and LINK - such that
INFO[K] and LINK[K] contain the information part and the next pointer field of a node
of LIST respectively. START contains the location of the beginning of the list, and a
next pointer sentinel-denoted by NULL-which indicates the end of the list.

iii. Recursion: We previously saw how iteration based on for-loops was a natural way to
process collections of items stored in arrays. When items are stored as linked-lists, there
is no index for each item, and recursion provides the natural way to process them. The
idea is to formulate procedures which involve at least one step that invokes (or calls)
the procedure itself.
iv. Stacks: Stacks are, on an abstract level, equivalent to linked lists. They are the ideal
data structure to model a First-In-Last-Out (FILO), or Last-In-First-Out (LIFO),
strategy in search.
Graphical Representation
Their relation to linked lists means that their graphical representation can be the same,
but one has to be careful about the order of the items. For instance, the stack created by
inserting the numbers [3,1,4,2,5] in that order would be represented as:

v. Queues: A queue is a data structure used to model a First-In-First-Out (FIFO) strategy.


Conceptually, we add to the end of a queue and take away elements from its front.
Graphical Representation

2
20/08/05/12

2. In a non-linear structure, each element may have one or more predecessors and successors,
and there may be multiple paths to reach a specific element. Because of their complex
organization, it is not possible to traverse all the elements in a single run. Examples of non-
linear structures are trees and graphs.
i. Trees: a tree can be defined as either the empty tree, or a node with a list of successor
trees. Nodes are usually, though not always, labelled with a data item (such as a number
or search key). We will refer to the label of a node as its value.
8

3 1

1 6 9 1

7 1 1 1
Types of Threes
i. Quad-trees: is a particular type of tree in which each leaf-node is labelled by
a value and each non-leaf node has exactly four children. It is used most
often to partition a two dimensional by recursively dividing it into four
quadrants.
ii. Binary trees: nary trees are the most common type of tree used in computer
science. A binary tree is a tree in which every node has at most two children,
and can be defined “inductively” by the following rules: Definition.
ii. Graphs: Graphs Often it is useful to represent information in a more general graphical
form than considered so far, such as the following representation of the distances
between towns. A graph G may be defined as a finite set V of vertices and a set E of
edges (pair of connected vertices). The notation used is as follows: Graph G = (V,E) Let
we consider graph of

Different types of data (e.g., integers, floating-point numbers, characters) are stored and
processed in memory using specific data types. These data types define the size and format of the
data, ensuring proper representation and manipulation. Common data types include:
1. Integers: Used for whole numbers and typically come in various sizes (e.g., int32, int64).
2. Floating-Point: Used for real numbers with decimal points, like 3.14 or 2.71828.
3. Characters: Used for representing text and symbols.
Conclusion
Data representation in memory is a fundamental aspect of computer science and plays a vital role
in how computers store and process information. It involves encoding data into binary form,
organizing memory units, specifying data types, and considering endianness. A solid
understanding of these concepts is essential for programmers and computer scientists working
with low-level programming, data structures, and computer architecture.

3
20/08/05/123

RUN-TIME STORAGE MANAGEMENT


Information needed during an execution of a procedure is kept in a block of storage called an
activation record, which includes storage for names local to the procedure. The two standard
storage allocation strategies are:
1. Static allocation 2. Dynamic allocation

1. Static allocation • In this allocation scheme, the compilation data is bound to a fixed
location in the memory and it does not change when the program executes. As the
memory requirement and storage locations are known in advance, runtime support
package for memory allocation and de-allocation is not required. In a static storage-
allocation strategy, it is necessary to be able to decide at compile time exactly where each
data object will reside at run time. In order to make such a decision, at least two criteria
must be met:
i. The size of each object must be known at compile time.
ii. Only one occurrence of each object is allowable at a given moment during program
execution.

Because of the first criterion, variable-length strings are disallowed, since their length
cannot be established at compile time. Similarly dynamic arrays are disallowed, since
their bounds are not known at compile time and hence the size of the data object is
unknown. Because of the second criterion, nested procedures are not possible in a static
storage-allocation scheme. This is the case because it is not known at compile time which
or how many nested procedures, and hence their local variables, will be active at
execution time.
2. Dynamic Allocation: The allocation can be varied during the execution and It makes the
use of recursive function. In a dynamic storage-allocation strategy, the data area
requirements for a program are not known entirely at compilation time.  In particular,
the two criteria that were given in the previous section as necessary for static storage

4
20/08/05/12

allocation do not apply for a dynamic storage-allocation scheme. The size and number of
each object need not be known at compile time; however, they must be known at run time
when a block is entered. Similarly more than one occurrence of a data object is allowed,
provided that each new occurrence is initiated at run time when a block is entered. Key
concepts related to dynamic memory allocation include:
i. Heap Memory: In many programming languages, dynamic memory is allocated
from a region of memory called the "heap." The heap is a pool of memory that
can be used for storing data structures of varying sizes during program execution.
ii. Allocation and Deallocation: During program execution, memory can be allocated
using functions like `malloc`, `calloc’. It is essential to release memory when it is
no longer needed, typically done with functions like `free` or `delete`. Failure to
deallocate memory can lead to memory leaks.
iii. Fragmentation: Fragmentation can occur in the heap when memory is allocated
and deallocated in an inefficient manner. Two main types of fragmentation exist:
external fragmentation, which involves free memory blocks that are not
contiguous, and internal fragmentation, where memory within allocated blocks is unused.

The following three-address statements are associated with the run-time allocation and de
allocation of activation records:
1. Call, 2. Return, 3. Halt, 4. Action, a placeholder for other
statements.

RECORDS AND STRINGS


Records
a record is a collection of related data items, each of which is called a field or attribute, and
a file is a collection of similar records. Each data item itself may be a group item composed
of sub items; those items which are indecomposable are called elementary items or atoms or
scalars. The names given to the various data items are called identifiers.
As we know that a record is a collection of data items, it differs from a linear array in
the following way,
a) A record may be a collection of non-homogeneous data; i.e., the data items in
a record may have different data types.
b) The data items in a record are indexed by attribute names, so there may not
be a natural ordering of its elements.
Under the relationship of group item to sub item, the data items in a record form a
hierarchical structure which can be described by means of "level" numbers.

The number to the left of each identifier is


called a level number. Observe that each

5
20/08/05/123

group item is followed by its sub items, and the level of the sub items is 1 more than
the level of the group item. Furthermore, an item is a group if and only if it is
immediately followed by an item with a greater level number.
Some of the identifiers in a record structure may also refer to arrays of elements. In
fact, the first line of the above structure is replaced by
1 Newborn(20)
This will indicate a file of 20 records, and the usual subscript notation will be used to
distinguish between different records in the file. That is, we will write to
Newborn[1], Newborn[2], Newborn[3],. . .
to denote different records in the file.

Strings
A string is a sequence of characters. In Programming, strings start and end with single or double
quotes (they are equivalent but they have to match).
>>> s = "foo"
>>> print s
foo
>>> s = 'Foo'
>>> print s
Foo
>>> s = "foo'
SyntaxError: EOL while scanning string literal
Each string is stored in the computer’s memory as a list (array) of characters.
>>> myString = "GATTACA"
Accessing single characters
>>> myString = "GATTACA"
>>> myString[0]
'G'

Conclusion: Records and strings are indispensable data structures in computer science and
programming. Records allow for the organization of structured data, while strings facilitate the
manipulation and representation of textual data. Understanding how to work with these data

6
20/08/05/12

structures is fundamental to building software applications that handle and process diverse types
of information.

You might also like