Está en la página 1de 4

Q1. Identify real life situations for data structures.

(a)Queues (b) Stack (c) Linked –List

Ans-:

Real life situations for Queues are -:

 People entering in a temple in a queue.


 Children walking one after other in a school for their assembly.

Real life situations for Linked Lists are -:

 A linked list can be compared with a necklace. When we find that we don't like any of the jewel
anymore, we take it out of the sequence and tie the resulting two ends together. There is no need
to loop through each pearl and displace it just so you can fix your necklace.
 It is used in operating systems. One may use a linked list to keep track of what processes are
running and what processes are sleeping. A process that is running and wants to sleep gets
removed from the Linked List that keeps track of running processes and once the sleep time is
over adds it back to the active process Linked List

Real life situations for Stacks are -:

 Cars parked in a parking at mall or cars at garage.


 Shuttle cock in its box.

Q2. Write an algorithm to search a second highest element in Multidimensional Array.


Ans-:
 Set M =1, N1=N2=A [0]

 Repeat steps 3 4 5 while M<=N

 if N1<A[M]

 Set N2=N1 and N1=A [M]

o else if N2<A[M] and N1>A[j] or N1=N2

 Set N2=a [M]


 Set M=M+1

 (End of loop 2)

 Print N2

 Exit

Q3. Consider the following multidimensional arrays


A (-5:5, 3:33) B (3:10, 1:15, 10:20)
(a) Find the length of each dimension and number of elements in A
and B
(b)Suppose Base (B) =4000 and there are w=4 words per memory
location. Find the effective indices E1, E2, E3 and the address of
B[8, 4, 17] .You have to find the address for Row-Major order and
also fro Column Major order.

Ans-:(a) As A [-5:5, 3:33]


• Now for the above given array A we calculate length of the two dimensions as follows:
• Length = upper bound – lower bound +1
• So L1= 5 – (-5) +1=11 and L2 = 33=3+1 =31 respectively.
• So the array A contains L1.L2=11.31=341 elements.

As B [3:10, 1:15, 10:20]


• Now for the above given array B we calculate length of all the three dimensions as follows:
• So L1= 10-3+1 = 8 L2=15-1+1 =15 L3=20-10+1= 11 respectively.
• So the array B contains L1.L2.L3= 8.15.11=1320 elements.

(b) We are given BASE(B)=4000


• The effective indices for B[8,4,17] are
• E1= 8-3 = 5 E2=4-1 = 3 E3=17-10 =7respectively.
The address depends on whether the programming language stores B in row major order or
column major order.

• For column major order


• E3L2= 7.15 = 105 E3L2+E2 = 105 + 3 = 108
• (E3L2 + E2)L1 = 108.8 = 864 (E3L2 + E2)L1 +E1 = 864 + 5 = 869
• Therefore LOC (B [8.4.17]) = 4000 + 4(869) = 7476.

• For row major order


• E1L2= 5.15=75 E1L2 + E2= 75+3 =78
• (E1L2+ E2)L3=78.11=858 [(E1L2+E2)L3]+E3= 858+7=865.
• Therefore LOC(B[8,4,17]) = 4000 +4(865) = 7460.
Q4. Can we design a new data structure? What will be the steps followed for the generation, analyze
those steps ?

Ans-: Yes, we can create a new data structure. It depends on the user how to make programming code
there are various steps that can result into creation of a new data structure.

The steps are -:


• Logical or mathematical description of the structure i.e. making an alogorithm of our problem or
the source code that we will use so as to control the error and less time is assumed by d compiler
and check that how much the memory is used.
• Implementation of the structure on a computer i.e. giving a trial to our source code by the
compiler and checks for the error.
• Quantitative analysis of the structure, which includes determining the amount of memory needed
to store the structure and the time required to process the structure.

Q5. Compare and contrast the Arrays and pointer Arrays. How record structures are accessed by the use
of pointer Arrays?

Ans-: A pointer is an address in memory where a variable is located. An array is a conceptual data
representation consisting of a list of more than one item of a particular scalar type (int, float, char,
structure, etc.) where each element is accessed by its index. The index can be thought of as a counter or
enumerator telling you how many elements you have to skip over to get to the one you're interested in.
Here's where addresses come in ... the location of a particular element in memory is offset from the so-
called base address (i.e. the address of the starting element) by the value (sizeof(one element) * index #)
The C compiler is smart enough to take the sizeof() into account when you do pointer arithmetic, so you
can find the address of the i-th element as (address of base) + i, rather than having to do the multiplication
explicitly. The idea of element address as offset also accounts for C's use of zero-relative array
definitions. Since the first element is offset by 0 positions from the first element its index in C is 0, not 1.
The second (ordinal) element is offset from the first by 1 position so its index is 1, and so on.

Record structures are accessed by the use of pointer Arrays as Computing applications often need data of
different kinds to be associated. A typical place where this occurs is in a record. For example a database
record for a particular student might contain the student number, full name, course-code and year of entry.

struct bank
{
char name[25];
char branch[100];
char acc no[16];
int year_established;
};

Q6. Which function grows faster?


nlogn or lognn
Ans-:

g(n)
log n n log nⁿ n log n
n

5 3 5 243 124

10 4 10 10⁶ 10⁴

100 7 100 10⁸3 10⁷

1000 10 103 101000 1030

From above table we find that g(n)= log nⁿ grows faster than g(n)= n log n

También podría gustarte