Data Structure Introduction
Data Structure Definition
Data Structure Types
Data Structure Characteristics
Need for Data Structure
Stack Definition
Stack Representation
Stack Operations
Stack Algorithm
Program for Stack in C++
Linked List Definition
Linked List Representation
Linked List Operations
Linked List Algorithm
Program for Linked List in C++
Linked List Defination
Linked List Representation
Linked List Operations
Linked List Algorithm
Program for Linked List in C++
this presentation is made for the students who finds data structures a complex subject
this will help students to grab the various topics of data structures with simple presentation techniques
best regards
BCA group
(pooja,shaifali,richa,trishla,rani,pallavi,shivani)
Data Structure Introduction
Data Structure Definition
Data Structure Types
Data Structure Characteristics
Need for Data Structure
Stack Definition
Stack Representation
Stack Operations
Stack Algorithm
Program for Stack in C++
Linked List Definition
Linked List Representation
Linked List Operations
Linked List Algorithm
Program for Linked List in C++
Linked List Defination
Linked List Representation
Linked List Operations
Linked List Algorithm
Program for Linked List in C++
this presentation is made for the students who finds data structures a complex subject
this will help students to grab the various topics of data structures with simple presentation techniques
best regards
BCA group
(pooja,shaifali,richa,trishla,rani,pallavi,shivani)
Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way. Data Structures is about rendering data elements in terms of some relationship, for better organization and storage. For example, we have data player's name "Virat" and age 26. Here "Virat" is of String data type and 26 is of integer data type.
We can organize this data as a record like Player record. Now we can collect and store player's records in a file or database as a data structure. For example: "Dhoni" 30, "Gambhir" 31, "Sehwag" 33
In simple language, Data Structures are structures programmed to store ordered data, so that various operations can be performed on it easily.
Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way. Data Structures is about rendering data elements in terms of some relationship, for better organization and storage. For example, we have data player's name "Virat" and age 26. Here "Virat" is of String data type and 26 is of integer data type.
We can organize this data as a record like Player record. Now we can collect and store player's records in a file or database as a data structure. For example: "Dhoni" 30, "Gambhir" 31, "Sehwag" 33
In simple language, Data Structures are structures programmed to store ordered data, so that various operations can be performed on it easily.
Iberdrola lidera la clasificación de las compañías eléctricas europeasEl_Blog_De_La_Energia
Iberdrola, multinacional española presidida por José Ignacio Sánchez Galán, se pone al frente ocupando la primera posición en la clasificación de compañías eléctricas europeas, según un informe publicado por Climate Disclosure Project (CDP). Esto es debido a su rápidas reacciones ante los grandes desafíos del cambio climático
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxmaxinesmith73660
Consider this code using the ArrayBag of Section 5.2 and the Location class from Chapter 2. What is the output?
Location i = new Location(0, 3);
Location j = new Location(0, 3);
b.add(i);
b.add(j);
System.out.println(b.countOccurrences(i));
A. 0
B. 1
C. 2
D. 3
Suppose that b and c are Integer objects. A typical use of the clone method looks like this:
b = (Integer) c.clone( );
Write a short clear explanation of why the (Integer) type cast is required in this typical example.
A. obj = s;
B. s = obj;
C. s = (String) obj;
D. Two or more answers are correct.
Suppose that obj is an Object variable and s is a String variable. Which of the following statements
is a correctly-compiling widening conversion? Don't worry about possible run-time exceptions
A. obj = s;
B. s = obj;
C. s = (String) obj;
D. Two or more answers are correct.
Suppose that x and y are reference variables and a program activates x.equals(y). What occurs if x is the null reference?
A. A NullPointerException occurs
B. It always returns true.
C. It always returns false.
D. It returns true if y is also a null reference; otherwise it returns false.
Consider the implementation of the Stack using a partially-filled array.
What goes wrong if we try to store the top of the Stack at location [0] and the bottom of the Stack at the last used position of the array?
A. Both peek and pop would require linear time.
B. Both push and pop would require linear time.
C. The Stack could not be used to check balanced parentheses.
D. The Stack could not be used to evaluate postfix expressions.
Write some lines of code that declares an Integer object, using the Integer wrapper class.
Assign the value 42 to this object, then copy this value from the Integer object to an ordinary int variable.
Consider the usual algorithm for determining whether a sequence of parentheses is balanced.
What is the maximum number of parentheses that will appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(()))?
A. 1
B. 2
C. 3
D. 4
E. 5 or more
Consider the usual algorithm to convert an infix expression to a postfix expression.
Suppose that you have read 10 input characters during a conversion and that the
stack now contains the symbols as shown below. Suppose that you read and process
the 11th symbol of the input. What symbol is at the top of the stack in the case where
the 11th symbol is each of the choices shown?
Which of the following stack operations could result in stack underflow?
Answer
A. is_empty
B. pop
C. push
D. Two or more of the above answers
What is the value of the postfix expression 6 3 2 4 + - *:
Answer
A. Something between -15 and -100
B. Something between -5 and -15
C. Something between 5 and -5
D. Something between 5 and 15
E. Something between 15 and 100
1. An array o.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Instructions for Submissions thorugh G- Classroom.pptx
L3
1. Binary Search Trees
Christopher Simpkins
chris.simpkins@gatech.edu
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 1 / 19
2. Trees are everywhere.
1
1Source:http://commons.wikimedia.org/wiki/File:
Winnersh_Meadows_Trees.jpg
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 2 / 19
3. They’re in our web browsers.
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 3 / 19
4. They’re in our file systems.
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 4 / 19
5. They’re even in pop culture.
2
2Source:
http://userserve-ak.last.fm/serve/500/44019065/Neon+Trees.png
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 5 / 19
6. But they’re not in Kansas.
3
3Source:
http://en.wikipedia.org/wiki/File:Wabaunsee_County_View.JPG
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 6 / 19
7. Binary Tree Nodes
The nodes of a binary tree have
a data item,
a link to a left node, and
a link to a right node.
private class Node<E> {
E item;
Node<E> left;
Node<E> right;
Node(E item, Node<E> left, Node<E> right) {
this.item = item;
this.left = left;
this.right = right;
}
}
Just as in the other linked data structures we’ve studied, binary trees
are recursive.
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 7 / 19
8. Binary Tree Structure
Every tree has a distinguished root node with no parent.
All other nodes have exactly one parent.
Nodes which have no children are called leaf nodes.
Nodes which have children are called interior nodes.
Every node has 0, 1, or 2 children.
Every node can be reached by a unique path from the root node.
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 8 / 19
9. Binary Search Trees
A binary search tree (BST) is a binary tree in which for any node,
all the elements in the node’s left subtree are less than the node’s
data item, and
all the elements in the node’s right subtree are equal to or greater
than the node’s data item.
A BST is distinguished by this property, but it’s ADT is simple: add
elements, find element’s in the tree, and iterate over the elements in a
tree.
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 9 / 19
10. Maintaining The BST Property
To add a new value to binary tree and maintain the BST property, we
insert new nodes for data items into the left subtree of a node if
the new item is less than the node’s item, or
the right subtree otherwise.
Every new item creates a leaf node, which can later become an interior
node after additional items have been added. Here’s the structure of a
BST after adding the sequence of numbers 3, 4, 1, 5, 2:
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 10 / 19
11. The Path to an Item
To find a path to an item in a BST: , then
set the path to the empy list
set the root node as the currentNode
until we find the node containing the item or exhaust the BST:
if currentNode contains the item, add it to the path and return it
else if query item is less than the item in currentNode, add
currentNode to path and set the left child as the new currentNode
else add add currentNode to path and set the right child as the new
currentNode
if the item wasn’t found, set the path to the empty list
See public List<E> path(E queryItem) in
BinarySearchTree.java for the code.
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 11 / 19
12. Traversing a Binary Tree
There are three primary ways to traverse a binary tree:
Pre-order:
Process node’s item.
Process left subtree.
Process right subtree.
In-order:
Process left subtree.
Process node’s item.
Process right subtree.
Post-order:
Process left subtree.
Process right subtree.
Process node’s item.
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 12 / 19
13. Simple In-Order Traversal
The code for in-order traversal follows the recursive structure of the
tree:
public void printInOrder() {
printInOrder(root);
}
private void printInOrder(Node<E> node) {
if (node != null) {
printInOrder(node.left);
System.out.print(node.item + " ");
printInOrder(node.right);
}
}
The code above prints the elements in ascending order. Let’s add a
printDescending() method to BinarySearchTree.java.
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 13 / 19
14. Recursively Building a Result: inOrderList()
We can use the recursive accumulator idiom to collect the elements of
the tree in an in-order traversal:
public List<E> toList() {
return inOrderList(root, new ArrayList<E>());
}
private List<E> inOrderList(Node<E> node, List<E> accum) {
if (null == node) {
return accum;
} else {
inOrderList(node.left, accum);
accum.add(node.item);
inOrderList(node.right, accum);
}
return accum;
}
Again, the code follows the recursive structure of the tree.
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 14 / 19
15. Imperative traveral: inOrderImperative()
Contrast the previous code for getting an in-order list of BST elements
with an imperative version:
public List<E> inOrderImperative() {
Node<E> curNode = root;
Stack<Node<E>> fringe = new LinkedStack<>();
List<E> accum = new ArrayList<E>();
while ((curNode != null) || !fringe.isEmpty()) {
while (curNode != null) {
fringe.push(curNode);
curNode = curNode.left;
}
curNode = fringe.pop();
accum.add(curNode.item);
curNode = curNode.right;
}
return accum;
}
We need extra bookkeeping variables to keep track of where we are in
the tree so we can back-track. See BinarySearchTree.java for
comments explaining the algorithm.
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 15 / 19
16. Iterators
Iterators can free clients from having to implement traversal
algorithms. We can even plug our data structures into Java’s for-each
loop by implementing java.lang.Iterable:
public interface Iterable<T> {
java.util.Iterator<T> iterator();
}
As a reminder, java.util.Iterator:
public interface Iterator<E> {
boolean hasNext();
E next();
void remove();
}
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 16 / 19
17. Stateful In-Order Tree Traversal
In the traversal examples we saw earlier the traversal order was
effected by the method call stack. A stateful iterator is much more
challenging because:
The iterator must remember where it is in the tree
The iterator must be able to back-track to parent nodes after
processing child branches
The essential implementation idea is to use a stack to store nodes for
back-tracking. Traditionally (at least in AI), this “to-do list” stack is
called the fringe4.
Let’s look at BinarySearchTree.java again to see how we implement a
stateful in-order iterator.
4This search strategy is called depth-first search. Using a queue for the fringe
instead of a stack would effect a breadth-first search
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 17 / 19
18. Programming Exercise 1
Add a toString method to BinarySearchTree.
The string should have a left square bracket, followed by the
elements in the BST in-oder separated by spaces, followed by a
right square bracket. For example, [1 2 3 4 ]
If the BST is empty, the string should contain empty square
barckets, e.g., [].
Your toString method should use a recursive helper method, similar
to inOrderList. Your helper method should use a StringBuilder
for its accumulator. 5
5StringBuilder works just like StringBuffer. What’s the difference?
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 18 / 19
19. Programming Exercise 2
Recall the method that adds nodes to the BinarySearchTree:
private Node<E> insert(E newItem, Node<E> node) {
if (node == null) {
return new Node<E>(newItem, null, null);
} else if (newItem.compareTo(node.item) < 0) {
node.left = insert(newItem, node.left);
return node;
} else {
node.right = insert(newItem, node.right);
return node;
}
}
Notice that this implementation allows duplicate items. Modify this
method so that BinarySearchTree is a set, that is, does not insert
duplicate items.
Chris Simpkins (Georgia Tech) CS 1331 Introduction to Object Oriented Programming CS 1331 19 / 19