Академический Документы
Профессиональный Документы
Культура Документы
118. Which of the following will NOT decrease the processing time
of a
computer?
w) increasing the processor speed
x) increasing the size of the data bus
y) increasing the resolution of the monitor
z) decreasing the access time of a hard disk
ANSWER: Y -- INCREASING THE RESOLUTION OF THE MONITOR
119.What does the acronym G-I-G-O mean?
ANSWER: GARBAGE IN, GARBAGE OUT
121. What is the name of the marker that indicates where the next
typed character will appear on the screen?
ANSWER: CURSOR
122. You are laying out the logic of your computer program before
you begin writing it. The graphical representation that you create is
called a
w) file
x) simulation
y) listing
z) flowchart
ANSWER: Z -- FLOWCHART
123.Which of the following does NOT belong?
w) printer
x) plotter
y) monitor
z) keyboard
ANSWER: Z -- KEYBOARD (Keyboard is input, others are output
devices)
132. Which computer pioneer was also a Rear Admiral of the U.S.
Navy?
w) Steve Jobs
x) John Backus
y) John von Neumann
z) Grace Hopper
ANSWER: Z -- GRACE HOPPER
141. In computer science what does the acronym JCL stand for?
w) Justified Computer Language
x) Justified Complete Language
y) Job Computerized Language
z) Job Control Language
ANSWER: Z -- JOB CONTROL LANGUAGE
147. One of the things that separates a "Terminal" from a "PC" is that
the terminal does not have a what?
w) Keyboard
x) Monitor
y) Power cord
z) CPU
ANSWER: Z CPU
148. The "First Generation" of computers used?
w) Gears
x) Vacuum Tubes
y) Transistors
z) No Electricity, Mechanical
ANSWER: X -- VACUUM TUBES
149.In communications an extra bit is added to each byte to aid in
checking data for accuracy. This bit is known as what?
ANSWER: PARITY
155. The term used to indicate, in bits per second, the transmission
speed of a modem is?
ANSWER: BAUD
169. What is the term for a temporary storage area that compensates
for
differences in data rate and data flow between devices?
w) Buffer
x) Bus
y) Channel
z) Modem
ANSWER: W -- BUFFER
170.Consider the following algorithm: x is initialized to 2; x is then
replaced by its double four times in sequence; x is then
decremented by 2 three times in sequence.
What is the final value of x.
ANSWER: 26.
180. The terms FIFO and LIFO would most likely arise during a
discussion of:
w) storage media
x) binary trees
y) compiler design
z) queues
ANSWER: Z -- QUEUES
181.
181.Which of the following is a computer program that appears to be legitimate but performs
an illicit activity
when it is run?
a. Redundant verification.
b. Parallel count.
c. Web crawler.
d. Trojan horse.
ANSWER:
Choice "d" is correct. A Trojan horse (like the wooden horse in Helen of Troy) is a program
that appears to have a useful function but that contains a hidden and unintended function that
presents a security risk (appears to be legitimate but performs an illicit activity when it is
run).Choice "a" is incorrect. It is unclear what redundant verification is. One possibility if
that it means verifying something twice to make sure that it is done once. This term is
probably just made up.
Choice "b" is incorrect. A parallel count appears to be the counting of bits in a parallel
fashion. It appearsto have something to do with digital circuits in digital clocks, watches,
microwave ovens, VCRs, and the like. It is not a computer program.
Choice "c" is incorrect. A web crawler (also known as a web spider or web robot) is a program
which browses the web in a methodical, automated manner. Web crawlers are mainly used to
create a copy of visited web pages for later processing by a search engine. Web crawlers can
also be used for automating maintenance tasks on a web site. Web crawlers can also be used to
gather specific types of information from web pages. There is nothing illicit about a web
crawler.
182. Consider the following functions.
void Myst(int a, int & b)
{
a *= b;
b = 2 + a;
}
void Test()
{
int u = 2;
int v = 3;
Myst(u, v);
cout << u << " " << v << endl;
}
Soln. Question 2:
Essential components to the answers are listed below:
(i) .
First indicate that it is not a case of tools but CASE tools.
Special software termed Computer Aided Software Engineering (CASE) can be
used to assist the introduction of software engineering techniques.
(ii) Analysis modelling refers to the technical representation of a system using one or
more of the following diagrammatic and textual techniques: entity relationship
diagrams, data flow diagrams, data dictionaries, and state transitions diagrams.
(iii) Data Dictionary - ``An organized listing of all data elements that are pertinent to the
system, with precise, definitions so that both user and system analyst will have a
common understanding of inputs, outputs, components of stores and [even]
intermediate calculations.
3. Give two advantages and two disadvantages of the following
specification
techniques:
i) Questionnaires
ii) Client Documents
iii) Observations
soln. Question 3:
Two advantages of questionnaires are:
a) Overcomes the burden of multiple interviews
b) Can be filled out by large numbers of people
Two disadvantages of questionnaires are:
a) Lacks interactivity
b) Must be carefully designed
Two advantages of client documents are:
a) Detailed information regarding the operating of the client organisation can be
captured and the types of data used by the organisation can be traced
b) Less invasive/disruptive than interviews.
Two disadvantages of client documents are:
a) May have legal issues is the document contain sensitive information.
b) Documents may not necessarily outline how the process is actually carried out.
They may be inaccurate or out of date.
Two advantages of observations are:
a) Use of video cameras can capture what happens in the
office, making this
technique less intrusive.
b) One can directly observe what actually happens wrt a
given process as oppose to
how it is documented.
Two disadvantages of observations are:
a) May have privacy issues
b) May have legal issues
Solution Question 5
The source of the problem lies in the fact that ESS is using the
Build-And-Fix approach. This approach should never be used to
produce software as its adhoc development approach has no
clearly defined phases. Moreover with the lack of project
management (incl. Risk management) and quality assessment
monitoring this approach is doomed to fail. In essence, the product
is built and modified as many times as possible until it
satisfies the client. The cost of using this approach is greater than
if specifications are drawn up and a design is carefully developed.
1. Which of the foll is not a protocol.
HTTP PIM PSI
Ans: PSI (check)
2 Which of the following does not help with security?
Good Password
Update Antivirus
VLAN
Ans: VLAN
3> What was the prob with Intel Processor
Cache
FPU
NONE
Ans: FIND OUT AND LET ME KNOW
4 What does MIME stand for
Ans: Multipurpose Mail Exchange Protocol
5 What does XP stand for in WIN-Xp
Ans: Experience
6 Who is associated with C
Ans: Dennis Ritchie
7 Which of the foll is not a IM client
AOL
MSN
JABBER
XINGC
Ans: XINGC
8 What does ERP stand for?
Ans: Enterprise resource planning.
9 Who is associated with HOTMAIL
SABEER Bhatia and Jack Smith
SABEER Bhatia and Bill Gates
Ans: SABEER Bhatia and Jack Smith
10 What does UNIX stand 4?
UNiplexed Information Computing System. UNICS later known
as UNIX.
hich of the following is not an app server?
ESTONE
SPHERE
CAT
SS
wer: BLUESTONE is not an app server.
ENERAL CSE (Computer science and engineering branch B.tech BE) quest
hat do u call software embedded in ROM
WARE
REWARE
WARE
BIOS (Verify and plz let me know)
hat is semaphore used 4????
tegral Constraint helps in???
Solving Inconsistent Data prob.
NG uses
ICMP
ADDRESS occupies
es
es
ytes
es
I wrote 8. correct ans 4
17 Which Data Structure helps Searching
STACK
LINKED LIST
HASH
Ans: HASH
18 Q on Binary tree Depth?
2^n
2^n 1
log n
19 Database should have
Ans: ACID properties.
20 VPN stands 4
Ans: virtual private n/w
21 what does fork() return 2 parent
child pid
0
Ans: 0
22> What do u call the relationship b/e a table and its columns
Ans: Schema
HP 12 Questions on c & c++
23 What is true about c++
Ans: It can have virtual constructors
24 result of i=6; printf(%d,i++*i++)
36
54
cant say
Ans: Cant say (compiler dependent)
25 output of
char str[20] = PANKAJ
printf(%d%d,sizeof(str),strlen(str))
Answer
26 Which 20,6
of the following cant be used across
files?
extern
volatile
static
const
Ans: static. (i wrote volatile)
27 union u{ int i; char c;};
sizeof(u);
Ans: 4
28 Identify the error below:
5[[a]
5["abc"]
26 Which of the following cant be used across files?
extern
volatile
static
const
Ans: static. (i wrote volatile)
27 union u{ int i; char c;};
sizeof(u);
Ans: 4
28 Identify the error below:
5[[a]
5["abc"]
Ans: 5["abc"]
8.1.1 An entity is
(a) a collection of items in an application
(b) a distinct real world item in an application
(c) an inanimate object in an application
(d) a data structure
8.1.2 Pick entities from the following:
(i) vendor
(ii) student
(iii) attends
(iv) km/hour
(a) i, ii, iii (b) i, ii, iv
(c) i and ii (d) iii and iv
8.1.3 A relationship is
(a) an item in an application
(b) a meaningful dependency between entities
(c) a collection of related entities
(d) related data
8.1.4 Pick the relationship from the following:
(a) a classroom
(b) teacher
(c) attends
(d) cost per dozen
8.1.5 Pick the meaningful relationship between entities
(a) vendor supplies goods
(b) vendor talks with customers
(c) vendor complains to vendor
(d) vendor asks prices
8.1.6 The entity set is a
(a) set of entities
(b) collection of different entities
(c) collection of related entities
(d) collection of similar entities
8.1.7 Pick entity set from the following
(a) all vendors supplying to an organization
(b) vendors and organizations they supply
(c) vendors and transporters
(d) a vendor supplying to many organizations
8.1.8 Attributes are
(i) properties of relationship
(ii) attributed to entities
(iii) properties of members of an entity set
(a) i (b) i and ii
(c) i and iii (d) iii
8.1.9 The attributes of relationship teaches in teacher teaches course should
be
(a) teacher code, teacher name, dept, phone no
(b) course no, course name, semester offered, credits
(c) teacher code, course no, semester no
(d) teacher code, course no, teacher name, dept, phone no
8.1.10 The expansion of E-R diagram is
(a) Entity-Relationship diagram
(b) Entity-Relative diagram
(c) Entity-Relation diagram
(d) Entity-Rationalized diagram
8.1.11 In an E-R diagram entities are represented by
(a) circles
(b) rectangles
(c) diamond shaped box
(d) ellipse
8.1.12 In an E-R diagram relationship is represented by
(a) circles
(b) rectangles
(c) diamond shaped box
(d) ellipse
8.1.13 Entities are identified from the word statement of a problem by
(a) picking words which are adjectives
(b) picking words which are nouns
(c) picking words which are verbs
(d) picking words which are pronouns
8.1.14 Relationships are identified from the word statement of a
problem by
(a) picking words which are adjectives
(b) picking words which are nouns
(c) picking words which are verbs
(d) picking words which are pronouns
8.1.15 One entity may be
(a) related to only one other entity
(b) related to itself
(c) related to only two other entities
(d) related to many other entities
8.1.1 b
8.1.2 c
8.1.3 b
8.1.4 c
8.1.5 a
8.1.6 d
8.1.7 a
8.1.8 c
8.1.9 c
8.1.10 a
8.1.11 b
8.1.12 c
8.1.13 b
8.1.14 c
8.1.15 d
8.2.1 By relation cardinality we mean
(a) number of items in a relationship
(b) number of relationships in which an entity can appear
(c) number of items in an entity
(d) number of entity sets which may be related to a given entity
8.2.2 If an entity appears in only one relationship then it is
(a) a 1:1 relationship
(b) a 1:N relationship
(c) a N:1 relationship
(d) a N:M relationship
8.2.3 If an entity appears in N relationships then it is
(a) a 1:1 relationship
(b) a 1:N relationship
(c) a N:1 relationship
(d) a N:M relationship
8.2.4 If an entity appears in not more than 5 relationships then it is a
(a) 1:1 relationship
(b) 1:5 relationship
(c) 5:1 relationship
(d) 5:5 relationship
8.2.5 A pilot can fly three types of planes and a plane can be piloted by
any qualified
pilot. The pilot-plane type relationship is
(a) N:3
(b) 3:N
(c) 1:3
(d) 3:1
8.2.6 A student can take not more than 5 subjects in a semester. The
number of
students allowed in a subject in a semester is not more than 40. The
student
subject relationship is:
(a) 5:40
(b) 40:5
(c) N:5
(d) 40:M
8.2.7 The following E-R diagram is interpreted as follows:
(a) A doctor treats upto N patients
(b) A doctor treats exactly N patients
(c) A doctor may treat upto N patients; Some doctors may
not treat any patients
(d) A doctor will treat patients based on some conditions
8.2.8 A relation is
(a) an entity
(b) a relationship
(c) members of a relationship set
(d) members of an entity set or a relationship set
8.2.9 Rows of a relation are called
(a) tuples
(b) a relation row
(c) a data structure
(d) an entity
8.2.10 The rows of a relation
(a) must be in specified order
(b) may be in any order
(c) in ascending order of key
(d) in descending order of key
8.2.11 The columns of a relation
(a) must be in specified order
(b) may be in any order
(c) with key field in first column
(d) with largest width column last
8.2.12 Relations are used in logical database design because
(i) sound theory of relations facilitates systematic design of relational
databases
(ii) they are very popular
(iii) they are flat files and easy to store and retrieve from computers
memory
(iv) E-R diagrams allow design of relations
(a) i and ii (b) i and iii
(c) ii and iii (d) iii and iv
8.4.1 a
8.4.2 c
8.4.3 a
8.4.4 d
8.5.1 By redundancy in a file based system we mean that
(a) unnecessary data is stored
(b) same data is duplicated in many files
(c) data is unavailable
(d) files have redundant data
8.5.2 Data integrity in a file based system may be lost because
(a) the same variable may have different values in different files
(b) files are duplicated
(c) unnecessary data is stored in files
(d) redundant data is stored in files
8.5.3 Data availability is often difficult in file based system
(a) as files are duplicated
(b) as unnecessary data are stored in files
(c) as one has to search different files and these files may be in different update
states
(d) redundant data are stored in files
8.5.4 Management policy changes are difficult to implement in a file based system
because
(a) relating data in different files is difficult
(b) files are duplicated
(c) redundant data are stored
(d) unnecessary data is stored
8.5.5 Some of the objectives of a database management system are to
(i) minimize duplication of data
(ii) ensure centralized management control of data
(iii) ease retrieval of data
(iv) maintain a data dictionary
(a) i and ii (b) i, ii and iv
(c) i and iii (d) i, ii and iii
8.5.6 A database is a
(a) collection of files
(b) collection of inputs and outputs of application
(c) collection of related data necessary to manage an organization
(d) data resource of an organization
8.5.7 A database models data so that it is
(a) appropriate for application
(b) independent of application program
(c) optimized for most frequent applications
(d) optimized for all applications
8.5.8 A database should be designed to allow providing
(a) different views of portions of data requested by an application
(b) data only to selected applications as decided by an organization
(c) a uniform view of data to all applications
(d) data to all applications
8.5.9 The abbreviation DBMS stands for
(a) Data Base Manipulation System
(b) Data Bank Manipulating System
(c) Data Base Management System
(d) Data Bank Management System
8.5.10 A DBMS is
(a) another name for database system
(b) independent of a database
(c) dependent on application programs
(d) is a set of procedures which manage a database
8.5.11 A DBMS
(a) is a set of procedures
(b) manages a database
(c) is a set of procedures to manage a database to provide data as
required by applications
(d) provides data to applications
8.5.12 One of the main objectives of a DBMS is to
(a) Create a database for an organization
(b) Facilitate sharing of a database by current and future applications
(c) Allow sharing application programs
(d) Replace file based systems
8.5.13 Database is
(a) an important resource of an organization
(b) not relevant to existing programs
(c) not relevant for future programs
(d) not as good as files as there is redundancy
8.5.14 By data independence we mean application programs
(a) do not need data
(b) may be developed independent of data
(c) may be developed without knowing the organization of data
(d) may be developed with independent data
8.5.15 Data independence allows
(i) no changes in application programs
(ii) change in database without affecting application programs
(iii) hardware to be changed without affecting application programs
(iv) system software to be changed without affecting application programs
(a) i, ii (b) ii, iii
(c) ii, iii, iv (d) i, ii, iv
8.5.16 Data independence allows
(a) sharing the same database by several applications
(b) extensive modification of applications
(c) no data sharing between applications
(d) elimination of several application programs
8.5.17 Among objectives of DBMS are ensuring
(i) data integrity
(ii) data redundancy
(iii) data security
(iv) easy data retrieval
(a) i, ii (b) i, iii
(c) i, iii, iv (d) i, ii, iii
8.5.18 DBMS
(a) does not allow replication of data
(b) allows controlled replication of data if it improves performance
(c) does not allow common data to be duplicated
(d) does not allow replication as it adversely affects reliability
8.5.19 By data integrity we mean
(a) maintaining consistent data values
(b) integrated data values
(c) banning improper access to data
(d) not leaking data values
8.5.20 Data integrity is ensured by
(a) good data editing
(b) propagating data changes to all data items
(c) preventing unauthorized access
(d) preventing data duplication
8.5.21 By data security in DBMS we mean
(a) preventing access to data
(b) allowing access to data only to authorized users
(c) preventing changing data
(d) introducing integrity constraints
8.5.22 DBMS must implement management controls to
(i) control access rights to users
(ii) implement audit trail when changes are made
(iii) allow data to be used extensively in the organization
(iv) duplicate databases
(a) i, ii (b) ii, iii
(c) iii, iv (d) i, iv
8.5.1 b 8.5.2 a 8.5.3 c 8.5.4 a 8.5.5 d
8.5.6 c 8.5.7 b 8.5.8 a 8.5.9 c 8.5.10 d
8.5.11 c 8.5.12 b 8.5.13 a 8.5.14 c 8.5.15 c
8.5.16 a 8.5.17 c 8.5.18 b 8.5.19 a 8.5.20 b
8.5.21 b 8.5.22 a
8.6.1 An E-R modelling for given application leads to
(a) conceptual data model
(b) logical data model
(c) external data model
(d) internal data model
8.6.2 A conceptual data model is converted using a Relational Data Base
Management System to a
(a) logical data model
(b) external data model
(c) internal data model
(d) an entity-relation data model
8.6.3 A subset of logical data model accessed by programmers is called a
(a) conceptual data model
(b) external data model
(c) internal data model
(d) an entity-relation data model
8.6.4 When a logical model is mapped into a physical storage such as a
disk store
the resultant data model is known as
(a) conceptual data model
(b) external data model
(c) internal data model
(d) disk data model
8.6.5 A DBMS has the following components
(i) a data definition language
(ii) a query language
(iii) a security system
(iv) audit trail
(a) i, ii (b) i, ii, iii
(c) i, ii, iii, iv (d) i, ii, iv
8.6.6 A check pointing system is needed
(a) to ensure system security
(b) to recover from transient faults
(c) to ensure system privacy
(d) to ensure system integrity
8.6.7 A database administrator
(a) administers data in an organization
(b) controls all inputs and all outputs of programs
(c) is controller of data resources of an organization
(d) controls all data entry operators
8.6.8 The responsibilities of a database administrator includes
(i) maintenance of data dictionary
(ii) ensuring security of database
(iii) ensuring privacy and integrity of data
(iv) obtain an E-R model
(a) i, ii (b) i, ii, iii
(c) i, ii, iii, iv (d) ii, iii, iv
8.6.9 Access right to a database is controlled by
(a) top management
(b) system designer
(c) system analyst
(d) database administrator
8.6.10 The sequence followed in designing a DBMS are
(a) physical model conceptual model logical model
(b) logical model physical model conceptual model
(c) conceptual model logical model physical model
(d) conceptual model physical model logical model
8.6.11 Designing physical model of DBMS requires information on
(i) data volume
(ii) frequency of access to data
(iii) programming language used
(iv) secondary memory characteristics
(a) i, ii (b) i, ii, iii
(c) i, ii, iii, iv (d) i, ii, iv
8.6.12A good database design
(i) caters primarily to current needs
(ii) caters to current and future needs as organizations grow
(iii) has to be modified when hardware is upgraded
(iv) ensures data security
(a) i, ii (b) i, ii, iii
(c) ii, iv (d) iii, iv
Answer:
Hence, in the while loop initial value pointed by p is 'h', which is changed to 'i' by executing ++*p and pointer moves to
point, 'a' which is similarly changed to 'b' and so on. Similarly blank space is converted to '!'. Thus, we obtain value in p
becomes ibj!gsjfoet and since p reaches '\0' and p1 points to p thus p1doesnot print anything.
#includestdio.h
#define a 10
main()
{
#define a 50
printf("%d",a);
}
Answer:
50
Explanation:
The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken.
#define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}
Answer:
100
Explanation:
Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 100
occurs.The input program to compiler looks like this :
main()
{
100;
printf("%d\n",100);
}
Note:
100; is an executable statement but with no action. So it doesn't give any problem
main()
{
printf("%p",main);
}
Answer:
Some address will be printed.
Explanation:
Function names are just addresses (just like array names are addresses).
main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They
are printed as hexadecimal numbers. main()
{
clrscr();
}
clrscr();
Answer:
No output/error
Explanation:
The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is
not inside any function).
enum colors {BLACK,BLUE,GREEN}
main()
{
printf("%d..%d..%d",BLACK,BLUE,GREEN);
return(1);
}
Answer:
0..1..2
Explanation: enum assigns numbers starting from 0, if not explicitly defined.
void main()
{
char far *farther,*farthest;
printf("%d..%d",sizeof(farther),sizeof(farthest));
}
Answer:
4..2
Explanation:
the second pointer is of char type and not a far pointer
main()
{
int i=400,j=300;
printf("%d..%d");
}
Answer:
400..300
Explanation:
printf takes the values of the first two assignments of the program. Any number of printf's may be given. All
of them take only the first two values. If more number of assignments given in the program,then printf will
take garbage values.
main()
{
char *p;
p="Hello";
printf("%c\n",*&*p);
}
Answer:
H
Explanation:
* is a dereference operator & is a reference operator. They can be applied any number of times provided it is
meaningful. Here p points to the first character in the string "Hello". *p dereferences it and so its value is H.
Again & references it to an address and * dereferences it to the value H.
main()
{
int i=1;
while (i<=5)
{
printf("%d",i);
if (i>2)
goto here;
i++;
}
}
fun()
{
here:
printf("PP");
}
Answer:
Compiler error: Undefined label 'here' in function main
Explanation:
Labels have functions scope, in other words The scope of the labels is limited to functions . The label 'here' is available in function fun() Hence it
is not visible in function main.
main()
{
static char names[5][20]={"pascal","ada","cobol","fortran","perl"};
int i;
char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i<=4;i++)
printf("%s",names[i]);
}
Answer:
Compiler error: Lvalue required in function main
Explanation:
Array names are pointer constants. So it cannot be modified.
void main()
{
int i=5;
printf("%d",i++ + ++i);
}
Answer:
Output Cannot be predicted exactly.
Explanation:
Side effects are involved in the evaluation of i
void main()
{
int i=5;
printf("%d",i+++++i);
}
Answer:
Compiler Error
Explanation:
The expression i+++++i is parsed as i ++ ++ + i which is an illegal combination of operators.
#includestdio.h
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}
Answer:
Compiler Error: Constant expression required in function main.
Explanation:
The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error).
Note:
Enumerated types can be used in case statements
main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}
Answer:
1
Explanation:
Scanf returns number of items successfully read and not 1/0. Here 10 is given as input which should have been scanned
successfully. So number of items read is 1.
#define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
Answer:
100
main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
}
Answer:
1
Explanation:
before entering into the for loop the checking condition is "evaluated". Here it evaluates to 0 (false) and comes out of the
loop, and i is incremented (note the semicolon after the for loop).
#includestdio.h
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
Answer:
M
Explanation:
p is pointing to character '\n'.str1 is pointing to character 'a' ++*p meAnswer:"p is pointing to '\n' and that is incremented by
one." the ASCII value of '\n' is 10. then it is incremented to 11. the value of ++*p is 11. ++*str1 meAnswer:"str1 is pointing
to 'a' that is incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98. both 11 and 98 is added and result is subtracted
from 32". i.e. (11+98-32)=77("M");
#includestdio.h
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
}
Answer:
Compiler Error
Explanation:
Initialization should not be done for structure members inside the structure declaration
includestdio.h
main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}
Answer:
Compiler Error
Explanation:
in the end of nested structure yy a member have to be declared.
main()
{
extern int i;
i=20;
printf("%d",sizeof(i));
}
Answer:
Linker error: undefined symbol '_i'.
Explanation:
extern declaration specifies that the variable i is defined somewhere else. The compiler passes the external variable to be
resolved by the linker. So compiler doesn't find an error. During linking the linker searches for the definition of i. Since it is
not found the linker flags an error.
main()
{
printf("%d", out);
}
int out=100;
Answer:
Compiler error: undefined symbol out in function main.
Explanation:
The rule is that a variable is available for use from the point of declaration. Even though a is a global variable, it is not available for main. Hence
an error.
main()
{
extern out;
printf("%d", out);
}
int out=100;
Answer:
100
Explanation:
This is the correct way of writing the previous program.
main()
{
show();
}
void show()
{
printf("I'm the greatest");
}
Answer:
Compier error: Type mismatch in redeclaration of show.
Explanation:
When the compiler sees the function show it doesn't know anything about it. So the default return type (ie, int) is assumed. But when compiler
sees the actual definition of show mismatch occurs since it is declared as void. Hence the error.
The solutions are as follows:
declare void show() in main() .
define show() before main().
declare extern void show() before the use of show().
Predict the output or error(s) for the following:
class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout "The value is " *ptr;
}
};
void SomeFunc(Sample x)
{
cout "Say i am in someFunc " endl;
}
int main()
{
Sample s1= 10;
SomeFunc(s1);
s1.PrintVal();
}
Answer:
Say i am in someFunc
Null pointer assignment(Run-time error)
Explanation:
As the object is passed by value to SomeFunc the destructor of the object is called when the control returns from the function. So when PrintVal is
called it meets up with ptr that has been freed.The solution is to pass the Sample object by reference to SomeFunc:
void SomeFunc(Sample &x)
{
cout "Say i am in someFunc " endl;
}
Which is the parameter that is added to every non-static member function when it is called?
Answer: 'this' pointer
class base
{
public:
int bval;
base(){ bval=0;}
};
class deri:public base
{
public:
int dval;
deri(){ dval=1;}
};
void SomeFunc(base *arr,int size)
{
for(int i=0; isize; i++,arr++)
coutarr-bval;
coutendl;
}
int main()
{
base BaseArr[5];
SomeFunc(BaseArr,5);
deri DeriArr[5];
SomeFunc(DeriArr,5);
}
Answer:
00000
01010
Explanation:
The function SomeFunc expects two arguments.The first one is a pointer to an array of base class objects and the second one is the sizeof the
array.The first call of someFunc calls it with an array of bae objects, so it works correctly and prints the bval of all the objects. When Somefunc is
called the second time the argument passed is the pointeer to an array of derived class objects and not the array of base class objects. But that is
what the function expects to be sent. So the derived class pointer is promoted to base class pointer and the address is sent to the function.
SomeFunc() knows nothing about this and just treats the pointer as an array of base class objects. So when arr++ is met, the size of base class
object is taken into consideration and is incremented by sizeof(int) bytes for bval (the deri class objects have bval and dval as members and so is
You install File and Printer Sharing for Microsoft Networks.You share a folder and leave the password
option blank.Who can gain access to the folder
a. Anyone who can gain access to your network and has a Microsoft redirector such as the Client for
Microsoft Networks installed.
b.Windows 98 will not allow a blank password in this field.
c.anyone with Internet Explorer installed.
d.Only users that are members of the same workgroup as you.
Answer: A
Some protocols are considered to be technically non-routable.Which of the following statements best
describes the most common reason why a protocol would be considered non-routable
A. It does not contain the appropriate Data Link layer information required by routers.
B. It uses advanced Transport layer services to move across the Internet and avoids the routing
overhead required by the more primitive networking protocols.
c.It defines Physical layer network addresses for internal routing.
D.It does not specify the Network layer addresses required by routers.
Answer: D
What is the binary network ID of the loopback IP address
A. 1
B. 10101010
C. 0
D. 1111111
Answer: D
You are the LAN administrator for your company.You have couple Windows 2000
Professional clients that dial in via PPP to the company networks RAS
server.You want the remote clients to be assigned dynamic IP addresses.You
reserve a pool of class B addresses for these clients.Upon connecting, you
find that the Windows 2000 computers are using a subnet mask of all
255s.What should you do
A. Run ipconfig with the /release and /renew switch on the client
B. Run ipconfig with the /renew_all switch on the client
C. Run winipcfg on the client
D. Do nothing.This is normal
Answer: D
In general:
If there are n nodes, there exist 2n-n different trees.
List out few of the Application of tree data-structure? Answer: The list is as follows:
The manipulation of Arithmetic expression,
Symbol Table construction,
Syntax analysis.
List out few of the applications that make use of Multilinked Structures? Answer:
The applications are listed below:
Sparse matrix,
Index generation.
In tree construction which is the suitable efficient data structure? Answer: Linked
list is the efficient data structure.
What is the type of the algorithm used in solving the 8 Queens problem? Answer:
Backtracking
In an AVL tree, at what condition the balancing is to be done? Answer: If the 'pivotal
value' (or the 'Height factor') is greater than 1 or less than -1.
What is the bucket size, when the overlapping and collision occur at same time? Answer:
One. If there is only one entry possible in the bucket, when the collision occurs, there is no
way to accommodate the colliding value. This results in the overlapping of values.
Traverse the given tree using Inorder, Preorder and Postorder traversals.
Answer:
Inorder : D H B E A F C I G J
Preorder: A B D H E C F G I J
Postorder: H D E B F I J G C A
There are 8, 15, 13, 14 nodes were there in 4 different trees. Which of them could have
formed a full binary tree? Answer: 15.
In general:
There are 2n-1 nodes in a full binary tree.
By the method of elimination:
Full binary trees contain odd number of nodes. So there cannot be full binary trees with 8
or 14 nodes, so rejected. With 13 nodes you can form a complete binary tree but not a full
binary tree. So the correct answer is 15.
In the given binary tree, using array you can store the node 4 at which location?
Answer: At location 6
1
2 3 - - 4 - - 5
Root LC1 RC1 LC2 RC2 LC3 RC3 LC4 RC4
where LCn means Left Child of node n and RCn means Right Child of node n
For the given graph, draw the DFS and BFS
Answer:
BFS: A X G H P E M Y J
DFS: A X H P E Y M J G
Classify the Hashing Functions based on the various methods by which the key
value is found. Answer: The list of Hashing functions is as follows:
Direct method
Subtraction method
Modulo-Division method
Digit-Extraction method
Mid-Square method
Folding method
Pseudo-random method
What are the types of Collision Resolution Techniques and the methods used in
each of the type? Answer: The types of Collision Resolution Techniques are:
Open addressing (closed hashing)
The methods used include:
Overflow block
Closed addressing (open hashing)
The methods used include:
Linked list Binary tree
In RDBMS, what is the efficient data structure used in the internal storage
representation? Answer: B+ tree. Because in B+ tree, all the data is stored only in
leaf nodes, that makes searching easier. This corresponds to the records that shall
be stored in leaf nodes.
Draw the B-tree of order 3 created by inserting the following data arriving in
sequence - 92 24 6 7 11 8 22 4 5 16 19 20 78 Answer:
What is a spanning Tree? Answer: A spanning tree is a tree associated with a
network. All the nodes of the graph appear on the tree once. A minimum spanning
tree is a spanning tree organized so that the total edge weight between nodes is
minimized.
Does the minimum spanning tree of a graph give the shortest distance between any
2 specified nodes? Answer: No. Minimal spanning tree assures that the total weight
of the tree is kept at its minimum. But it doesn't mean that the distance between any
two nodes involved in the minimum-spanning tree is minimum.
Convert the given graph with weighted edges to minimal spanning tree.
What is time-stamping?
Answer:
It is a technique proposed by Lamport, used to order events in a distributed system without the use
of clocks. This scheme is intended to order events consisting of the transmission of messages.
Each system 'i' in the network maintains a counter Ci. Every time a system transmits a message, it
increments its counter by 1 and attaches the time-stamp Ti to the message. When a message is
received, the receiving system 'j' sets its counter Cj to 1 more than the maximum of its current value
and the incoming time-stamp Ti. At each site, the ordering of messages is determined by the
following rules: For messages x from site i and y from site j, x precedes y if one of the following
conditions holds....(a) if Ti<j.< and Ti="Tj" if (b) or>
How are the wait/signal operations for monitor different from those for semaphores?
Answer:
If a process in a monitor signal and no task is waiting on the condition variable, the signal is lost. So
this allows easier program design. Whereas in semaphores, every operation affects the value of the
semaphore, so the wait and signal operations should be perfectly balanced in the program.
In the context of memory management, what are placement and replacement algorithms?
Answer:
Placement algorithms determine where in available real-memory to load a program. Common methods are first-fit, next-fit, best-fit. Replacement
algorithms are used when memory is full, and one process (or part of a process) needs to be swapped out to accommodate a new program. The
replacement algorithm determines which are the partitions to be swapped out.
In loading programs into memory, what is the difference between load-time dynamic linking and run-time dynamic linking?
Answer:
For load-time dynamic linking: Load module to be loaded is read into memory. Any reference to a target external module causes that module to
be loaded and the references are updated to a relative address from the start base address of the application module. With run-time dynamic
loading: Some of the linking is postponed until actual reference during execution. Then the correct module is loaded and linked.
What are demand- and pre-paging?
Answer:
With demand paging, a page is brought into memory only when a location on that page is actually referenced during execution. With pre-paging,
pages other than the one demanded by a page fault are brought in. The selection of such pages is done based on common access patterns,
especially for secondary memory devices.
Paging a memory management function, while multiprogramming a processor management function, are the two interdependent?
Answer:
Yes.
What is page cannibalizing?
Answer:
Page swapping or page replacements are called page cannibalizing.
What has triggered the need for multitasking in PCs?
Answer:
Increased speed and memory capacity of microprocessors together with the support fir virtual memory and Growth of client server computing
What are the four layers that Windows NT have in order to achieve independence?
Answer:
Hardware abstraction layer
Kernel
Subsystems
System Services.
What is SMP?
Answer:
To achieve maximum efficiency and reliability a mode of operation known as symmetric
multiprocessing is used. In essence, with SMP any process or threads can be assigned
to any processor.
What are the key object oriented concepts used by Windows NT?
Answer:
Encapsulation
Object class and instance
Is Windows NT a full blown object oriented operating system? Give reasons.
Answer:
No Windows NT is not so, because its not implemented in object oriented language and
the data structures reside within one executive component and are not represented as
objects and it does not support object oriented capabilities .
What is the Translation Lookaside Buffer (TLB)?
Answer:
In a cached system, the base addresses of the last few referenced pages is maintained
in registers called the TLB that aids in faster lookup. TLB contains those page-table
entries that have been most recently used. Normally, each virtual memory reference
causes 2 physical memory accesses-- one to fetch appropriate page-table entry, and
one to fetch the desired data. Using TLB in-between, this is reduced to just one physical
memory access in cases of TLB-hit.
What is the resident set and working set of a process?
Answer:
Resident set is that portion of the process image that is actually in real-memory at a
particular instant. Working set is that subset of resident set that is actually needed for
execution. (Relate this to the variable-window size method for swapping techniques.)
What is an idle thread?
Answer:
The special thread a dispatcher will execute when no ready thread is found.
What is FtDisk?
Answer:
It is a fault tolerance disk driver for Windows NT.
What are the possible threads a thread can have?
Answer:
Ready
Standby
Running
Waiting
Transition
Terminated.
What are rings in Windows NT?
Answer:
Windows NT uses protection mechanism called rings provides by the process to
implement separation between the user mode and kernel mode.
What is Executive in Windows NT?
Answer:
In Windows NT, executive refers to the operating system code that runs in kernel mode.
What are the sub-components of I/O manager in Windows NT?
Answer:
Network redirector/ Server
Cache manager.
File systems
Network driver
Device driver
What are DDks? Name an operating system that includes this feature.
Answer:
DDks are device driver kits, which are equivalent to SDKs for writing device drivers.
Windows NT includes DDks.
What level of security does Windows NT meets?
Answer:
C2 level security.
All devices are represented by files called special files that are located in/dev
directory. Thus, device files and other files are named and accessed in the same
way. A 'regular file' is just an ordinary data file in the disk. A 'block special file'
represents a device with characteristics similar to a disk (data transfer in terms of
blocks). A 'character special file' represents a device with characteristics similar to a
keyboard (data transfer is by stream of bits in sequential order).
What is 'inode'?
Answer:
All UNIX files have its description stored in a structure called 'inode'. The inode contains
info about the file-size, its location, time of last access, time of last modification,
permission and so on. Directories are also represented as files and have an associated
inode. In addition to descriptions about the file, the inode contains pointers to the data
blocks of the file. If the file is large, inode has indirect pointer to a block of pointers to
additional data blocks (this further aggregates for larger files). A block is typically 8k.
Inode consists of the following fields:
File owner identifier
File type
File access permissions
File access times
Number of links
File size
Location of the file data
Brief about the directory representation in UNIX
Answer:
A Unix directory is a file containing a correspondence between filenames and inodes. A
directory is a special file that the kernel maintains. Only kernel modifies directories, but
processes can read directories. The contents of a directory are a list of filename and
inode number pairs. When new directories are created, kernel makes two entries named
'.' (refers to the directory itself) and '..' (refers to parent directory). System call for
creating directory is mkdir (pathname, mode).
What are the Unix system calls for I/O?
Answer:
open(pathname,flag,mode) - open file
creat(pathname,mode) - create file
close(filedes) - close an open file
read(filedes,buffer,bytes) - read data from an open file
write(filedes,buffer,bytes) - write data to an open file
lseek(filedes,offset,from) - position an open file
dup(filedes) - duplicate an existing file descriptor
dup2(oldfd,newfd) - duplicate to a desired file descriptor
fcntl(filedes,cmd,arg) - change properties of an open file
ioctl(filedes,request,arg) - change the behaviour of an open file
The difference between fcntl anf ioctl is that the former is intended for any open file, while the latter is for device-specific operations.
How do you change File Access Permissions?
Answer:
Every file has following attributes:
owner's user ID ( 16 bit integer )
owner's group ID ( 16 bit integer )
File access mode word
'r w x -r w x- r w x'
(user permission-group permission-others permission)
r-read, w-write, x-execute
A simple generic use case for a "file open" operation might look like:
Open File
Summary: A user performs this task in order to view a document. The user specifies a
filename and the document is opened in a new window.
Steps:
1. Scan item's bar code and 2. Display confirmation that the loan is
borrower's library card. allowed, give due date.
3. Stamp item with the due date.
4. Click "OK" to check out item to 5. Record the loan and display confirmation
borrower. that record has been made.
a bunch of more exotic use case diagram items, namely actors and use
cases that use or extend other actors and use cases.
Class Diagrams
Class diagrams are the "meat and potatoes" of object-oriented analysis and
design. We will begin our discussion of them today, and continue next week. Class
diagrams describe more detailed, more implementation-oriented things than use
case diagrams.
Class diagrams can present varying levels of detail about the classes in them.
Some class diagrams may have nothing more than the class name for each class;
others may hold the full list of fields and methods. When more space is taken by
class details, there is room for fewer classes per diagram, so you often have
"overview diagrams" that show many classes and their connections,
supplemented by "detail diagrams" that show more information about closely
related classes.
Associations
Perhaps the main purpose for class diagrams is to identify and depict relationships
between objects that will be needed in the running system. An association is the word
we use for such a relationship. We draw a line between the rectangles for classes to
depict an assocation. There are three major types of associations:
inheritance
aggregation
user defined
Inheritance: the Un-Association
We have discussed how inheritance is not really an association, it is a relationship
between kinds of things, in the design and maybe in the programming language type
system, whereas associations are relationships between instances (objects) at run-
time. Inheritance is so vital that many class diagrams focus specifically on a large
inheritance class hierarchy, similar to a biological taxonomy of species. Inheritance is
usually a static feature of a design, although there exist languages in which instances
can change who they inherit from at runtime.
2 4 5 12 16 19 22 26 29 32 37 41 46 50
2
2 4 5 12 16 19 22 26 29 32 37 41 46 50
3
2 4 5 12 16 19 22 26 29 32 37 41 46 50
Notes on Binary Searches
List must be ordered (sorted)
can maintain a list in ordered fashion
68 98 83 74 93
68 74 83 98 93
68 74 83 98 93
68 74 83 93 98 SORTED!
Selection Sort
Sorts in ascending order
68 98 83 74 93
68 83 98 74 93
68 74 83 98 93
68 74 83 93 98 SORTED!
Insertion Sort
Outer loop controls the index in the array of the
next value to be inserted
68 98 83 74 93
68 83 98 74 93
68 83 74 98 93
68 83 74 93 98
68 74 83 93 98 SORTED!
Sort Implementations
All three use double (nested) loops
Bubble
an outer loop repeats until no swaps are needed
an inner loops scans and swaps as needed
Sorting
Things To Know
Be able to recognize and follow an
insertion sort, selection sort, and bubble
sort
Understand their pros and cons
Know that many other sorts exist with
varying efficiency and programming
difficulty
Sorting animations (in Java of course!)
http://www.cs.hope.edu/~alganim/animator/Animator.html
Question
Given the operation of the following sort,
identify the type of sort (selection, insertion,
or bubble)
original
34 21 97 15 87
pass 1
21 34 97 15 87
pass 2
21 34 15 97 87
21 34 15 87 97 pass 3
21 15 34 87 97 pass 4
pass 5
15 21 34 87 97
SORTED
Question
Given the operation of the following
sort, identify the type of sort (selection,
insertion, or bubble)
original
34 21 97 15 87
pass 1
21 34 97 15 87
pass 2
21 34 97 15 87
pass 3
15 21 34 97 87
pass 4
15 21 34 87 97 SORTED
Sorting
Things Other Than Numbers
characters
same as integers (compare with < and >)
Strings
use the built-in compareTo method
Other Objects
we write a compareTo method
use the compareTo method
Recursion
An O(n2) method:
Complexity Analysis (cont.)
Examples:
A summation of array values has a best,
worst, and typical complexity of O(n).
Always visits every array element
A linear search:
Best case of O(1) element found on
first iteration
Worst case of O(n) element found on
last iteration
Complexity Analysis (cont.)
Bubble sort complexity:
Best case is O(n) when array already
sorted
Worst case is O(n2) array sorted in reverse
order
Average case is closer to O(n2).
Binary Search
Phase 1:
Quicksort (cont.)
Phase 1 (cont.):
Quicksort (cont.)
Phase 1 (cont.):
Quicksort (cont.)
Phase 1 (cont.):
Quicksort (cont.)
Phase 1 (cont.):
Quicksort (cont.)
Phase 1 (cont.):
Implementation:
Merge Sort
Recursive, divide-and-conquer
approach
Compute middle position of an array and
recursively sort left and right subarrays.
Merge sorted subarrays into single
sorted array.
Three methods required:
mergeSort: Public method called by
clients
Merge Sort (cont.)
Merge Sort (cont.)
Merge Sort (cont.)
Figure 10: Array list before copying list[3] into list[4], then list[2] into list[3]
Figure 11: Array list after copying list[3] into list[4], and then list[2] into list[3]
Insertion Sort Algorithm (Contd)
Hello World
#include statement makes libraries of
classes & functions accessible to the
program
Compile needs access to interface, what
the functions look like, but not the
implementation.
Documentation comments on codes
increase the readability. Cost of
maintenance is always higher than that of
development.
A More General C++ program
Functions
Reason: functions are
abstractions that help you
to reuse ideas and codes
make the code clearer,
more logical and
comprehensible
Functions
function prototyping: a description of the
types of arguments when declaring and
defining a function
void funct(float x, float y, float z);
Of course, you can choose not to have
any arguments, void funct(void)
Functions
Return values
Example
Execution and Flow
Execution of C++ program is organized
around statements
Statements execute sequentially
Or governed by control that repeats a
group of statement (loop). Eg. For, while..
Or selected one of several groups to
execute. (ifelse)
A statement executes, it cause other
statements to execute (function calls)
Pointers & Dynamic Data
Pointer Variable
Dereference Operator
More Example
Pointer & Array
Pointer and array are closely related in
C++
We can use a pointer to access the
elements of an array
Pointer & array
Pointer & Array
Pointers & Constants
When using a pointer, two objects are
involved: the pointer itself and the object
pointed to.
Consider the difference between pointer to
constant, constant pointer and constant
pointer to constant
Pointers & Constants
Pointers and Constants
Note that rr++ does not increment the reference rr (comparing with pointer),
rather, it is applied to an int that happens to be ii
Reference
Value of a reference cannot be changed
after initialization
Similar to a constant pointer (but cannot
be manipulated the way that a pointer is)
In the previous case, pp is a pointer and rr
is a reference to ii
Function Revisited
Usually, arguments are passed to function
as input for manipulation
Knowledge on pointers and references
can be employed
The manner that parameters are passed
to the function can lead to different results
Parameter Passing
Different ways to pass parameters into a
function
Pass-by-value, pass-by-address, and
pass-by reference
Ordinarily, arguments are passed by value
to a function a copy of the argument is
made inside the function
Pass-by-value
Pass-by-address
A pointer is passed instead of a value
Pointer acts as an alias to an outside
object
Any changes to the alias in the function
will be reflect to outside object
Pass-by-address
Pass-by-reference
C++ provide another way to pass an
address into a function reference
Similar to pass-by-address
The effect of the reference is that it
actually takes the address and passes it
in, rather than making a copy of the value
Pass-by-reference
Class
A tool for creating new types
Conveniently used as if the built-in type,
but user-defined
Derived classes and templates related
classes are organized in a specific way
according to their relationships
Remember: Class is an abstraction of a
group of objects, while an object is an
instance of the class
Class
Class
Class Member Functions
Functions declared within a class definition
Invoked only for a specific variable of the
appropriate type
Class Constructor
A special function for the initialization of
class objects
It has the same name as the class itself
Default or user-defined constructors
Class - Constructor
Class Access Control
Three keywords/categories: public, private
and protected
public means all member declarations
that follow are available to everyone
The private keyword, means that no one
can access that member except you, the
creator of the type, inside function
members of that type
Class Access Control
Protected acts just like Private, except
that it allow the inherited class to gain
access.
Example
Summary
Topics covered in this tutorial: Function,
Class, Pointer, Reference, etc
For more details, please refer to your
lecture notes ,texture book and references
Of course, I am looking forward to having
your feedback on the tutorials (for
example, Is there any interesting problem
that you want me to address in the tutorial)
This week's topics
Sorting
Selection, bubble, and insertion sort
Profiling and analyzing sort
algorithms
Searching
Linear search
Binary search
Sorting
Often useful and necessary to sort
information (alphabetical order, numerical
order)
Ordering of information helps the process
of evaluation, searching, and selecting
data.
What types of data do you know that is
typically sorted?
Simple sort algorithms are:
selection sort
bubble sort
insertion sort
Selection Sort
Given an unsorted array of numbers, sort them in order smallest to
largest
Algorithm:
Compare the first array element with the smallest of the remaining
elements. If the first element is larger, then swap them. Otherwise,
leave them alone.
When done, the first element in the array will be the smallest.
Repeat, starting with the second element of the array.
Repeat for entire array up to the next to last element.
Time
Parabola shape.
Double data
numbers results in four-
fold increase in
time.
Analyzing sort algorithms
Can also determine time by analyzing how many times
each array element is visited during search.
Number of visits for selection sort (n numbers): n2 +
5/2 n 3
As n gets bigger, fastest growing term is n2, so rest of
equation can be ignored.
Selection sort considered O(n2) algorithm - this is called
Big-Oh notation
Selection sort, Bubble sort, and Insertion sort are all
O(n2)algorithms
Searching
When there are a large number of items to search, it is often
necessary to have a strategy for finding a specific item.
What examples can you think of for searching out an item?
Does it help if the items are ordered or arranged?
Two simple searching techniques are the linear search and the
binary search.
Linear Search
A linear search looks through list from the beginning until it
encounters the desired item.
If the list is sorted, the search process can end when a value greater
than the one sought out is found.
int foundIt = -1;
for (int i = 0; i < array.length; i++)
{
if (array[i] == searchValue)
{
foundIt = i;
break; // out of for loop
}
}
// at this point, foundIt holds position of item or 1
Linear search is
O(?) algorithm
Binary Search
Divide and Conquer
A binary search assumes you start with a sorted list.
Algorithm:
The list is divided in half to find the mid-point.
Code for binary
At this mid-point, one of three states exist: search is in
BigJava pg. 652
1. You have found the item.
2. The item is less than the mid-point.
3. The item is greater than the mid-point.
If the value sought is not found, divide the remaining space in half
and find a new mid-point.
Repeat until you find the item or run out of space to divide.
Answer:0 0
This code is to show that preprocessor expressions are not the same as the
ordinary expressions. If a name is not known the preprocessor treats it to be
equal to zero.