This document summarizes a lecture on arrays and linked lists. It discusses arrays, including how to declare and access array elements. It then covers linear arrays and 2-dimensional arrays. Linked lists are introduced, including how they are composed of nodes that link to the next node. Operations on linked lists like traversing, searching, inserting and deleting nodes are described. Doubly linked lists are also covered, which include pointers to both the next and previous nodes.
Introduction: Data Types, Data structures
Types of Data Structures
Operations, ADTs
Algorithms, Comparison of Algorithms, Complexity, Time- space tradeoff.
Recursion: Introduction, format of recursive functions, recursion Vs. Iteration, examples.
Sorting: Quick sort, Merge Sort, Selection Sort
Introduction: Data Types, Data structures
Types of Data Structures
Operations, ADTs
Algorithms, Comparison of Algorithms, Complexity, Time- space tradeoff.
Recursion: Introduction, format of recursive functions, recursion Vs. Iteration, examples.
Sorting: Quick sort, Merge Sort, Selection Sort
Data may be organized in many different ways; the logical or mathematical model of a particular organization of data is called "Data Structure". The choice of a particular data model depends on two considerations:
It must be rich enough in structure to reflect the actual relationships of the data in the real world.
The structure should be simple enough that one can effectively process the data when necessary.
Data Structure Operations
The particular data structure that one chooses for a given situation depends largely on the nature of specific operations to be performed.
The following are the four major operations associated with any data structure:
i. Traversing : Accessing each record exactly once so that certain items in the record may be processed.
ii. Searching : Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions.
iii. Inserting : Adding a new record to the structure.
iv. Deleting : Removing a record from the structure.
Primitive and Composite Data Types
Primitive Data Types are Basic data types of any language. In most computers these are native to the machine's hardware.
Some Primitive data types are:
Integer
What is Link list? explained with animationsPratikNaik41
This Presentation expalins what are data structures and linked lists with animations.
It also contains a sample implementation of Linked List using C++language.
It uses C++ Pointers to define linked lists.
DATA STRUCUTRES AND LINKED LIST
WHAT ARE DATA STRUCTURES?
Classification Of Data Structures ?
WHAT IS LINKED LIST?
WHY USE LINKED LIST?
INSERTION AND DELETION IN LINKED LIST
LINKED LIST CODE
Introduction of Data Structures and Algorithms by GOWRU BHARATH KUMARBHARATH KUMAR
Basic Terminology: Elementary Data Organization:
Data Structures Usage
Data Structures Implementation
CLASSIFICATION OF DATA STRUCTURES
DATA STRUCTURES OPERATIONS
Space-Time Trade-off
Searching Algorithms
Data may be organized in many different ways; the logical or mathematical model of a particular organization of data is called "Data Structure". The choice of a particular data model depends on two considerations:
It must be rich enough in structure to reflect the actual relationships of the data in the real world.
The structure should be simple enough that one can effectively process the data when necessary.
Data Structure Operations
The particular data structure that one chooses for a given situation depends largely on the nature of specific operations to be performed.
The following are the four major operations associated with any data structure:
i. Traversing : Accessing each record exactly once so that certain items in the record may be processed.
ii. Searching : Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions.
iii. Inserting : Adding a new record to the structure.
iv. Deleting : Removing a record from the structure.
Primitive and Composite Data Types
Primitive Data Types are Basic data types of any language. In most computers these are native to the machine's hardware.
Some Primitive data types are:
Integer
What is Link list? explained with animationsPratikNaik41
This Presentation expalins what are data structures and linked lists with animations.
It also contains a sample implementation of Linked List using C++language.
It uses C++ Pointers to define linked lists.
DATA STRUCUTRES AND LINKED LIST
WHAT ARE DATA STRUCTURES?
Classification Of Data Structures ?
WHAT IS LINKED LIST?
WHY USE LINKED LIST?
INSERTION AND DELETION IN LINKED LIST
LINKED LIST CODE
Introduction of Data Structures and Algorithms by GOWRU BHARATH KUMARBHARATH KUMAR
Basic Terminology: Elementary Data Organization:
Data Structures Usage
Data Structures Implementation
CLASSIFICATION OF DATA STRUCTURES
DATA STRUCTURES OPERATIONS
Space-Time Trade-off
Searching Algorithms
Data structure is an arrangement of data in computer's memory. It makes the data quickly available to the processor for required operations.It is a software artifact which allows data to be stored, organized and accessed.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
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.
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.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
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!
1. Data Structures & Algorithm
CSC-102
Lecture 2
Arrays & Link List
Lecturer: Syeda Nazia Ashraf
1
2. Arrays
▪ Array declaration: int x[6];
▪ An array is collection of cells of the same type.
▪ The collection has the name ‘x’.
▪ The cells are numbered with consecutive
integers.
▪ To access a cell, use the array name and an
index:
x[0], x[1], x[2], x[3], x[4], x[5]
2
4. Linear(1-Dimensional Array)
A linear array A[8] consisting of numbers is pictured
in following figure.
4
A linear array STUDENT consisting of the names of
six students STUDENT[1] denotes John Brown,
STUDENT[2] denotes Sandra Gold, and so on.
5. 2-Dimensional Array
5
A chain of 28 stores, each store having 4 departments, may lists its weekly
sales first subscript denotes the store and the second subscript the
department. SALES is the name given to the Array.
SALES[1,1]=2872, SALES[1,2]=805, SALES[1,3]=3211,……..,SALES[28,4]=282
The size of this array is denoted by 28 X 4 (read 28 by 4), since it contains 28 rows
(the horizontal lines of numbers) and 4 columns (the vertical lines of numbers).
Such arrays are called Matrices in mathematics, and tables in business
applications.
9. Data Structure Operations
9
The following four operations play a major role:
1. Traversing: Accessing each record exactly once so that certain items in the
record may be processed. (this accessing and processing is sometimes called
“visiting” the record.)
2. Searching: Finding the location of the record with a given key value, or finding
the locations of all records which satisfy one or more conditions.
3. Inserting: Adding a new record to the structure.
4. Deleting: Removing a record from the structure.
Sometimes two or more of the operations may be used in a given situation; e.g.,
we may want to delete the record with a given key, which may mean we first
need to search for the location of the record.
The following operations, which are used in special situations, will also be
considered:
1. Sorting: Arranging the records in some logical order (e.g., alphabetically
according to some NAME key, or in numerical order according to some
NUMBER key, such as social security number or account number or student
id)
2. Merging: Combining the records in two different sorted files into a single
sorted file.
10. ADT
• An ADT, is a logical description of how we view the
data and the operations that are allowed without
regard to how they will be implemented.
• This means that we are concerned only with what the
data is representing and not with how it will
eventually be constructed.
• By providing this level of abstraction, we are creating
an encapsulation around the data. The idea is that by
encapsulating the details of the implementation, we
are hiding them from the user’s view. This is
called information hiding.
• The implementation of an abstract data type, often
referred to as a data structure, will require that we
provide a physical view of the data using some
collection of programming constructs and primitive
data types.
10
11. 11
Figure shows a picture of what an abstract data type is and how it operates. The
user interacts with the interface, using the operations that have been specified by
the abstract data type. The abstract data type is the shell that the user interacts
with. The implementation is hidden one level deeper. The user is not concerned
with the details of the implementation.
ADT
15. Data Abstraction and Abstract Data Types (ADT)
• A data type is a template for objects and a set of operations
that define the behavior of the objects ( or Instances) of that
type.
• An abstract Data Type (ADT) is a data type in which the
implementation details are hidden and the user is concerned
with the properties ( or behavior) of that type.
• An ADT has two components:
- Interface (the behavior)
- Implementation
• Example:
- int, float
15
16. Implementation
Abstract Data Type
• The data structures used to
implement the data type can
only be accessed through the
interface.
• Any change in the
implementation does not
change the user programs as
long as the interface remains
the same
• This is also known as the data
encapsulation or data
abstraction.
Interface 1 Interface 2
Interface 3 Interface 4
Implementation
16
18. Linked List
• A list is an abstract data type that implements an
ordered collection of values, where the same
value may occur more than once.
• Create a structure called a Node.
• The object field will hold the actual list
element.
• The next field in the structure will hold the
starting location of the next node.
• Chain the nodes together to form a linked list.
18
object next
19. Linked List
▪ Picture of our list (2, 6, 8, 7, 1) stored as a
linked list:
2 6 8 7 1
head
current
size=5
19
21. Linked List
Note some features of the list:
▪ Need a head to point to the first node of the list.
Otherwise we won’t know where the start of the
list is.
▪ The current here is a pointer, not an index.
▪ The next field in the last node points to nothing.
We will place the memory address NULL which
is guaranteed to be inaccessible.
21
22. Linked List
Actual picture in memory
1051
1052
1055
1059
1060
1061
1062
1063
1064
1056
1057
1058
1053
1054 2
6
8
7
1
1051
1063
1057
1060
0
head 1054
1063
current
1065
Tail / null
24. Real world examples: Linked lists
24
In real life, objects often appear in simple lists. For
example,Companies may maintain a list of
Employees, Banks may keep a list of Bank Accounts,
a Person may keep a list of "Things to Do".etc..
A List ADT allows us to access any of its elements
at any time as well as insert or remove elements anywhere in the list
at any time. The list will automatically shift the elements around in
memory to make the needed room or reduce the unused space. The
general list is the most flexible kind of list in terms of its capabilities.
We use a general List whenever we have elements coming in and
being removed in a random order. For example, when we have a
shelf of library books, we may need to remove a book from anywhere
on the shelf and we may insert books back into their proper location
when they are returned.
25. Operations on Linked List:
There are several operations associated with
linked list i.e.
a) Traversing a Linked List
Suppose we want to traverse LIST in order to
process each node exactly once. The
traversing algorithm uses a pointer variable
PTR which points to the node that is currently
being processed. Accordingly, PTR->NEXT
points to the next node to be processed so,
25
26. 26
PTR:=START [ Moves the pointer to the first node of the
list]
PTR:=LINK[PTR] [ Moves the pointer to the next node in
the list.]
INFO[PTR] [Process information at the node]
28. 28
Algorithm: (Traversing a Linked List) Let LIST be a
linked list in memory. This algorithm traverses LIST,
applying an operation PROCESS to each element of
list. The variable PTR point to the node currently
being processed.
1. Set PTR:=START. [Initializes pointer PTR.]
2. Repeat Steps 3 and 4 while PTR ≠ NULL.
3. Apply PROCESS to INFO[PTR].
4. Set PTR:= LINK[PTR]. [PTR now points to the
next node]
[End of Step 2 loop.]
5. Exit.
29. 29
b) Searching a Linked List:(UNSORTED LIST)
Suppose the data in LIST are not necessarily sorted. Then one searches for ITEM in LIST by
traversing through the list using a pointer variable PTR and comparing ITEM with the contents
INFO[PTR] of each node, one by one, of LIST. Before we update the pointer PTR by
PTR:=LINKPTR], we require two tests. First we have to check to see whether we have reached
the end of the LIST i.e. PTR=NULL. If not, then we check to see whether INFO[PTR]=ITEM.
The two tests cannot be performed at the same time, since INFO[PTR] is not defined when
PTR=NULL. Accordingly we use the First test to control the execution of a loop, and we let the
second test take place inside the loop.
Algorithm: SEARCH(INFO, LINK,START, ITEM, LOC)
LIST is a linked list in the memory. This algorithm finds the location LOC of the
node where ITEM first appear in LIST, or sets LOC=NULL.
1. Set PTR:=START.
2. Repeat Step 3 while PTR≠NULL:
3. If ITEM = INFO[PTR], then:
Set LOC:=PTR, and Exit. [Search is successful.]
Else:
Set PTR:=LINK[PTR]. [PTR now points to the next node]
[End of If structure.]
[End of Step 2 loop.]
4. Set LOC:=NULL. [Search is unsuccessful.]
5. Exit.
30. 30
b) Searching a Linked List:(SORTED LIST)
Suppose the data in LIST are sorted. Again we search for ITEM in LIST by traversing the list using
a pointer variable PTR and comparing ITEM with the contents INFO[PTR] of each node, one by
one, of LIST. Now, however, we can stop once ITEM exceeds INFO[PTR]. (List sorted in
descending order)
Algorithm: SRCHSL(INFO, LINK,START, ITEM, LOC)
LIST is sorted list in memory. This algorithm finds the location LOC of the node
where ITEM first appear in LIST, or sets LOC=NULL.
1. Set PTR:=START.
2. Repeat Step 3 while PTR≠NULL:
3. If ITEM < INFO[PTR], then:
Set PTR:=LINK[PTR]. [PTR now points to the next node]
Else If ITEM=INFO[PTR],then
Set LOC:=PTR, and Exit. [Search is successful.]
Else:
LOC:=NULL , and Exit. [ITEM now exceeds INFO[PTR].]
[End of If structure.]
[End of Step 2 loop.]
4. Set LOC:=NULL.
5. Exit.
31. 31
Search Linked List for insertion and deletion of Nodes:
Both insertion and deletion operations need searching the linked list.
• To add a new node, we must identify the logical predecessor (address of
previous node) where the new node is to be inserting.
• To delete a node, we must identify the location (addresses) of the node
to be deleted and its logical predecessor (previous node).
Basic Search Concept
Assume there is a sorted linked list and we wish that after each
insertion/deletion this list should always be sorted. Given a target value,
the search attempts to locate the requested node in the linked list.
Since nodes in a linked list have no names, we use two pointers, pre (for
previous)and cur (for current) nodes. At the beginning of the search, the
pre pointer is null and the cur pointer points to the first node (Head). The
search algorithm moves the two pointers together towards the end of the
list. Diagram in a next slide, shows the movement of these two pointers
through the list in an extreme case scenario: when the target value is
larger than any value in the list.
34. Linked List Operations
▪ add(9): Create a new node in memory to hold ‘9’
Node* newNode = new Node(9); 9
newNode
34
35. Linked List Operations
▪ add(9): Create a new node in memory to hold ‘9’
Node* newNode = new Node(9);
▪ Link the new node into the list
9
newNode
2 6 8 7 1
head
current
size=5 6
9
newNode
1
3
2
35
37. Building a Linked List
headNode
2
headNode
currentNode
size=1
lastcurrentNode
size=0
List list;
list.add(2);
37
38. Building a Linked List
headNode
2
headNode
currentNode
size=1
lastcurrentNode
2 6
headNode
currentNode
size=2
lastcurrentNode
size=0
List list;
list.add(2);
list.add(6);
38
39. Building a Linked List
List.add(8); list.add(7); list.add(1);
2 6 7 1
headNode
currentNode
size=5
lastcurrentNode
8
39
40. Insertion at the beginning of a List
40
Insertion into a Linked List:
If a node N is to be inserted into the list between nodes A and B in a
linked list named LIST. Its schematic diagram would be:
41. 41
Inserting at the Beginning of a List:
If the linked list is sorted list and new node has the least low value
already stored in the list i.e. (if New->info < Head->info) then new node
is inserted at the beginning / Top of the list.
51. Analysis of Linked List
▪ add
• we simply insert the new node after the current
node. So add is a one-step operation.
▪ remove
▪ remove is also a one-step operation
▪ find
▪ worst-case: may have to search the entire list
▪ back
▪ moving the current pointer back one node requires
traversing the list from the start until the node whose
next pointer points to current node.
51
52. Two-Way or Doubly-linked List
▪ Moving forward in a singly-linked list is easy;
moving backwards is not so easy.
▪ To move back one node, we have to start at the
head of the singly-linked list and move forward
until the node before the current.
▪ To avoid this we can use two pointers in a
node: one to point to next node and another to
point to the previous node:
element next
prev
52
53. Doubly-linked List
▪ Need to be more careful when adding or
removing a node.
▪ Consider add: the order in which pointers are
reorganized is important:
size=5
2 6 8 7 1
head
current
53