Datastructue and Software Eng
Datastructue and Software Eng
Each element in an array is of the same data type and carries the same size that is
4 bytes.
A very important limitation of primitive data types is the fact that values cannot
be stored in contiguous memory locations. This problem is solved by using arrays,
in which the Java array occupies dynamic memory in which individual elements are
stored in contiguous locations, one after the other.
Disadvantages
it is impossible to declare array withoud knowning the size of array.
class Testarray1{
public static void main(String args[]){
int arr[]={33,3,4,5};
//printing array using for-each loop
for(int i:arr)
System.out.println(i);
}}
Declare Array:-
int a[]=new int[5];
triverse in array
class triverse{
public static void main(String args[]){
int arr[5]={18,30,15 ,70,12};
int i;
for(i=0, i<5; i++){
System.out.println(arr[i]);
}
}
}
a[pos-1]=x;
System.out.println("After inserting");
for(int i=0; i<n; i++){
Sytem.out.print(a[i])
}
}
}
------------------------------------------------------------
n=(size of array)
if(flag==1)
{
for(int i=loc+1; i<n; i++){
a[i-1]=a[i];
}
System.out.print("After deleting")
for(int i=0; i<n-2; i++)
{
Sytstm.out.println(a[i])
}
else{
System.out.println("Element not found");
}
}
}
------------------------------------------------------------
We read the linear data structures like an array, linked list, stack and queue in
which all the elements are arranged in a sequential manner.
------------------------------------------------------------
DS Linked List
Linked list is a linear data structure that includes a series of connected nodes.
Why use linked list over array?
1.The size of the array must be known in advance before using it in the program.
2. It is almost impossible to expand the size of the array at run time.
3.All the elements in the array need to be contiguously stored in the memory.
Inserting an element in the array needs shifting of all its predecessors.
Singly-linked list
Doubly linked list
Circular singly link list
Circular doubly linked lis
Singly-linked list -A node in the singly linked list consists of two parts: data
part and link part. Data part of the node stores actual information that is to be
represented by the node, while the link part of the node stores the address of its
immediate successor.
Doubly linked list - in which a node contains a pointer to the previous as well as
the next node in the sequence.
Circular singly linked list - In a circular singly linked list, the last node of
the list contains a pointer to the first node of the list.
Circular doubly linked list - in which a node contains pointers to its previous
node as well as the next node. Circular doubly linked list doesn't contain NULL in
any of the nodes. The last node of the list contains the address of the first node
of the list. The first node of the list also contains the address of the last node
in its previous pointer.
Applications:-
1.dynamic memory alocation;
2.memory alocation done at run time
3.The various operations like student's details, employee's details, or product
details can be implemented using the linked list as the linked list uses the
structure data type that can hold different data types.
------------------------------------------------------------
DS Stack
A Stack is a linear data structure that follows the LIFO (Last-In-First-Out)
principle.
a stack can be defined as a container in which insertion and deletion can be done
from the one end known as the top of the stack.
A Stack is an abstract data type with a pre-defined capacity, which means that it
can store the elements of a limited size.
It is a data structure that follows some order to insert and delete the elements,
and that order can be LIFO or FILO.
Common operations
push(),pop(),isEmpty(),isFull(),peek(),count(),change(),display()
Application:
UNDO/REDO,DFS,Backtracking,
Expression Conversion(infix to prefix,infix to postfix)
memory management(all the variables are assigned to a function call stack
memory.when the fun completed its execution, all the variables assigned in the
stack are released).
------------------------------------------------------------
DS Queue
A queue can be defined as an ordered list which enables insert operations to be
performed at one end called REAR and delete operations to be performed at another
end called FRONT.Queue is referred to be as First In First Out list.
Applications of Queue
queue are widely used as waiting lists for a single shared resource like printer,
disk ,CPU;
queue are used as buffers in most of the applications like MP3 media player,CD
player etc maintain the play list in media players in order to add and remove the
songs from the play list
Queue are used in operating system for handling interrupts
------------------------------------------------------------
Some factors are considered for choosing the data structure:
What type of data needs to be stored?:
Cost of operations:
Memory usage:
------------------------------------------------------------
Tree data structure
A tree data structure is a non-linear data structure because it does not store in a
sequential manner. It is a hierarchical structure as elements in a Tree are
arranged in multiple levels.
In the Tree data structure, the topmost node is known as a root node. Each node
contains some data, and data can be of any type.
Each node contains some data and the link or reference of other nodes that can be
called children.
Applications of trees
Storing naturally hierarchical data:
Organize data:
Routing table:
types
1.Binary tree: each node in a tree can have utmost two child nodes
2.Binary Search tree:in which one node is connected to n number of nodes. It is a
node-based data structure.
Varients of binary search tree:
1.AVL tree:It is a self-balancing binary search tree
2.Splay tree: recently accessed element is placed at the root position of tree by
performing some rotation operations.
------------------------------------------------------------
Software Eng
------------------------------------------------------------
Software :-The term software specifies to the set of computer programs, procedures
and associated documents (Flowcharts, manuals, etc.) that describe the program and
how they are to be used.
types of requirements:-
Functional Requirements
Technical Requirements
Transitional Requirements
Operational Requirements
------------------------------------------------------------
SDLC MODELS
Waterfall model
prototype model
RAD Model
spiral model
Agile model
iterative model
1.Water fall model:-when the requirements are constant and not changed regularly.A
project is short.The situation is calm.tool and technology used is consistent and
is not changing.