Summer Training Report: Bachelor of Technology
Summer Training Report: Bachelor of Technology
Summer Training Report: Bachelor of Technology
Submitted in partial fulfilment of the requirements for the award of the degree
of
BACHELOR OF TECHNOLOGY
In
By
ANANT BHARDWAJ
42311502816
BACHELOR OF TECHNOLOGY
in
by
ANANT BHARDWAJ
42311502816
Guided by
Mr.Ankur Kumar
(Coding Mentor, Coding Ninjas)
DURATION-8 WEEKS
AT:
CODING NINJAS
FROM:
GUIDED BY:-
(Coding Mentor)
CANDIDATE’S DECLARATION
It is hereby certified that the work which is being presented in the B. Tech Major
Project Report entitled "JAVA WITH DATA STRUCTURES" in partial
fulfilment of the requirements for the award of the degree of Bachelor of
Technology and submitted in the Department of Electronics & Communication
Engineering of BHARATI VIDYAPEETH’S COLLEGE OF ENGINEERING,
New Delhi (Affiliated to Guru Gobind Singh Indraprastha University, Delhi) is an
authentic record of my own work carried out during a period from June 2018 to
August 2018 under the guidance of Mr.Ankur Kumar, Coding Mentor.
The matter presented in the B. Tech Major Project Report has not been submitted
by me for the award of any other degree of this or any other Institute.
ANANT BHARDWAJ
_________________________
ABSTRACT
The topic highlighted in report includes few algorithms & data structures
structure. It also consist of overview of few problems that were solved by
me during the duration of course and a game of tic tac toe was also
prepared.
The questions were solved and game was prepared using basic java
language & implementation of data structures wherever needed.
1 . JAVA
Java is a simple language that finds its application in wide range of
technologies which include anderoid, web development.
It is one of the basic language that is used for getting a good hold over data
structures.
2 . DATA STRUCTURES
A data structure is a particular way of organizing data in a computer so
that it can be used effectively. The idea is to reduce the space and time
complexities of different tasks.
The information and data given in the report is authentic to the best of my
knowledge. This Training Report is not submitted to any other university for award
of any other Degree, Diploma or Fellowship.
My sincere thanks and gratitude to Mr. Ankur Kumar for his valuable support
and guidance throughout my training.
ANANT BHARDWAJ
TABLE OF CONTENTS
1. CANDIDATE’S DECLARATION
2. CERTIFICATE
3. ABSTRACT
4. ACKNOWLEDGEMENT
5. TABLE OF CONTENTS
6. JAVA
7. DATA STRUCTURES
8. TIC TAC TOE
JAVA
Introduction
Java is one of the most popular programming languages in use, particularly for
client-server web applications. Programs written in Java have a reputation for
being slower and requiring more memory than those written in C++. The syntax of
Java is largely influenced by C++. Unlike C++, which combines the syntax for
structured, generic, and object-oriented programming, Java was built almost
exclusively as an object-oriented language.
Features of Java
Java is a platform independent language
Compiler present in editor Eclipse converts source code (.java file) to the byte
code(.class file). JVM executes the bytecode produced by compiler. This byte code
can run on any platform such as Windows, Linux, Mac OS etc. Which means a
program that is compiled on windows can run on Linux and vice-versa. Each
operating system has different JVM, however the output they produce after
execution of bytecode is same across all operating systems. That is why we call
java as platform independent language.
Java is an Object Oriented language
Object oriented programming is a way of organizing programs as collection of
objects, each of which represents an instance of a class.
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism
Simple
Java is considered as one of simple language because it does not have complex
features like Operator overloading, Multiple inheritance, pointers and Explicit
memory allocation.
Robust Language
Robust means reliable. Java programming language is developed in a way that
puts a lot of emphasis on early checking for possible errors, that’s why java
compiler is able to detect errors that are not easy to detect in other programming
languages. The main features of java that makes it robust are garbage collection,
Exception Handling and memory allocation.
Secure
We don’t have pointers and we cannot access out of bound arrays (you get
ArrayIndexOutOfBoundsException if you try to do so) in java. That’s why several
security flaws like stack corruption or buffer overflow is impossible to exploit in
Java.
Java is distributed
Using java programming language we can create distributed applications.
RMI(Remote Method Invocation) and EJB(Enterprise Java Beans) are used for
creating distributed applications in java. In simple words: The java programs can
be distributed on more than one systems that are connected to each other using
internet connection. Objects on one JVM (java virtual machine) can execute
procedures on a remote JVM.
Multithreading
Java supports multithreading. Multithreading is a Java feature that allows
concurrent execution of two or more parts of a program for maximum utilisation
of CPU.
Portable
Java code that is written on one machine can run on another machine. The
platform independent byte code can be carried to any platform for execution that
makes java code portable.
o Object
o Class
o Inheritance
o Polymorphism
o Abstraction
o Encapsulation
Object
Any entity that has state and behavior is known as an object. For example a chair,
pen, table, keyboard, bike, etc. It can be physical or logical.
Example: A dog is an object because it has states like color, name, breed, etc. as
well as behaviors like wagging the tail, barking, eating, etc.
Class
Collection of objects is called class. It is a logical entity.
A class can also be defined as a blueprint from which you can create an individual
object. Class doesn't consume any space.
Inheritance
When one object acquires all the properties and behaviors of a parent object, it is
known as inheritance. It provides code reusability. It is used to achieve runtime
polymorphism.
Polymorphism
If one task is performed by different ways, it is known as polymorphism. For
example: to convince the customer differently, to draw something, for example,
shape, triangle, rectangle, etc.
Abstraction
Encapsulation
Binding (or wrapping) code and data together into a single unit are known as
encapsulation. For example capsule, it is wrapped with different medicines.
A java class is the example of encapsulation. Java bean is the fully encapsulated
class because all the data members are private here.
Application
According to Sun, 3 billion devices run Java. There are many devices where Java
is currently used. Some of them are as follows:
Data Structures are the main part of many computer science algorithms as they
enable the programmers to handle the data in an efficient way. It plays a vitle
role in enhancing the performance of a software or a program as the main
function of the software is to store and retrieve the user's data as fast as possible
Basic Terminology
Data structures are the building blocks of any program or the software.
Choosing the appropriate data structure for a program is the most difficult task
for a programmer. Following terminology is used as far as data structures are
concerned
Data: Data can be defined as an elementary value or the collection of values, for
example, student's name and its id are the data about the student.
Group Items: Data items which have subordinate data items are called Group
item, for example, name of a student can have first name and the last name.
Record: Record can be defined as the collection of various data items, for
example, if we talk about the student entity, then its name, address, course and
marks can be grouped together to form the record for the student.
File: A File is a collection of various records of one type of entity, for example,
if there are 60 employees in the class, then there will be 20 records in the related
file where each record contains the data about each employee.
Attribute and Entity: An entity represents the class of certain objects. it
contains various attributes. Each attribute represents the particular property of
that entity.
Processor speed: To handle very large amout of data, high speed processing is
required, but as the data is growing day by day to the billions of files per entity,
processor may fail to deal with that much amount of data.
Linear Data Structures: A data structure is called linear if all of its elements
are arranged in the linear order. In linear data structures, the elements are stored
in non-hierarchical way where each element has the successors and predecessors
except the first and last element.
The elements of array share the same variable name but each one carries a
different index number known as subscript. The array can be one dimensional,
two dimensional or multidimensional.
Linked List: Linked list is a linear data structure which is used to maintain a list
in the memory. It can be seen as the collection of nodes stored at non-contiguous
memory locations. Each node of the list contains a pointer to its adjacent node.
Stack: Stack is a linear list in which insertion and deletions are allowed only at
one end, called top.
Queue: Queue is a linear list in which elements can be inserted only at one end
called rear and deleted only at the other end called front.
Non Linear Data Structures: This data structure does not form a sequence i.e.
each item or element is connected with two or more other items in a non-linear
arrangement. The data elements are not arranged in sequential structure.
Tree data structure is based on the parent-child relationship among the nodes.
Each node in the tree can have more than one children except the leaf nodes
whereas each node can have atmost one parent except the root node. Trees can
be classfied into many categories which will be discussed later in this tutorial.
If the size of data structure is n then we can only insert n-1 data elements into it.
4) Searching: The process of finding the location of an element within the data
structure is called Searching. There are two algorithms to perform searching,
Linear Search and Binary Search. We will discuss each one of them later in this
tutorial.
6) Merging: When two lists List A and List B of size M and N respectively, of
similar type of elements, clubbed or joined to produce the third list, List C of
size (M+N), then this process is called merging
Algorithm
An algorithm is a procedure having well defined steps for solving a particular
problem. Algorithm is finite set of logic or instructions, written in order for
accomplish the certain predefined task. It is not the complete program or code, it is
just a solution (logic) of a problem, which can be represented either as an informal
description using a Flowchart or Pseudo code.
Characteristics of an Algorithm
An algorithm must follow the mentioned below characteristics:
Array
Definition
o Arrays are defined as the collection of similar type of data items stored at
contiguous memory locations.
o Arrays are the derived data type in C programming language which can store
the primitive type of data such as int, char, double, float, etc.
o Array is the simplest data structure where each data element can be
randomly accessed by using its index number.
o For example, if we want to store the marks of a student in 6 subjects, then
we don't need to define different variable for the marks in different subject.
instead of that, we can define an array which can store the marks in each
subject at a the contiguous memory locations.
Following example illustrates, how array can be useful in writing code for a
particular problem.
In the following example, we have marks of a student in six different subjects. The
problem intends to calculate the average of all the marks of the student.
In order to illustrate the importance of array, we have created two programs, one is
without using array and other involves the use of array to store marks.
Advantages of Array
o Array provides the single name for the group of variables of the same type
therefore, it is easy to remember the name of all the elements of an array.
o Traversing an array is a very simple process, we just need to increment the
base address of the array in order to visit each element one by one.
o Any element in the array can be directly accessed by using the index.
1. 0 (zero - based indexing) : The first element of the array will be arr[0].
2. 1 (one - based indexing) : The first element of the array will be arr[1].
3. n (n - based indexing) : The first element of the array can reside at any
random index number.
In the following image, here is shown the memory allocation of an array arr of size
5. The array follows 0-based indexing approach. The base address of the array is
100th byte. This will be the address of arr[0]. Here, the size of int is 4 bytes
therefore each element will take 4 bytes in the memory.
Linked List
o Linked List can be defined as collection of objects called nodes that are
randomly stored in the memory.
o A node contains two fields i.e. data stored at that particular address and the
pointer which contains the address of the next node in the memory.
o The last node of the list contains pointer to the null.
1. The size of array must be known in advance before using it in the program.
2. Increasing size of the array is a time taking process. 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 any element in the array needs shifting of all its predecessors.
Linked list is the data structure which can overcome all the limitations of an array.
Using linked list is useful because,
1. It allocates the memory dynamically. All the nodes of linked list are non-
contiguously stored in the memory and linked together with the help of
pointers.
2. Sizing is no longer a problem since we do not need to define its size at the
time of declaration. List grows as per the program's demand and limited to
the available memory space.
One way chain or singly linked list can be traversed only in one direction. In other
words, we can say that each node contains only next pointer, therefore we can not
traverse the list in the reverse direction.
Consider an example where the marks obtained by the student in three subjects are
stored in a linked list as shown in the figure.
In the above figure, the arrow represents the links. The data part of every node
contains the marks obtained by the student in the different subject. The last node in
the list is identified by the null pointer which is present in the address part of the
last node. We can have as many elements we require, in the data part of the list.
A doubly linked list containing three nodes having numbers from 1 to 3 in their
data part, is shown in the following image.
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. We can have circular singly linked list as well as circular doubly
linked list.We traverse a circular singly linked list until we reach the same node
where we started. The circular singly liked list has no beginning and no ending.
There is no null value present in the next part of any of the nodes.
Stack
1. Stack is an ordered list in which, insertion and deletion can be performed
only at one end that is called top.
2. Stack is a recursive data structure having pointer to its top element.
3. Stacks are sometimes called as Last-In-First-Out (LIFO) lists i.e. the element
which is inserted first in the stack, will be deleted last from the stack.
Applications of Stack
1. Recursion
2. Expression evaluations and conversions
3. Parsing
4. Browsers
5. Editors
6. Tree Traversals
Operations on Stack
There are various operations which can be performed on stack.
Queue
1.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.
Applications of Queue
Due to the fact that queue performs actions on first in first out basis which is
quite fair for the ordering of actions. There are various applications of queues
discussed as below.
1. Queues are widely used as waiting lists for a single shared resource like
printer, disk, CPU.
2. Queues are used in asynchronous transfer of data (where data is not being
transferred at the same rate between two processes) for eg. pipes, file IO,
sockets.
3. Queues are used as buffers in most of the applications like MP3 media
player, CD player, etc.
4. Queue are used to maintain the play list in media players in order to add
and remove the songs from the play-list.
5. Queues are used in operating systems for handling interrupts.
Tree
o A Tree is a recursive data structure containing the set of one or more data
nodes where one node is designated as the root of the tree while the
remaining nodes are called as the children of the root.
o The nodes other than the root node are partitioned into the non empty sets
where each one of them is to be called sub-tree.Nodes of a tree either
maintain a parent-child relationship between them or they are sister nodes.
o In a general tree, A node can have any number of children nodes but it can
have only a single parent.
o The following image shows a tree, where the node A is the root node of the
tree while the other nodes can be seen as the children of A.
Basic terminology
o Root Node :- The root node is the topmost node in the tree hierarchy. In
other words, the root node is the one which doesn't have any parent.
o Sub Tree :- If the root node is not null, the tree T1, T2 and T3 is called sub-
trees of the root node.
o Leaf Node :- The node of tree, which doesn't have any child node, is called
leaf node. Leaf node is the bottom most node of the tree. There can be any
number of leaf nodes present in a general tree. Leaf nodes can also be called
external nodes.
o Path :- The sequence of consecutive edges is called path. In the tree shown
in the above image, path to the node E is A→ B → E.
o Ancestor node :- An ancestor of a node is any predecessor node on a path
from root to that node. The root node doesn't have any ancestors. In the tree
shown in the above image, the node F have the ancestors, B and A.
o Degree :- Degree of a node is equal to number of children, a node have. In
the tree shown in the above image, the degree of node B is 2. Degree of a
leaf node is always 0 while in a complete binary tree, degree of each node is
equal to 2.
o Level Number :- Each node of the tree is assigned a level number in such a
way that each node is present at one level higher than its parent. Root node
of the tree is always present at level 0.
TTT() {
super("Tic Tac Toe");
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(640, 640);
setResizable(false);
GridLayout grid = new GridLayout(BOARD_SIZE, BOARD_SIZE);
setLayout(grid);
board = new JButton[BOARD_SIZE][BOARD_SIZE];
for (int i = 0; i < BOARD_SIZE; i++) {
for (int j = 0; j < BOARD_SIZE; j++) {
board[i][j] = new JButton();
board[i][j].setFont(new Font("Times New Roman", 1, 225));
add(board[i][j]);
}
}
startGame();
}
If 0 wins
REFERENCES
3.Internet