a. Concept and Definition
b. Binary Tree
c. Introduction and application
d. Operation
e. Types of Binary Tree
• Complete
• Strictly
• Almost Complete
f. Huffman algorithm
g. Binary Search Tree
• Insertion
• Deletion
• Searching
h. Tree Traversal
• Pre-order traversal
• In-order traversal
• Post-order traversal
Slides at myblog
http://www.ashimlamichhane.com.np/2016/07/tree-slide-for-data-structure-and-algorithm/
Assignments at github
https://github.com/ashim888/dataStructureAndAlgorithm/tree/dev/Assignments/assignment_7
a. Concept and Definition✓
b. Inserting and Deleting nodes ✓
c. Linked implementation of a stack (PUSH/POP) ✓
d. Linked implementation of a queue (Insert/Remove) ✓
e. Circular List
• Stack as a circular list (PUSH/POP) ✓
• Queue as a circular list (Insert/Remove) ✓
f. Doubly Linked List (Insert/Remove) ✓
For more course related material:
https://github.com/ashim888/dataStructureAndAlgorithm/
Personal blog
www.ashimlamichhane.com.np
a. Concept and Definition
b. Binary Tree
c. Introduction and application
d. Operation
e. Types of Binary Tree
• Complete
• Strictly
• Almost Complete
f. Huffman algorithm
g. Binary Search Tree
• Insertion
• Deletion
• Searching
h. Tree Traversal
• Pre-order traversal
• In-order traversal
• Post-order traversal
Slides at myblog
http://www.ashimlamichhane.com.np/2016/07/tree-slide-for-data-structure-and-algorithm/
Assignments at github
https://github.com/ashim888/dataStructureAndAlgorithm/tree/dev/Assignments/assignment_7
a. Concept and Definition✓
b. Inserting and Deleting nodes ✓
c. Linked implementation of a stack (PUSH/POP) ✓
d. Linked implementation of a queue (Insert/Remove) ✓
e. Circular List
• Stack as a circular list (PUSH/POP) ✓
• Queue as a circular list (Insert/Remove) ✓
f. Doubly Linked List (Insert/Remove) ✓
For more course related material:
https://github.com/ashim888/dataStructureAndAlgorithm/
Personal blog
www.ashimlamichhane.com.np
It is related to Analysis and Design Of Algorithms Subject.Basically it describe basic of topological sorting, it's algorithm and step by step process to solve the example of topological sort.
Traversal is a process to visit all the nodes of a tree and may print their values too. Because, all nodes are connected via edges (links) we always start from the root (head) node. That is, we cannot randomly access a node in a tree.
In computer science, a data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data. https://apkleet.com
<a href="https://apkleet.com" >games apk </a>
It is related to Analysis and Design Of Algorithms Subject.Basically it describe basic of topological sorting, it's algorithm and step by step process to solve the example of topological sort.
Traversal is a process to visit all the nodes of a tree and may print their values too. Because, all nodes are connected via edges (links) we always start from the root (head) node. That is, we cannot randomly access a node in a tree.
In computer science, a data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data. https://apkleet.com
<a href="https://apkleet.com" >games apk </a>
DEFINITION OF DATA STRUCTURES & ALGORITHM
OVERVIEW OF DATA STRUCTURES
TYPES OF DATA STRUCTURE
LINEAR DATA STRUCTURE
NON-LINEAR DATA STRUCTURE
ABSTRACT DATA TYPE.
For years, the Machine Learning community has focused on developing efficient
algorithms that can produce very accurate classifiers. However, it is often much easier
to find several good classifiers based on dataset combination, instead of single classifier
applied on deferent datasets. The advantages of using classifier dataset combinations
instead of a single one are twofold: it helps lowering the computational complexity by
using simpler models, and it can improve the classification accuracy and performance.
Most Data mining applications are based on pattern matching algorithms, thus improving
the performance of the classification has a positive impact on the quality of the overall
data mining task. Since combination strategies proved very useful in improving the
performance, these techniques have become very important in applications such as
Cancer detection, Speech Technology and Natural Language Processing .The aim of this
paper is basically to propose proprietary metric, Normalized Geometric Index (NGI)
based on the latent properties of datasets for improving the accuracy of data mining tasks.
International Refereed Journal of Engineering and Science (IRJES) irjes
International Refereed Journal of Engineering and Science (IRJES)
Ad hoc & sensor networks, Adaptive applications, Aeronautical Engineering, Aerospace Engineering
Agricultural Engineering, AI and Image Recognition, Allied engineering materials, Applied mechanics,
Architecture & Planning, Artificial intelligence, Audio Engineering, Automation and Mobile Robots
Automotive Engineering….
MODULE III Parallel Processors and Memory Organization 15 Hours
Parallel Processors: Introduction to parallel processors, Concurrent access to memory and cache
coherency. Introduction to multicore architecture. Memory system design: semiconductor memory
technologies, memory organization. Memory interleaving, concept of hierarchical memory
organization, cache memory, cache size vs. block size, mapping functions, replacement
algorithms, write policies.
Case Study: Instruction sets of some common CPUs - Design of a simple hypothetical CPU- A
sequential Y86-64 design-Sun Ultra SPARC II pipeline structure
MODULE II Control unit, I/O systems and Pipelining 15 Hours
CPU control unit design: Hardwired and micro-programmed design approaches, Peripheral
devices and their characteristics: Input-output subsystems, I/O device interface, I/O transfersprogram controlled, interrupt driven and DMA, privileged and non-privileged instructions, software
interrupts and exceptions. Programs and processes-role of interrupts in process state transitions,
I/O device interfaces - SCII, USB. Basic concepts of pipelining, throughput and speedup, pipeline
hazards.
Functional Blocks of a Computer: Functional blocks and its operations. Instruction set architecture of a CPU - registers, instruction execution cycle, Data path, RTL interpretation of
instructions, instruction set. Performance metrics. Addressing modes. Data Representation:
Signed number representation, fixed and floating point representations, character representation.
Computer arithmetic - integer addition and subtraction, ripple carry adder, carry look-ahead
adder, etc. multiplication - shift-and add, Booth multiplier, carry save multiplier, etc. Division
restoring and non-restoring techniques, floating point arithmetic.
Module II - Distributed objects and file systems:
Introduction - Communication between distributed objects - Remote procedure call - Events and notifications - case study - Operating system support - introduction - operating system layer - protection - process and threads - communication and invocation - architecture - Introduction to DFS - File service architecture - Sun network file system - Andrew file system - Enhancements and future developments.
Module 2 - Distributed Objects and File Systems
Introduction - Communication between distributed objects - Remote procedure call - Events and notifications - case study - Operating system support - introduction - operating system layer - protection - process and threads - communication and invocation - architecture - Introduction to DFS - File service architecture - Sun network file system - Andrew file system - Enhancements and future developments.
Module I
Introduction to Distributed systems - Examples of distributed systems, resource sharing and the web, challenges - System model - introduction - architectural models - fundamental models - Introduction to inter-process communications - API for Internet protocol - external data.
Module I
Introduction to Distributed systems - Examples of distributed systems, resource sharing and the web, challenges - System model - introduction - architectural models - fundamental models - Introduction to inter-process communications - API for Internet protocol - external data.
Module 6: IP and System Security
IP security overview-IP security policy-Encapsulating Security payload-intruders-intrusion detectionvirus/worms-countermeasure-need for firewalls-firewall characteristics-types of fire
Module 4: Key Management and User Authentication
X.509 certificates- Public Key infrastructure-remote user authentication principles-remote user
authentication using symmetric and asymmetric encryption-Kerberos V5
Module 1: Introduction to Cryptography and Symmetric Key Ciphers
Computer Security Concepts - OSI Security Architecture -Security Attacks - Services, Mechanisms -
Symmetric Cipher Model - Traditional Block Cipher Structure - The Data Encryption Standard -The Strength of DES - Advanced Encryption Standard.
Module 6
Advanced Networking
Security problems with internet architecture, Introduction to Software defined networking, Working of SDN, SDN in data centre, SDN applications, Data centre networking, IoT.
Module 6: Standards for Information Security Management
Information Security Management Systems (ISMS) - ISO 27001 - Framing Security Policy of
Organization- Committees- Security Forum, Core Committee, Custodian and Users, Business
Continuity Process Team & Procedure- Information Security Auditing Process. IT Security Incidents
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
Automobile Management System Project Report.pdfKamal Acharya
The proposed project is developed to manage the automobile in the automobile dealer company. The main module in this project is login, automobile management, customer management, sales, complaints and reports. The first module is the login. The automobile showroom owner should login to the project for usage. The username and password are verified and if it is correct, next form opens. If the username and password are not correct, it shows the error message.
When a customer search for a automobile, if the automobile is available, they will be taken to a page that shows the details of the automobile including automobile name, automobile ID, quantity, price etc. “Automobile Management System” is useful for maintaining automobiles, customers effectively and hence helps for establishing good relation between customer and automobile organization. It contains various customized modules for effectively maintaining automobiles and stock information accurately and safely.
When the automobile is sold to the customer, stock will be reduced automatically. When a new purchase is made, stock will be increased automatically. While selecting automobiles for sale, the proposed software will automatically check for total number of available stock of that particular item, if the total stock of that particular item is less than 5, software will notify the user to purchase the particular item.
Also when the user tries to sale items which are not in stock, the system will prompt the user that the stock is not enough. Customers of this system can search for a automobile; can purchase a automobile easily by selecting fast. On the other hand the stock of automobiles can be maintained perfectly by the automobile shop manager overcoming the drawbacks of existing system.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfKamal Acharya
The College Bus Management system is completely developed by Visual Basic .NET Version. The application is connect with most secured database language MS SQL Server. The application is develop by using best combination of front-end and back-end languages. The application is totally design like flat user interface. This flat user interface is more attractive user interface in 2017. The application is gives more important to the system functionality. The application is to manage the student’s details, driver’s details, bus details, bus route details, bus fees details and more. The application has only one unit for admin. The admin can manage the entire application. The admin can login into the application by using username and password of the admin. The application is develop for big and small colleges. It is more user friendly for non-computer person. Even they can easily learn how to manage the application within hours. The application is more secure by the admin. The system will give an effective output for the VB.Net and SQL Server given as input to the system. The compiled java program given as input to the system, after scanning the program will generate different reports. The application generates the report for users. The admin can view and download the report of the data. The application deliver the excel format reports. Because, excel formatted reports is very easy to understand the income and expense of the college bus. This application is mainly develop for windows operating system users. In 2017, 73% of people enterprises are using windows operating system. So the application will easily install for all the windows operating system users. The application-developed size is very low. The application consumes very low space in disk. Therefore, the user can allocate very minimum local disk space for this application.
Quality defects in TMT Bars, Possible causes and Potential Solutions.PrashantGoswami42
Maintaining high-quality standards in the production of TMT bars is crucial for ensuring structural integrity in construction. Addressing common defects through careful monitoring, standardized processes, and advanced technology can significantly improve the quality of TMT bars. Continuous training and adherence to quality control measures will also play a pivotal role in minimizing these defects.
Democratizing Fuzzing at Scale by Abhishek Aryaabh.arya
Presented at NUS: Fuzzing and Software Security Summer School 2024
This keynote talks about the democratization of fuzzing at scale, highlighting the collaboration between open source communities, academia, and industry to advance the field of fuzzing. It delves into the history of fuzzing, the development of scalable fuzzing platforms, and the empowerment of community-driven research. The talk will further discuss recent advancements leveraging AI/ML and offer insights into the future evolution of the fuzzing landscape.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Explore the innovative world of trenchless pipe repair with our comprehensive guide, "The Benefits and Techniques of Trenchless Pipe Repair." This document delves into the modern methods of repairing underground pipes without the need for extensive excavation, highlighting the numerous advantages and the latest techniques used in the industry.
Learn about the cost savings, reduced environmental impact, and minimal disruption associated with trenchless technology. Discover detailed explanations of popular techniques such as pipe bursting, cured-in-place pipe (CIPP) lining, and directional drilling. Understand how these methods can be applied to various types of infrastructure, from residential plumbing to large-scale municipal systems.
Ideal for homeowners, contractors, engineers, and anyone interested in modern plumbing solutions, this guide provides valuable insights into why trenchless pipe repair is becoming the preferred choice for pipe rehabilitation. Stay informed about the latest advancements and best practices in the field.
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
Advancements in technology unveil a myriad of electrical and electronic breakthroughs geared towards efficiently harnessing limited resources to meet human energy demands. The optimization of hybrid solar PV panels and pumped hydro energy supply systems plays a pivotal role in utilizing natural resources effectively. This initiative not only benefits humanity but also fosters environmental sustainability. The study investigated the design optimization of these hybrid systems, focusing on understanding solar radiation patterns, identifying geographical influences on solar radiation, formulating a mathematical model for system optimization, and determining the optimal configuration of PV panels and pumped hydro storage. Through a comparative analysis approach and eight weeks of data collection, the study addressed key research questions related to solar radiation patterns and optimal system design. The findings highlighted regions with heightened solar radiation levels, showcasing substantial potential for power generation and emphasizing the system's efficiency. Optimizing system design significantly boosted power generation, promoted renewable energy utilization, and enhanced energy storage capacity. The study underscored the benefits of optimizing hybrid solar PV panels and pumped hydro energy supply systems for sustainable energy usage. Optimizing the design of solar PV panels and pumped hydro energy supply systems as examined across diverse climatic conditions in a developing country, not only enhances power generation but also improves the integration of renewable energy sources and boosts energy storage capacities, particularly beneficial for less economically prosperous regions. Additionally, the study provides valuable insights for advancing energy research in economically viable areas. Recommendations included conducting site-specific assessments, utilizing advanced modeling tools, implementing regular maintenance protocols, and enhancing communication among system components.
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxR&R Consult
CFD analysis is incredibly effective at solving mysteries and improving the performance of complex systems!
Here's a great example: At a large natural gas-fired power plant, where they use waste heat to generate steam and energy, they were puzzled that their boiler wasn't producing as much steam as expected.
R&R and Tetra Engineering Group Inc. were asked to solve the issue with reduced steam production.
An inspection had shown that a significant amount of hot flue gas was bypassing the boiler tubes, where the heat was supposed to be transferred.
R&R Consult conducted a CFD analysis, which revealed that 6.3% of the flue gas was bypassing the boiler tubes without transferring heat. The analysis also showed that the flue gas was instead being directed along the sides of the boiler and between the modules that were supposed to capture the heat. This was the cause of the reduced performance.
Based on our results, Tetra Engineering installed covering plates to reduce the bypass flow. This improved the boiler's performance and increased electricity production.
It is always satisfying when we can help solve complex challenges like this. Do your systems also need a check-up or optimization? Give us a call!
Work done in cooperation with James Malloy and David Moelling from Tetra Engineering.
More examples of our work https://www.r-r-consult.dk/en/cases-en/
2. UNIT I LINEAR DATA STRUCTURES – LIST
Abstract Data Types (ADTs) List ADT array based
implementation – linked list implementation –– singly
linked lists- circularly linked lists- doubly-linked lists –
applications of lists –Polynomial Manipulation – All
operations (Insertion, Deletion, Merge, Traversal)
TEXTBOOKS:
1. Mark Allen Weiss, “Data Structures and Algorithm
Analysis in C”, 2nd Edition, Pearson Education,1997.
2. Reema Thareja, “Data Structures Using C”, Second Edition,
Oxford University Press, 2011
12 July 2018
2
MNMJEC, Chennai - 600 097
3. 12 July 2018MNMJEC, Chennai - 600 097
3
Topics
Introduction
Definitions
Classification of Data Structures
Arrays and Linked Lists
Abstract Data Types [ADT]
The List ADT
Array-based Implementation
Linked List Implementation
Doubly Linked Lists
4. 12 July 2018MNMJEC, Chennai - 600 097
4
Data Structure [Wikipedia]
Data Structure is a particular way of storing and
organizing data in a computer so that it can be used
efficiently.
Different kinds of data structures are suited to different
kinds of applications.
Storing and retrieving can be carried out on data
stored in both main memory and in secondary memory.
5. 12 July 2018MNMJEC, Chennai - 600 097
5
Merriam-Webster's Definition
Way in which data are stored for efficient search and
retrieval.
The simplest data structure is the one-dimensional
(linear) array.
Data items stored non-consecutively in memory may be
linked by pointers.
Many algorithms have been developed for storing data
efficiently
6. 12 July 2018MNMJEC, Chennai - 600 097
6
Algorithms [Wikipedia]
An algorithm is a step-by-step procedure for
calculations.
An algorithm is an effective method expressed as a
finite list of well-defined instructions for calculating a
function.
The transition from one state to the next is not
necessarily deterministic; some algorithms incorporate
random input.
7. 12 July 2018MNMJEC, Chennai - 600 097
7
Merriam-Webster's Definition
Procedure that produces the answer to a question or
the solution to a problem in a finite number of steps.
An algorithm that produces a yes or no answer is called
a decision procedure; one that leads to a solution is a
computation procedure.
Example: A mathematical formula and the instructions in
a computer program
8. 12 July 2018MNMJEC, Chennai - 600 097
8
Data Structure Classification
Primitive / Non-primitive
Basic Data Structures available / Derived from Primitive
Data Structures
Homogeneous / Heterogeneous
Elements are of the same type / Different types
Static / Dynamic
memory is allocated at the time of compilation / run-time
Linear / Non-linear
Maintain a Linear relationship between element
9. 12 July 2018MNMJEC, Chennai - 600 097
9
ADT - General Concept
Problem solving with a computer means processing
data
To process data, we need to define the data type and
the operation to be performed on the data
The definition of the data type and the definition of the
operation to be applied to the data is part of the idea
behind an Abstract Data Type (ADT)
10. 12 July 2018MNMJEC, Chennai - 600 097
10
ADT - General Concept
The user of an ADT needs only to know that a set of
operations are available for the data type, but does
not need to know how they are applied
Several simple ADTs, such as integer, real, character,
pointer and so on, have been implemented and are
available for use in most languages
11. 12 July 2018MNMJEC, Chennai - 600 097
11
Data Types
A data type is characterized by:
A set of values
A data representation, which is common to all these values,
and
A set of operations, which can be applied uniformly to all
these values
12. 12 July 2018MNMJEC, Chennai - 600 097
12
Primitive Data Types
Languages like „C‟ provides the following primitive
data types:
boolean
char, byte, int
float, double
Each primitive type has:
A set of values
A data representation
A set of operations
These are “set in stone”.
13. 12 July 2018MNMJEC, Chennai - 600 097
13
ADT Definition [Wikipedia]
In computer science, an abstract data type (ADT) is a
mathematical model for a certain class of data
structures that have similar behavior.
An abstract data type is defined indirectly, only by the
operations that may be performed on it and by
mathematical constraints on the effects (and possibly
cost) of those operations.
14. 12 July 2018MNMJEC, Chennai - 600 097
14
ADT Definition [Wikipedia]
An ADT may be implemented by specific data types or
data structures, in many ways and in many
programming languages; or described in a formal
specification language.
example, an abstract stack could be defined by three
operations:
push, that inserts some data item onto the structure,
pop, that extracts an item from it, and
peek, that allows data on top of the structure to be
examined without removal.
15. 12 July 2018MNMJEC, Chennai - 600 097
15
Definition from techforum4you
Abstract data types or ADTs are a mathematical
specification of a set of data and the set of operations
that can be performed on the data.
They are abstract in the sense that the focus is on the
definitions and the various operations with their
arguments.
The actual implementation is not defined, and does not
affect the use of the ADT.
16. 12 July 2018MNMJEC, Chennai - 600 097
16
ADT in Simple Words
Definition:
Is a set of operation
Mathematical abstraction
No implementation detail
Example:
Lists, sets, graphs, stacks are examples of ADT along
with their operations
17. 12 July 2018MNMJEC, Chennai - 600 097
17
Why ADT?
Modularity
divide program into small functions
easy to debug and maintain
easy to modify
group work
Reuse
do some operations only once
Easy to change the implementation
transparent to the program
18. 12 July 2018MNMJEC, Chennai - 600 097
18
Implementing an ADT
To implement an ADT, you need to choose:
A data representation
must be able to represent all necessary values of the ADT
should be private
An algorithm for each of the necessary operation:
must be consistent with the chosen representation
all auxiliary (helper) operations that are not in the contract
should be private
Remember: Once other people are using it
It‟s easy to add functionality
19. 12 July 2018MNMJEC, Chennai - 600 097
19
The List ADT
The List is an
Ordered sequence of data items called
elements
A1, A2, A3, …,AN is a list of size N
size of an empty list is 0
Ai+1 succeeds Ai
Ai-1 preceeds Ai
Position of Ai is i
First element is A1 called “head”
Last element is AN called “tail”
20. 12 July 2018MNMJEC, Chennai - 600 097
20
Operations on Lists
MakeEmpty
PrintList
Find
FindKth
Insert
Delete
Next
Previous
21. 12 July 2018MNMJEC, Chennai - 600 097
21
List – An Example
The elements of a list are 34, 12, 52, 16, 12
Find (52) -> 3
Insert (20, 4) -> 34, 12, 52, 20, 16, 12
Delete (52) -> 34, 12, 20, 16, 12
FindKth (3) -> 20
22. 12 July 2018MNMJEC, Chennai - 600 097
22
List - Implementation
Lists can be implemented using:
Arrays
Linked List
Cursor [Linked List using Arrays]
23. 12 July 2018MNMJEC, Chennai - 600 097
23
Arrays
Array is a static data structure that represents a
collection of fixed number of homogeneous data items
or
A fixed-size indexed sequence of elements, all of the
same type.
The individual elements are typically stored in
consecutive memory locations.
The length of the array is determined when the array is
created, and cannot be changed.
24. 12 July 2018MNMJEC, Chennai - 600 097
24
Arrays
Any component of the array can be inspected or
updated by using its index.
This is an efficient operation
O(1) = constant time
The array indices may be integers (C, Java) or other
discrete data types (Pascal, Ada).
The lower bound may be zero (C, Java), one (Fortran),
or chosen by the programmer (Pascal, Ada)
25. 12 July 2018MNMJEC, Chennai - 600 097
25
Different Types of Arrays
One-dimensional array: only one index is used
Multi-dimensional array: array involving more than one
index
Static array: the compiler determines how memory will
be allocated for the array
Dynamic array: memory allocation takes place during
execution
26. 12 July 2018MNMJEC, Chennai - 600 097
26
One Dimensional Static Array
Syntax:
ElementType arrayName [CAPACITY];
ElementType arrayName [CAPACITY] =
{ initializer_list };
Example in C++:
int b [5];
int b [5] = {19, 68, 12, 45, 72};
27. 12 July 2018MNMJEC, Chennai - 600 097
27
Array Output Function
void display(int array[],int num_values)
{
for (int I = 0; i<num_values; i++)
cout<< array[i] << “ ”;
}
29. 12 July 2018MNMJEC, Chennai - 600 097
29
Operations On Lists
We‟ll consider only few operations and
not all operations on Lists
Let us consider Insert
There are two possibilities:
Ordered List
Unordered List
34. 12 July 2018MNMJEC, Chennai - 600 097
34
Find / Search
Searching is the process of looking for a specific
element in an array
For example, discovering whether a certain score
is included in a list of scores.
Searching, like sorting, is a common task in
computer programming.
There are many algorithms and data structures
devoted to searching.
The most common one is the linear search.
35. 12 July 2018MNMJEC, Chennai - 600 097
35
Linear Search
The linear search approach compares the given
value with each element in the array.
The method continues to do so until the given
value matches an element in the list or the list is
exhausted without a match being found.
If a match is made, the linear search returns the
index of the element in the array that matches the
key.
If no match is found, the search returns -1.
37. 12 July 2018MNMJEC, Chennai - 600 097
37
Linear Search Function
int LinearSearch (int a[], int n, int key)
{
int i;
for(i=0; i<n; i++)
{
if (a[i] == key)
return i;
}
return -1;
}
38. 12 July 2018MNMJEC, Chennai - 600 097
38
Using the Function
LinearSearch (a,n,item,loc)
Here "a" is an array of the size n.
This algorithm finds the location of the element "item"
in the array "a".
If search item is found, it sets loc to the index of the
element; otherwise, it sets loc to -1
index=linearsearch(array, num, key)
39. 12 July 2018MNMJEC, Chennai - 600 097
39
PrintList Operation
int myArray [5] = {19,68,12,45,72};
/* To print all the elements of the array
for (int i=0;i<5;i++)
{
printf("%d", myArray[i]);
}
43. 12 July 2018MNMJEC, Chennai - 600 097
43
PrintList O(N)
Find
Insert O(N) (on avarage half
Delete needs to be moved)
FindKth
Next O(1)
Previous
Operations Running Times
44. 12 July 2018MNMJEC, Chennai - 600 097
44
Disadvantages of Using Arrays
Need to define a size for array
High overestimate (waste of space)
insertion and deletion is very slow
need to move elements of the list
redundant memory space
it is difficult to estimate the size of array
45. 12 July 2018MNMJEC, Chennai - 600 097
45
Linked List
Series of nodes
not adjacent in memory
contain the element and a pointer to a node
containing its succesor
Avoids the linear cost of insertion and deletion!
49. 12 July 2018MNMJEC, Chennai - 600 097
49
Singly-linked List - Addition
Insertion into a singly-linked list has two special cases.
It's insertion a new node before the head (to the very
beginning of the list) and after the tail (to the very end
of the list).
In any other case, new node is inserted in the middle of
the list and so, has a predecessor and successor in the
list.
50. 12 July 2018MNMJEC, Chennai - 600 097
50
Empty list case
When list is empty, which
is indicated by (head ==
NULL) condition, the
insertion is quite simple.
Algorithm sets both head
and tail to point to the
new node.
51. 12 July 2018MNMJEC, Chennai - 600 097
51
Add first
In this case, new node is inserted right before the
current head node.
52. 12 July 2018MNMJEC, Chennai - 600 097
52
Add First - Step 1
It can be done in two steps:
Update the next link of the new node, to point to the current
head node.
53. 12 July 2018MNMJEC, Chennai - 600 097
53
Add First - Step 2
Update head link to point to the new node.
55. 12 July 2018MNMJEC, Chennai - 600 097
55
Add last
In this case, new node is inserted right after the current
tail node.
It can be done in two steps:
Update the next link of the current tail node, to point to the
new node.
Update tail link to point to the new node.
57. 12 July 2018MNMJEC, Chennai - 600 097
57
Insert - General Case
In general case, new node is always inserted
between two nodes, which are already in the list.
Head and tail links are not updated in this case.
We need to know two nodes "Previous" and "Next",
between which we want to insert the new node.
This also can be done in two steps:
Update link of the "previous" node, to point to the new node.
Update link of the new node, to point to the "next" node.
59. 12 July 2018MNMJEC, Chennai - 600 097
59
Singly-linked List - Deletion
There are four cases, which can occur while removing
the node.
We have the same four situations, but the order of
algorithm actions is opposite.
Notice, that removal algorithm includes the disposal of
the deleted node - unnecessary in languages with
automatic garbage collection (Java).
60. 12 July 2018MNMJEC, Chennai - 600 097
60
List has only one node
When list has only one
node, that the head
points to the same node
as the tail, the removal is
quite simple.
Algorithm disposes the
node, pointed by head
(or tail) and sets both
head and tail to NULL.
61. 12 July 2018MNMJEC, Chennai - 600 097
61
Remove First
In this case, first node (current head node) is removed
from the list.
It can be done in two steps:
Update head link to point to the node, next to the head.
Dispose removed node.
63. 12 July 2018MNMJEC, Chennai - 600 097
63
Remove Last
In this case, last node (current tail node) is removed
from the list. This operation is a bit more tricky, than
removing the first node, because algorithm should find
a node, which is previous to the tail first.
It can be done in three steps:
Update tail link to point to the node, before the tail. In
order to find it, list should be traversed first, beginning from
the head.
Set next link of the new tail to NULL.
Dispose removed node.
65. 12 July 2018MNMJEC, Chennai - 600 097
65
Remove - General Case
In general case, node to be removed is always located
between two list nodes. Head and tail links are not
updated in this case.
We need to know two nodes "Previous" and "Next", of
the node which we want to delete.
Such a removal can be done in two steps:
Update next link of the previous node, to point to the next
node, relative to the removed node.
Dispose removed node.
67. 12 July 2018MNMJEC, Chennai - 600 097
67
Advantages of Using Linked Lists
Need to know where the first node is
the rest of the nodes can be accessed
No need to move the elements in the list for
insertion and deletion operations
No memory waste
68. 12 July 2018MNMJEC, Chennai - 600 097
68
Arrays - Pros and Cons
Pros
Directly supported by C
Provides random access
Cons
Size determined at compile time
Inserting and deleting elements is time
consuming
69. 12 July 2018MNMJEC, Chennai - 600 097
69
Linked Lists - Pros and Cons
Pros
Size determined during runtime
Inserting and deleting elements is quick
Cons
No random access
User must provide programming support
70. 12 July 2018MNMJEC, Chennai - 600 097
70
Application of Lists
Lists can be used
To store the records sequentially
For creation of stacks and queues
For polynomial handling
To maintain the sequence of operations for do /
undo in software
To keep track of the history of web sites visited
71. 12 July 2018MNMJEC, Chennai - 600 097
71
Why Doubly Linked List ?
given only the pointer location, we cannot access its predecessor in
the list.
Another task that is difficult to perform on a linear linked list is
traversing the list in reverse.
Doubly linked list A linked list in which each node is linked to both
its successor and its predecessor
In such a case, where we need to access the node that precedes a
given node, a doubly linked list is useful.
72. 12 July 2018MNMJEC, Chennai - 600 097
72
Doubly Linked List
In a doubly linked list, the nodes are linked in both
directions. Each node of a doubly linked list contains
three parts:
Info: the data stored in the node
Next: the pointer to the following node
Back: the pointer to the preceding node
73. 12 July 2018MNMJEC, Chennai - 600 097
73
Operations on Doubly Linked Lists
The algorithms for the insertion and deletion operations
on a doubly linked list are somewhat more complicated
than the corresponding operations on a singly linked
list.
The reason is clear: There are more pointers to keep
track of in a doubly linked list.
74. 12 July 2018MNMJEC, Chennai - 600 097
74
Inserting Item
As an example, consider the Inserting an item.
To link the new node, after a given node, in a singly
linked list, we need to change two pointers:
newNode->next and
location->next.
The same operation on a doubly linked list requires four
pointer changes.
78. 12 July 2018MNMJEC, Chennai - 600 097
78
Doubly Linked List - Deletion
One useful feature of a doubly linked list is its
elimination of the need for a pointer to a node's
predecessor to delete the node.
Through the back member, we can alter the next
member of the preceding node to make it jump over
the unwanted node.
Then we make the back pointer of the succeeding node
point to the preceding node.
80. 12 July 2018MNMJEC, Chennai - 600 097
80
Special Cases of Deletion
We do, however, have to be careful about the end
cases:
If location->back is NULL, we are deleting the first node
if location->next is NULL, we are deleting the last node.
If both location->back and location->next are NULL, we
are deleting the only node.
81. Circular Linked Lists
In linear linked lists if a list is traversed (all the
elements visited) an external pointer to the list must
be preserved in order to be able to reference the
list again.
Circular linked lists can be used to help the traverse
the same list again and again if needed. A circular
list is very similar to the linear list where in the
circular list the pointer of the last node points not
NULL but the first node.
85. Circular Linked Lists
In a circular linked list there are two methods to know
if a node is the first node or not.
Either a external pointer, list, points the first node or
A header node is placed as the first node of the
circular list.
The header node can be separated from the others
by either heaving a sentinel value as the info part or
having a dedicated flag variable to specify if the
node is a header node or not.
86. PRIMITIVE FUNCTIONS IN
CIRCULAR LISTS
The structure definition of the circular linked lists
and the linear linked list is the same:
struct node{
int info;
struct node *next;
};
typedef struct node *NODEPTR;
87. PRIMITIVE FUNCTIONS IN
CIRCULAR LISTS
The delete after and insert after functions of the linear lists and the circular lists are
almost the same.
The delete after function: delafter( )
void delafter(NODEPTR p, int *px)
{
NODEPTR q;
if((p == NULL) || (p == p->next)){ /*the empty list
contains a single node and may be pointing itself*/
printf(“void deletionn”);
exit(1);
}
q = p->next;
*px = q->info; /*the data of the deleted node*/
p->next = q->next;
freenode(q);
}
88. PRIMITIVE FUNCTIONS IN
CIRCULAR LISTS
The insertafter function: insafter( )
void insafter(NODEPTR p, int x)
{
NODEPTR q;
if(p == NULL){
printf(“void insertionn”);
exit(1);
}
q = getnode();
q->info = x; /*the data of the inserted node*/
q->next = p->next;
p->next = q;
}
89. CIRCULAR LIST with header node
The header node in a circular list can be specified by a
sentinel value or a dedicated flag:
Header Node with Sentinel: Assume that info part contains
positive integers. Therefore the info part of a header
node can be -1. The following circular list is an example
for a sentinel used to represent the header node:
struct node{
int info;
struct node *next;
};
typedef struct node *NODEPTR;
91. CIRCULAR LIST with header node
Header Node with Flag: In this case a extra variable
called flag can be used to represent the header node. For
example flag in the header node can be 1, where the
flag is 0 for the other nodes.
struct node{
int flag;
int info;
struct node *next;
};
typedef struct node *NODEPTR;
93. Example
Consider a circular linked list with a header node,
where each node contains the name, account
number and the balance of a bank customer. The
header node contains a sentinel account number to
be -99.
(a) Write an appropriate node structure definition
for the circular linked list.
(b) Write a function to display the full records of
the customers with negative balance.
94. a) struct node{
char Name[15]; int AccNo;
float Balance;
struct node *next;
};
typedef struct node *NODEPTR;
b) Assume that the list pointer points the header with the sentinel account number -99.
void DispNegBalanca(NODEPTR *plist)
{
NODEPTR p;
p=*plist;
if(p == NULL){
printf(“There is no list!n”);
exit(1);
}
p=p->next;
while(p->AccNo!=-99){
if(p->Balance < 0.0)
printf(“The Customer Name:%snThe Account No:%dnThe
Balance:%.2fn”, p->Name, p->AccNo, p->Balance);
p=p->next;
}
}
95. Example
Write a function that returns the average of the
numbers in a circular list. Assume that the following node
structure is used, where the flag variable is 1 for the
header node and 0 for all the other nodes.
struct node{
int flag;
float info;
struct node *next;
};
typedef struct node *NODEPTR;
96. float avList(NODEPTR *plist)/*assume that plist points the
header node*/
{
int count=0;
float sum =0.0;
NODEPTR p;
p=*plist;
if((p == NULL)){
printf(“Empty listn”);
exit(1);
}
do{
sum=sum + p->info;
p =p->next;
count++;
}while(p->flag !=1);
return sum/count;
}
97. Polynomials (1/9)
Representing Polynomials As Singly Linked Lists
The manipulation of symbolic polynomials, has a classic example of list
processing.
In general, we want to represent the polynomial:
Where the ai are nonzero coefficients and the ei are nonnegative
integer exponents such that
em-1 > em-2 > … > e1 > e0 ≧ 0 .
We will represent each term as a node containing coefficient and
exponent fields, as well as a pointer to the next term.
01
01)( ee
m xaxaxA m
98. Polynomials (2/9)
Assuming that the coefficients are integers, the type
declarations are:
typedef struct poly_node *poly_pointer;
typedef struct poly_node {
int coef;
int expon;
poly_pointer link;
};
poly_pointer a,b,d;
Draw poly_nodes as:
coef expon link
123 814
xxa
b x x x 8 3 1014 10 6
99. Polynomials (3/9)
Adding Polynomials
To add two polynomials,we examine their terms starting at
the nodes pointed to by a and b.
If the exponents of the two terms are equal
1. add the two coefficients
2. create a new term for the result.
If the exponent of the current term in a is less than b
1. create a duplicate term of b
2. attach this term to the result, called d
3. advance the pointer to the next term in b.
We take a similar action on a if a->expon > b->expon.
Figure 4.12 generating the first three term of
d = a+b (next page)
101. Operating On Polynomials
With linked lists, it is much easier to perform
operations on polynomials such as adding and
deleting.
E.g., adding two polynomials a and b
a.first 143 2 8 1 0 0
b.first 148 -3 10 10 6 0
p
q
(i) p->exp == q->exp
c.first 11 14 0
105. Polynomials (6/9)
Attach a node to the end of a list
void attach(float coefficient, int exponent, poly_pointer *ptr){
/* create a new node with coef = coefficient and expon = exponent, attach it to the
node pointed to by ptr. Ptr is updated to point to this new node */
poly_pointer temp;
temp = (poly_pointer) malloc(sizeof(poly_node));
/* create new node */
if (IS_FULL(temp)) {
fprintf(stderr, “The memory is fulln”);
exit(1); }
temp->coef = coefficient; /* copy item to the new node */
temp->expon = exponent;
(*ptr)->link = temp; /* attach */
*ptr = temp; /* move ptr to the end of the list */
}
106. Polynomials (7/9)
Analysis of padd
1. coefficient additions
0 additions min(m, n)
where m (n) denotes the number of terms in A (B).
2. exponent comparisons
extreme case:
em-1 > fm-1 > em-2 > fm-2 > … > e1 > f1 > e0 > f0
m+n-1 comparisons
3. creation of new nodes
extreme case: maximum number of terms in d is m+n m + n
new nodes
summary: O(m+n)
))(())(( 0101
0101
ff
n
ee
m xbxbxBxaxaxA nm
107. Polynomials (8/9)
A Suite for Polynomials
e(x) = a(x) * b(x) + d(x)
poly_pointer a, b, d, e;
...
a = read_poly();
b = read_poly();
d = read_poly();
temp = pmult(a, b);
e = padd(temp, d);
print_poly(e);
temp is used to hold a partial result.
By returning the nodes of temp, we
may use it to hold other polynomials
read_poly()
print_poly()
padd()
psub()
pmult()
108. Polynomials (9/9)
Erase Polynomials
erase frees the nodes in temp
void erase (poly_pointer *ptr){
/* erase the polynomial pointed to by ptr */
poly_pointer temp;
while ( *ptr){
temp = *ptr;
*ptr = (*ptr) -> link;
free(temp);
}
}