Sunteți pe pagina 1din 9

1 Raj Kamal: Mobile Computing (2/e)

Chapter 7: Databases
Question Bank

Q1. Discuss how data is organised as file. Give an example.

Data can be organized in the following forms:


MemoPad
File
Files in a folder
Folder in a subdirectory or directory.

A File has records and file-data descriptor. Whenever data is required for computation, the records in the file can be used
by software.

Files are stored in the device memory or in the media card. Device memory is the internal flash memory which holds
persistent data. Persistent data is the non-volatile (permanently stored) data. Media card is a micro SD card which is
stacked in the mobile. An additional card can be stacked when the original cards memory is full.

Consider a directory Applications in a Mobile. Applications directory has subdirectory MemPad for the text files.
MemPad has folders CarPetrolRecord, GasConnectionRecord, BuyList and BirthdayPartyInviteeList.

Page references:
File: Pages 306 and 307

Q2. (a) How are data organised in structured formats?


(b) Give an example of a data structure.

Computations require data which can also be organized in the following forms:
(i) Data structure,
(ii) Database, and
(iii) Object.

A data structure provides simplicity and non-redundancy. (Non-redundancy means that the same information is not placed
again, either in the same form or in some other form). There are many types of data structures. Examples include queues,
buffers, arrays, trees, lists, heap and tables. A data structure can also be defined in a program. Example 7.2 explains this in
detail.

Example of Data Structure

A data structure trainSchedule, which encapsulates information about which train schedule in C as follows:

typedefstruct{
char[]trainName,trainStation,trainOrigin,trainDestination;
unsignedint[]arrivalTimehr,arrivalTimemin,depTimehr,depTimemin;
}trainSchedule;

trainScheduledelhi_bombay_train; /*delhi_bombay_trainisadataoftype
trainSchedule*/
delhi_bombay_train.trainName=FrontierMail;/*AssignmentofTrainnameusing
statement*/

Page reference:
Data Structure: Page 307

OXFORD H i g h e r Education
Oxford University Press, 2012. All rights reserved.
1 Raj Kamal: Mobile Computing (2/e)
Chapter 7: Databases
Question Bank

Q3. How are data organised in database format?

Data can be structured as database. A database is a collection of systematically stored records or information. A database
is considered as an organized collection of data where the records are saved according to a specific model. A database is
not just arbitrarily stored data without any logic. Indeed, databases store data in a particular logical manner.

For example, consider contact data (with fields such as name, work-place phone number, fax number, mobile number, and
address). The contact data of a number of people and companies can be organized as a database named Contacts.

Section 7.1.1 gives the database concept in detail.


.
Page reference:
Database: Page 308

Q4.
(a) What is the advantage of using a database?

(b) Give examples of logical structures according to which data can be recorded in databases?

(c) What are the transactions carried between the API and databases?

(d) Give the sample XML code StuAttendances for maintaining the database of records of attendances of
students in a class of 20 students in subject Java.

(e) Give examples of the transactions with an API.

Advantage of a database
A database advantage is that it is a collection of systematically stored records or information. It has stored data with
logic. Computations require data. It is better to organise this data in a database which enables raising queries due to
storage using the logic. Computations can perform data transactions. Computations can retrieve the required section of
data.
_______________________________________________________________________________________________
Example
Consider contact data (with fields such as name, work place phone number, fax number, mobile number, and address).
The contact data of a number of peoples and companies can be organized in a database Contacts. Contacts during
computing and the required information, such as a select mobile number, can be retrieved.

Using an API (Application Program Interface) the queries can be raised to the database. For example, a query from the
API to the Contacts can be to get a list of 5 contact names along with their phone numbers starting. The list is in an
alphabetical ascending order. First character of first name in the list = A.

Transactions can be carried out with the database Contacts for modifications or additions to the information stored in it,
such as a transaction to modify a select mobile number.
_______________________________________________________________________________________________

OXFORD H i g h e r Education
Oxford University Press, 2012. All rights reserved.
1 Raj Kamal: Mobile Computing (2/e)
Chapter 7: Databases
Question Bank
Logical Structures in Databases
Databases store data in a particular logical manner, for example, as lookup table. A lookup table is a database which
stores a table. The table has the following structurethe first column in a row has a reference for looking into the data
and the subsequent column or columns contain the data in the row. The reference is called key to the data-values.

Another logical structure is a database which stores data using tags. The tag is also known as the key to the data-values.
For example, contact: 1 John, 2 Lucy. and address: 1 ABC Street, 2 DEF Street. Here contact and address are the
tags in the database. Using these tags during computation the data for Johns address can be fetched.

Transaction

The computational actions such as connecting to a database and using the database for querying for a record, deleting
a specific set of records, modifications of records, insertions into the record and appending the records may be
considered as an act of business ( transactions ) between the application software and database. The command which is
sent for retrieving the data from the database, embodies the logic used for obtaining (and storing) the data.

Sample code for maintaining the database of records of attendances of students in a class of 20 students in
subject Java
The sample code is a database StuAtetendences designed in XML. Let us use javaStuAttendance, year,
semester, month, class, subject, serial_number, roll_number, name, month_attendance, total_semAttendence
and totalAttribute as the tags. The tags and attributes function as primary and secondary keys for the given
XML database. Let us use attribute roll number with the tag <serial_number>.

<javaStuAttendence subject = Java year = 2010, class = M.Sc. Semester = 2>


<serial_number > 1 <roll_number> 20100601 <name> Abhinav
<total_attendance>
<month> January <month_attendance> 92 </month_attendence> </month>
<month> February <month_attendance> 86 </month_attendence> </month>
<month> March <month_attendance> 98 </month_attendence> </month>
92
</total_attendance>
</name> </roll_number> </serial_number>
<serial_number > 2 <roll_number> 20100602 <name> Kirti <total_attendance>
<month> January <month_attendance> 80 </month_attendence> </month>
<month> February <month_attendance> 86 </month_attendence> </month>
<month> March <month_attendance> 98 </month_attendence> </month>
92
</total_attendance> </name> </roll_number> </serial_number>
<serial_number > 3 <roll_number> 20100603 <name> Amrita <total_attendance>
<month> January <month_attendance> 90 </month_attendence> </month>
<month> February <month_attendance> 90 </month_attendance> </month>
<month> March <month_attendance> 100 </month_attendance> </month>
93
</total_attendance> </name> </roll_number> </serial_number>
.
.
.
</ javaStuAttendence>

OXFORD H i g h e r Education
Oxford University Press, 2012. All rights reserved.
1 Raj Kamal: Mobile Computing (2/e)
Chapter 7: Databases
Question Bank

Examples of the transaction with an API


Transaction with StuAttendances can be done by following commands (functions). An API named FindAttendance
uses using a XML parser.

A Connect transaction connects the API FindAttendance with the StuAttendances.


A read transaction from the API FindAttendance reads a month_attendance from the StuAttendances.
A write transaction from the API FindAttendance writes a month_attendance into the StuAttendances.
An append transaction from the API FindAttendance appends a month_attendance into the StuAttendances.
A query transaction from the API FindAttendance queries the StuAttendances. The transaction gets the
attendance record of a specified student or a specified set of students (for example between roll number
20100601 to 20100605) from the database StuAttendances.
A close transaction disconnects the API FindAttendance with the StuAttendances.

Page references:
Database: Pages 308 to 313; XML database: Page 313; Transactions with database: Pages 308, 311 and 312

Q5. (a) Explain Database hoarding.


(b) Explain data-caching.

Database hoarding
The cached data is hoarded in the mobile device database. Hoarding of the cached data in the database ensures that
even when the device is not connected to a network or server (disconnected mode), the data required from the database
is available for computing.

Example
consider the train schedules in a railway timetable. The schedule of specific trains to and from the device user location
is stored in the huge databases of the servers and network of the company operating the trains. The user device caches
and hoards some specific information from the databases and the hoarded device database is used during computations
for retrieving the data for a specific set of train schedules.

Data caching
Large databases are available on servers, remote computing systems, or networks. A mobile device is not always
connected to the server or network, neither does the device retrieve data from a server or a network for each
computation. Rather, the device caches some specific data which may be required for future computations during the
interval in which the device is connected to the server or network.

Caching entails saving a copy of select data or a part of a database from a connected system with a large database.

A client device caches the pushed (disseminated) data records from a server (Section 8.2.1). Caching of the pushed data
leads to a reduced access interval as compared to the pull (on-demand) mode of data fetching. (Section 8.2.2) Further, it
also reduces the dependence on pushing precedence at the server. Caching of data records can be based on pushed hot
records (the most needed database records at the client device).

Also, caching can be based on the ratio of two parametersaccess probability (at the device) and pushing rates (from
the server) for each record. This method is called cost-based data replacement or caching. However, the access
probability of each record and its comparison with probabilities of other records is often unpredictable in the wireless
environment. An alternative method is that the least frequently pushed records and the pushed records having larger
access time are placed in the database at the device. This access method, therefore, use the ratio of two
parametersaverage access time between two successive instances of access to the record and pushing rates for the
record.

OXFORD H i g h e r Education
Oxford University Press, 2012. All rights reserved.
1 Raj Kamal: Mobile Computing (2/e)
Chapter 7: Databases
Question Bank

Page references:
Database hoarding and Caching: Pages 328 to 330;

Q6. (a) Discuss the features of client-server computing.


(b) Explain two-tier, three-tier and four-tier client server architecture.

Features of client-server computing


Consider a network of distributed nodes (computers and computing devices). The network architecture can be designed
such that a node is either a client or a server.

A client node runs application software which depends on server node resources (files, databases, web pages, other
resources, processor power, or other devices or computers connected or networked to it).

The server node has larger resources and computing power than the client nodes. This architecture is known as client
server computing architecture. It is different from peer-to-peer architecture, where each node on the network has
similar resources and the various nodes can depend on each other resources.

Mobile devices function as client nodes due to their resource constraints. A server networks to a number of devices.
Clientserver architecture is used for mobile computing.

Consider a network of distributed nodes (computers and computing devices). The network architecture can be designed
such that a node is either a client or a server. A client node runs application software which depends on server node
resources (files, databases, web pages, other resources, processor power, or other devices or computers connected or
networked to it).

The server node has larger resources and computing power than the client nodes. This architecture is known as client
server computing architecture. It is different from peer-to-peer architecture, where each node on the network has
similar resources and the various nodes can depend on each other resources.

Mobile devices function as client nodes due to their resource constraints. A server networks to a number of devices.
Clientserver architecture is used for mobile computing.

Two-tier, three tier and four tier client server architecture


Read Sections 7.7.1.1 to 7.7.1.3 for detailed answer.

OXFORD H i g h e r Education
Oxford University Press, 2012. All rights reserved.
1 Raj Kamal: Mobile Computing (2/e)
Chapter 7: Databases
Question Bank

OXFORD H i g h e r Education
Oxford University Press, 2012. All rights reserved.
1 Raj Kamal: Mobile Computing (2/e)
Chapter 7: Databases
Question Bank

OXFORD H i g h e r Education
Oxford University Press, 2012. All rights reserved.
1 Raj Kamal: Mobile Computing (2/e)
Chapter 7: Databases
Question Bank

Page references:
Client server computing: Page 335; Two-tier, three-tier and four-tier client server computing: Pages 336 to 339;

Q7. (a) Show a query processing architecture.


(b) Explain query processing.

Query Processing
During a transaction with a database, queries are sent to read and get the records from the database. Queries can be
better understood by the following example. Assume that there are two sets of database records Contacts and
SavedNumbers. Contacts stores the rows of records consisting of first character (firstChar) of name, contact-
name (cName), and contact telephone number (cTelNum). A record in Contacts can be searched by firstChar,
cName, or cTelNum.

DialledNumbers stores the rows of records consisting of dialling sequence number (seqNum), time of call
(cTime), and dialled telephone number (dTelNum). A record in DialledNumbers can be searched by seqNum,
cTime, or dTelNum.

Figure 7.2 shows a query processing architecture.

OXFORD H i g h e r Education
Oxford University Press, 2012. All rights reserved.
1 Raj Kamal: Mobile Computing (2/e)
Chapter 7: Databases
Question Bank

The query optimizer employs (a) query processing plan generator and (b) query processing cost estimator to provide an
efficient plan for query processing. Here, plan means a tree like structure of relational algebraic operations for the given
equation.

Assume that a query for processing is as followsGet that contact name and telephone number in which the first
character of the contact name is R and contact telephone number is among the previously dialled numbers. If high-
level language SQL is used for declarations, then the SQL query during a transaction is programmed as follows:

SELECT cName, cTelNum FROM Contacts, DialledNumbers WHERE Contacts.firstChar =


R AND Contacts.cTelNum = DialledNumbers.dTelNum

Query processing means making a correct as well as efficient execution strategy by query decomposition and query-
optimization. A relational-algebraic equation defines a set of operations needed during query processing. Either of the
two equivalent relational-algebraic equations given below can be used.

cName, cTelNum (Contacts.firstChar = R ( Contacts.cTelNum = DialledNumbers.dTelNum (Contacts) DialledNumbers)) (7.1)

This means first select a column Contacts.cTelNum in a row in Contacts in which Contacts.cTelNum
column equals a column DialledNumbers.dTelNum by crosschecking and matching the records of a column in
Contacts with all the rows of DialledNumbers. Then in the second step select the row in which
Contacts.firstChar = R and the selected cTelNum exists. Then in the third step project cName and
cTelNum.
cName,cTelNum(Contacts.firstChar = R Contacts.cTelNum = DialledNumbers.dTelNum (Contacts DialledNumbers)) (7.2)

This means that in first series of step, crosscheck all rows of Contacts and DialledNumbers and select, after AND
operation, the rows in which Contacts.firstChar = R and Contacts.cTelNum =
DialledNumbers.dTelNum. Then in the next step project cName and cTelNum form the selected records.

represents the projection operation, , the selection operation, and , the AND operation. It is clear that the second
set of operations in query processing is less efficient than the first. Query decomposition of the first set gives
efficiency. Decomposition is done by (i) analysis, (ii) conjunctive and disjunctive normalization, and (iii) semantic
analysis.

Efficient processing of queries needs optimization of steps for query processing. Optimization can be based on cost
(number of micro-operations in processing) by evaluating the costs of sets of equivalent expressions. Optimization can
also be based on a heuristic approach consisting of the following steps: perform the selection steps and projection steps
as early as possible and eliminate duplicate operations. For example, in the above case, in first set of operations, the
column Contacts.cTelNum was first selected and then the other operations were carried out.

Page references:
Query processing: Pages 322 to 324.

OXFORD H i g h e r Education
Oxford University Press, 2012. All rights reserved.

S-ar putea să vă placă și