0% found this document useful (0 votes)
73 views

Introduction PDF

The document discusses the need for data structures to efficiently organize and store data. It introduces common problems like slow data search times that data structures address. The objective is to learn fundamental data structure concepts and algorithms. It discusses using Eclipse as an IDE for developing Java programs and running them using the JDK. It also provides details about Udemy courses for teaching data structures and algorithms using Java.

Uploaded by

Sanchit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Introduction PDF

The document discusses the need for data structures to efficiently organize and store data. It introduces common problems like slow data search times that data structures address. The objective is to learn fundamental data structure concepts and algorithms. It discusses using Eclipse as an IDE for developing Java programs and running them using the JDK. It also provides details about Udemy courses for teaching data structures and algorithms using Java.

Uploaded by

Sanchit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

1.

INTRODUCTION

1.1 Need & Objective:

The needs of data structures include the following:

Efficiency, Reusability, and Invisibility.


Data structure provides a means of organizing, managing, and storing data efficiently.
It also includes the collection of data as well as the operations that can be applied to
that data.
As applications are getting complex and data rich, there are three common problems
that applications face now-a-days.

Data Search − Consider an inventory of 1 million(106) items of a store. If the


application is to search an item, it has to search an item in 1 million(106) items every
time slowing down the search. As data grows, search will become slower.
Processor speed − Processor speed although being very high, falls limited if the data
grows to billion records.
Multiple requests − As thousands of users can search data simultaneously on a web
server, even the fast server fails while searching the data.

To solve the above-mentioned problems, data structures come to rescue. Data can be
organized in a data structure in such a way that all items may not be required to be
searched, and the required data can be searched almost instantly.

Objective of Course:
To impart the basic concepts of data structures and algorithms
To understand concepts about searching and sorting techniques
To Understand basic concepts about stacks,queues,lists,trees and graphs
To understanding about writing algorithms and step by step approach in solving
problems with the help of fundamental data structures

1
1.2 Software used

*ECLIPSE

Eclipse is an integrated development environment (IDE) used in computer


programming. It contains a base workspace and an extensible plug-in system for
customizing the environment. Eclipse is written mostly in Java and its primary use is
for developing Java applications, but it may also be used to develop applications in
other programming languages via plug-ins, including Ada, ABAP, C, C++, C#, Clojure,
COBOL, D, Erlang, Fortran, Groovy, Haskell, JavaScript, Julia, Lasso, Lua,
NATURAL, Perl, PHP, Prolog, Python, R, Ruby (including Ruby on Rails framework),
Rust, Scala, and Scheme. It can also be used to develop documents with LaTeX (via a
TeXlipse plug-in) and packages for the software Mathematica. Development
environments include the Eclipse Java development tools (JDT) for Java and Scala,
Eclipse CDT for C/C++, and Eclipse PDT for PHP, among others.

Here we run java program in eclipse using JDK.

The JDK is a key platform component for building Java applications. At its heart is the
Java compiler

The Java Development Kit (JDK) is one of three core technology packages used in Java
programming, along with the JVM (Java Virtual Machine) and the JRE (Java Runtime
Environment). It's important to differentiate between these three technologies, as well
as understanding how they're connected:

- The JVM is the Java platform component that executes programs.


- The JRE is the on-disk part of Java that creates the JVM.
- The JDK allows developers to create Java programs that can be executed and
run by the JVM and JRE.

Developers new to Java often confuse the Java Development Kit and the Java Runtime
Environment. The distinction is that the JDK is a package of tools for developing Java-

2
based software, whereas the JRE is a package of tools for running Java code.

The JRE can be used as a standalone component to simply run Java programs, but it's
also part of the JDK. The JDK requires a JRE because running Java programs is part of
developing them.

1.3 About Organization

*UDEMY:

They’ve kept a single goal declaration to not let the emphasis


be scattered, but a goal can never be clearly expressed without clearly defined and
measurable metrics. Here are a few metrics we will hold ourselves against

1. There students becoming smart enough to be coveted by the best IT firms –


the Microsoft’s, Apples, Google, Facebook’s, Oracles and Amazons - across
India and globe.
2. There students becoming smart enough to win the best coding competitions
world – ICPC, Code jams and Hacker cups.
3. There students ushering in the next wave of Indian start-ups – I’ll wish to
believe that my students have enough raw talent to one day build companies
like Google’s and Microsoft’s, and I’ve enough talent to teach them the self-
belief which will take them there.

It doesn’t matter whether the above will take 1 year, 5 years, 10 years or the entire
life. They’ll love to die on their work-desk working for the goals and metrics
mentioned above.

The way the divide their course it’s also very good for students, and students can get
course according to their own prior knowledge.

I enrolled for the Data Structure and Algorithms: Deep Dive using Java at
Udemy in July 2021 and I loved the course so much. These courses have helped me

3
build my basics of Data Structure and Algorithm. It was only after joining this Course
that I started competitive coding. The study material and class are incredible

1.4 SOFTWARE TRAINING WORK UNDERTAKEN

❖ PURPOSE
• Are necessary for design of efficient algorithms
• It built our logical mind to solve real world problems
• It will give us more knowledge about how we optimise our code
that it run in minimum time and space complexity
• Most important almost every company in India 80% focus on
DS-Algo

2.2 LANGUAGE USED:-

*JAVA:
In my project, I have chosen Java language for developing the code.

About Java

Initially the language was called as “Oak” but it was renamed as “Java” in
1995. The primary motivation of this language was the need for a platform-independent
(i.e., architecture neutral) language that could be used to create software to be
embedded in various consumer electronic devices.

• Java is a programmer’s language.


• Except for those constraints imposed by the internet environment, Java gives
the programmer, full control.
• Finally, java is to internet programming where C was to system programming.

Importance of Java to the Internet

Java has had a profound effect on the Internet. This is because, Java expands
the Universe of objects are transmitted between the Server and the Personal Computer.

4
They are: Passive information and Dynamic active programs. The Dynamic, Self-
executing programs cause serious problems in the areas of Security and probability.
But, Java addresses those concerns and by doing so, has opened the door to an exciting
new form of program called Applet.

Java can be used create two types of programs

Applications and Applets: An application is a program that runs on our


Computer under the operating system of that computer. It is more or less like one
creating using C or C++. Java’s ability to create Applets makes it important. An Applet
is an application designed to be transmitted over the Internet and executed by a Java-
compatible web browser.

And applet is actually a tiny Java program, dynamically downloaded across the
network, just like an image. But the difference is, it is intelligent program, not just a
media file. It can react to the user input and dynamically change.

Features of java

• Security

Every time you that you download a “normal” program; you are risking a viral
infection. Prior to Java, most users did not download executable programs frequently,
and those who did scan them for viruses prior to execution. Most users still worried
about malicious program exists that must be guarded against. This type of program can
gather private information. Such as credit card numbers, bank account balances, and
passwords. Java answers the both of these concerns by providing a “firewall” between
a networked application and your computer.

• Portability

For programs to be dynamically downloaded to all the various types of


platforms connected to the Internet, some means of generating portable executable code
is needed as you will see the same mechanism that helps ensure security also helps

5
create portability. Indeed, Java’s solution to these two problems is both elegant and
efficient.

• The Byte code

The key that allows the Java to solve the security and portability problems is
that the output of Java compiler is Byte code. Byte code is a highly optimized set of
instructions designed to be executed by the Java run-time system, which is called the
Java Virtual Machine (JVM). That is, in its standard form, the JVM is an interpreter
for byte code. Translating a java program into byte code helps makes it much easier to
run a program in a wide variety of environments. The reason is, once the run-time
package exists for a given system, any Java program can run on it.

Although Java was designed for interpretation, there is technically nothing


about Java that prevents on-the-fly compilation of byte code into native code. Sun has
just completed its Just In Time (JIT) compiler for byte code. When the JIT compiler is
a part of JVM, it compiles byte code into executable code in real time, on a piece –by-
piece, all at once, because Java performs various run-time checks that can be done only
at run Java Virtual Machine (JVM).

Beyond the language, there is the Java virtual machine. The java virtual
machine is an important element of the java technology. The virtual machine can be
embedded within a web browser or an operating system. Once a piece of Java code is
loaded onto a machine, it is verified. As part of the loading process, a class loader is
invoked and does byte code verification makes sure that the code that’s has been
generated by the compiler will not corrupt the machine that it’s loaded on. Byte code
verification takes place at the end of the compilation process to make sure that is all
accurate and correct. So byte code verification is integral to the compiling and
executing of Java code

Article II: Java Java Java


Javac
Byte Code Virtual Machine
Article III: Source
.java .class

Figure: Development process of java programmin

6
• Java Architecture

Java architecture provides a portable, robust, high performing environment for


development. Java provides portability by compiling the byte codes for the Java Virtual
Machine, which is then interpreted on each platform by the run-time environment. Java
is a dynamic system, able to load code when needed from a machine in the same room
or across the planet.

• Compilation of code:

When you compile the code, the Java compiler creates machine code (called
byte code) for a hypothetical machine called Java Virtual Machine (JVM). The JVM
is supposed to execute the byte code. The JVM is created for overcoming the issue of
portability. The code is written and compiled for on machine and interpreted on all
machines. This machine is called Java Virtual Machine.

• Compiling and interpreting Java Source Code

PC Java
Compiler Interpreter
(PC)

Source Java
Code Byte Code
…………..
………
……………
…….. (Platform
…………… (Independ
…….. Macintosh
ent) Java
Compiler
…………… Interpre
…….. ter
……………. (Macint

SPARC Java
Compil Interpr
er eter
(Sparc)

7
During run-time the Java interpreter tricks the byte code file into thinking that it is
running on a Java Virtual Machine. In reality this could be a Inte3l Pentium Windows
95 or sun SARC station running Solaris or Apple Macintosh running system and all
could receive code from any computer through Internet and run the Applets.

• Simple

Java was designed to be easy for the Professional programmer to learn and to
se effectively. If you are an experienced C++ programmer, learning Java will be even
easier. Because Java inherits the C/C++ syntax and many of the object oriented features
of C++. Most of the confusing concepts from C++ are either left out of Java or
implemented in a cleaner, more approachable manner. In java there are a small number
of clearly defined ways to accomplish a given task.

• Object-Oriented

Java was not designed to be source code compatible with any other language.
This allowed the Java team the freedom to design with a blank slate. One outcome of
this was a clean usable, pragmatic approach to objects. The object model in java is
simple and easy to extend, while simple types, such as integers, are kept as high-
performance non-objects.

• Robust

The multi-platform environment of the Web places extraordinary demands on a


program, because the program must execute reliably in a variety of systems. The ability
to create robust programs was given a high priority in the design of Java. Java is strictly
typed language; it checks your code at compile time and runtime.

Java virtually eliminates the problems of memory management and


deallocation, which is completely automatic. In a well-written Java program, all run
time errors –can and should –be managed by your program

8
2. PROJECT WORK

• IMPLEMENTATION OF HASHMAP

Objective:-
Hash Map is a Map based collection class that is used
for storing Key & value pairs, it is denoted as Hash Map<Key, Value>
or Hash Map<K, V>. This class makes no guarantees as to the order of
the map. It is similar to the Hash table class except that it is
unsynchronized and permits nulls(null values and null key).

THEORY:-

In the ArrayList chapter, you learned that Arrays store items as


an ordered collection, and you have to access them with an index number (int type). A
HashMap however, store items in "key/value" pairs, and you can access them by an
index of another type (e.g. a String).

One object is used as a key (index) to another object (value). It can store different
types: String keys and Integer values, or the same type, like: String keys and String
values.

DECLERATION OF HASH MAP:-

Create a HashMap object called capitalCities that will store


String keys and String values:

import java.util.HashMap; // import the HashMap class


HashMap<String, String> capitalCities = new HashMap<String, String>();

9
METHOD OF HASHMAP:-

• ADD AN ITEM

The HashMap class has many useful methods. For example, to


add items to it, use the put() method:

public static void main(String[] args) {


HashMap<String, String> capitalCities = new HashMap<String, String>();
capitalCities.put("England", "London");
capitalCities.put("Germany", "Berlin");
System.out.println(capitalCities);
}

• Access an Item

To access a value in the HashMap, use the get() method and


refer to its key:

capitalCities.get("England");

• Remove an Item

To remove an item, use the remove() method and refer


to the key:

capitalCities.remove("England");

To remove all items, use the clear() method:

capitalCities.clear();

10
• HashMap Size

To find out how many items there are, use the size()
method:

capitalCities.size();

• Loop Through a HashMap

Loop through the items of a HashMap with a for-


each loop.

// Print keys
for (String i : capitalCities.keySet()) {
System.out.println(i);
}

for (String i : capitalCities.values()) {


System.out.println(i);
}

• Getting all value from set

.keySet() method in Java is used to create a set out of


the key elements contained in the hash map. It basically
returns a set view of the keys or we can create a new set
and store the key elements in them.

capitalCities.keySet();

11
• Checking for given key value:

.containsKey() method is used to check whether a


particular key is being mapped into the HashMap or not.
It takes the key element as a parameter and returns True
if that element is mapped in the map.

Parameters: The method takes just one parameter key element that refers to the key
whose mapping is supposed to be checked inside a map.

Return Value: The method returns boolean true if the presence of the key is
detected else false .

capitalCities.conatinsKey();

12
3. IMPLEMENTATION

• import java.io.*;
import java.util.*;

public class Main {

public static class HashMap<K, V> {


private class HMNode {
K key;
V value;

HMNode(K key, V value) {


this.key = key;
this.value = value;
}
}

private int size; // n


private LinkedList<HMNode>[] buckets; // N = buckets.length

public HashMap() {
initbuckets(4);
size = 0;
}

private void initbuckets(int N) {


buckets = new LinkedList[N];
for (int bi = 0; bi < buckets.length; bi++) {
buckets[bi] = new LinkedList<>();
}
}

13
private int findBucketIndex( K key ) throws Exception{
int hc = key.hashCode();
if( hc < 0 ){
hc = -hc;
}
int bi = hc % buckets.length;
return bi;
}

private int findInBucket( int bi, K key ) throws Exception{


int di = 0;
for( HMNode node : buckets[ bi ] ){
if( node.key.equals( key ) ){
return di;
}
di++;
}
return -1;
}

private void reShuffle() throws Exception{


LinkedList<HMNode>[] oldBuckets = buckets;
initbuckets( 2 * oldBuckets.length );
size = 0;
for( int bi = 0 ; bi < oldBuckets.length ; bi++ ){
for( HMNode node : oldBuckets[ bi ] ){
put( node.key, node.value );
}
}

public void put(K key, V value) throws Exception {


14
int bi = findBucketIndex( key );
int di = findInBucket( bi, key );

if( di == -1 ){
buckets[ bi ].add( new HMNode( key, value ) );
size++;
}else{
HMNode cnode = buckets[ bi ].get( di );
cnode.value = value;
}

// n / N
if( (( size * 1.0 ) / buckets.length) > 2.0 ){
reShuffle();
}
}

public V get(K key) throws Exception {

int bi = findBucketIndex( key );


int di = findInBucket( bi, key );

if( di == -1 ){
return null;
}else{
HMNode cnode = buckets[ bi ].get( di );
return cnode.value;
}
}

public boolean containsKey(K key) throws Exception{


int bi = findBucketIndex( key );
int di = findInBucket( bi, key );
15
if( di == -1 ){
return false;
}else{
return true;
}
}

public V remove(K key) throws Exception {


int bi = findBucketIndex( key );
int di = findInBucket( bi, key );

if( di == -1 ){
return null;
}else{
HMNode cnode = buckets[ bi ].remove( di );
size--;
return cnode.value;
}
}

public ArrayList < K > keyset() throws Exception {


ArrayList<K> set = new ArrayList<>();

for( int bi = 0; bi < buckets.length ; bi++ ){


for( HMNode node : buckets[ bi ] ){
set.add( node.key );
}
}

return set;
}

public int size() {


16
return size;
}

public void display() {


System.out.println("Display Begins");
for (int bi = 0; bi < buckets.length; bi++) {
System.out.print("Bucket" + bi + " ");
for (HMNode node : buckets[bi]) {
System.out.print( node.key + "@" + node.value + " ");
}
System.out.println(".");
}
System.out.println("Display Ends");
}
}

public static void main(String[] args) throws Exception {


BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
HashMap<String, Integer> map = new HashMap();

String str = br.readLine();


while (str.equals("quit") == false) {
if (str.startsWith("put")) {
String[] parts = str.split(" ");
String key = parts[1];
Integer val = Integer.parseInt(parts[2]);
map.put(key, val);
} else if (str.startsWith("get")) {
String[] parts = str.split(" ");
String key = parts[1];
System.out.println(map.get(key));
} else if (str.startsWith("containsKey")) {
17
String[] parts = str.split(" ");
String key = parts[1];
System.out.println(map.containsKey(key));
} else if (str.startsWith("remove")) {
String[] parts = str.split(" ");
String key = parts[1];
System.out.println(map.remove(key));
} else if (str.startsWith("size")) {
System.out.println(map.size());
} else if (str.startsWith("keyset")) {
System.out.println(map.keyset());
} else if (str.startsWith("display")) {
map.display();
}
str = br.readLine();
}
}
}

18
Sample Input for Testing:-

put India 135


put Aus 5
put Canada 3
display
get China
remove Aus
get Aus
containsKey US
put US 10
put UK 20
remove US
containsKey US
put Pak 80
put China 200
display
put Utopia 0
display
put Nigeria 3
display
put India 138
display
put Sweden 1
display
put finland 20
display
quit

19
4. RESULT & DISCUSSION

In an ArrayList what we learn we can add numbers dynamically into a collection and
get it from any index in O(1) time.

Same here in HashMap we can access the element not only by its index number also
with its value in same O(1) time, in ArrayList we can add infinite number of duplicate
values but here in HashMap we cannot add duplicate.

Time Complexity:-
Complexity in searching, removing, addition are much better than ArrayList.

20
5. FUTURE SCOPE AND CONCLUSION:

FUTURESCOPE:-

• India’s $150 billion IT services outsourcing industry is adapting to the


changes that are fast setting in because of automation and higher adoption
of digital technologies.

• There is one clear trend from the multiple surveys on the most widely used
programming language worldwide: Java and JavaScript still rule the
coding world.

• Government projects like Digital India and Demonetization surely will


give rise to demand for Java Programmers in every company going digital.

CONCLUSIONS:-

Java offers the real possibility that most programs can be written in a type-
safe language. However, for Java to be broadly useful, it needs to have more
expressive power than it does at present. This paper addresses one of the areas where
more power is needed.

21
REFRENCES

Tutorialspoint - https://www.tutorialspoint.com/eclipse/index.htm

Javatpoint - https://www.javatpoint.com/internal-details-of-hello-java-program

Infoworld- https://www.infoworld.com/article/3296360/what-is-the-jdk-introduction-to-
the-java-development-kit.html

W3chools - https://www.w3schools.com/java/java_hashmap.asp

22

You might also like