Download presentation
Presentation is loading. Please wait.
Published bySpencer Washington Modified over 5 years ago
1
Sorted Linked List A linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains a reference (i.e., a link) to the next record in the sequence. Course Name: Networking Level(UG/PG): UG Author(s) : Phani Swathi Chitta Mentor: Aruna Adil *The contents in this ppt are licensed under Creative Commons Attribution-NonCommercial-ShareAlike 2.5 India license
2
Learning Objectives After interacting with this Learning Object, the learner will be able to: Explain the concept of sorted linked list
3
1 2 3 4 5 Definitions of the components/Keywords: Glossary:
Node: Node contains a value and reference to next node Reference: Reference is address of next node in the linked list Null Pointer: Reference with no address Head: Starting node of linked list TEMP node: Node with no address 2 3 4 5
4
1 2 3 4 5 Definitions of the components/Keywords:
In Computer Science, a linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains a reference (i.e., a link) to the next record in the sequence. Linked Lists are among the simplest and most common data structures. They provide an easy implementation for several important abstract data structures including stacks, queues, hash table, symbolic expressions and skip lists. The principle benefit of a linked list over a conventional array is that the order of the linked items may be different from the order in which the data items are stored in memory or on disk. For that reason, linked lists allow insertion and removal of nodes at any point in the list, with a constant number of operations. 2 3 4 5
5
1 Master Layout 1 2 3 4 5 Sorted Linked list: Give a PLAY button
Fig. B Fig. A 3 Give a PLAY button Give PAUSE and RESTART/CLEAR buttons Give the color details as given below 4 5
6
Step 1: 1 Sequence: 15, 50, 40, 10, 60, 35 2 3 4 Instruction for the animator Text to be displayed in the working area (DT) When the user clicks PLAY, show fig. A in the master layout along with the sequence given above The text in DT should appear in parallel to the figure Now new TEMP node is 15. It is inserted in sorted linked list at position 1. 5
7
3 Step 2: 1 2 4 5 Instruction for the animator
Text to be displayed in the working area (DT) The next number in the sequence should appear in the TEMP node square box and the linked list square box. Place the new number at proper position depending on the value greater or less than the numbers present in the linked list. Finally all the numbers in the sorted linked list must be in the ascending order. In the sorted linked list, give the box blue color and the next section in pink color. The text in DT should appear in parallel to the figure Now new TEMP node is 50. It is inserted in sorted linked list at position 2 as value of TEMP node, 50 is greater than 15. 4 5
8
3 Step 3: 1 2 4 5 Instruction for the animator
Text to be displayed in the working area (DT) The similar process given in the previous slide follows till the end of the sequence The text in DT should appear in parallel to the figure The value of TEMP node is 40. As it is greater than 15 but less than 50, it comes at position number 2 in the sorted linked list. 5
9
3 Step 4: 1 2 4 5 Instruction for the animator
Text to be displayed in the working area (DT) The similar process given in the slide 2 is followed till the end of the sequence The text in DT should appear in parallel to the figure Now new TEMP node is 10. It is inserted in sorted linked list at position 1 as value of TEMP node, 10 is less than 15. 5
10
3 Step 5: 1 2 4 5 Instruction for the animator
Text to be displayed in the working area (DT) The similar process given in the slide 2 is followed till the end of the sequence The text in DT should appear in parallel to the figure Now new TEMP node is 60. It is inserted in sorted linked list at position 5 as its value 60 is greater than 50. 5
11
3 Step 6: 1 2 4 5 Instruction for the animator
Text to be displayed in the working area (DT) The similar process given in the slide 2 is followed till the end of the sequence The text in DT should appear in parallel to the figure The value of TEMP node is 35. As it is greater than 15 but less than 40, it comes at position number 3 in the sorted linked list. 5
12
Test your understanding
Electrical Engineering Slide 1 Slide 3 Slide 13-17 Slide 18 Introduction Definitions Analogy Test your understanding (questionnaire) Lets Sum up (summary) Want to know more… (Further Reading) Interactivity: Try it yourself The same algorithm as in demo is followed When ADD is selected, add the values given by user and fill the sorted linked list. When REMOVE is selected, remove the particular number from the list as given by user When SEARCH is selected, find out the corresponding number in the list Give a text box to enter node value Give limit that only 7 nodes can be added Give ADD, REMOVE and SEARCH buttons 12 Credits
13
Questionnaire 1 1. In the sorted linked list with n elements, how many shift operations are required for deleting the first element? Answers: a) n b) 0 c) n-1 d) n/2 2 3 4 5
14
Questionnaire 1 2. Suppose getFront is called on a sorted linked list that has exactly two entries with equal priority. How is the return value of getFront selected? Answers: a) The one is chosen at random b) The one which was inserted first c) The one which was inserted most recently d) This can never happen (violates the precondition) 2 3 4 5
15
Questionnaire 1 3. An array of Linked List can be used to implement a Sorted Linked List, with each possible priority corresponding to its own element in the array. When is this implementation not feasible? A. When the number of possible priorities is huge B. When the number of possible priorities is small Answers: a) Both A & B b) Only A c) Only B d) None 2 3 4 5
16
Questionnaire 1 4. Suppose temp points to a node in a Linked List, what Boolean expression will be true when cursor points to the tail node of the list? Answers: a) cursor==null b) cursor->next==null c) cursor->next==null 2 3 4 5
17
Questionnaire 1 5. Suppose that TEMP is a pointer variable that contains the NULL pointer. What happens if your program tries to read or write *TEMP? Answers: A syntax error always occurs at compilation time b) A run-time error always occurs when *TEMP is evaluated c) A run-time error always occurs when the program finishes d) The results are unpredictable 2 3 4 5
18
Links for further reading
Reference websites: Books:
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.