Assist. Prof. Dr. Caner ÖZCAN

Similar documents
Data Structure [Question Bank]

DATA STRUCTURES USING C

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Data Structures Fibonacci Heaps, Amortized Analysis

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Lecture 12 Doubly Linked Lists (with Recursion)

Unordered Linked Lists

Data Structures Using C++ 2E. Chapter 5 Linked Lists

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

Node-Based Structures Linked Lists: Implementation

10CS35: Data Structures Using C

LINKED DATA STRUCTURES

recursion, O(n), linked lists 6/14

Introduction to Object-Oriented Programming

Data Structures Using C++ 2E. Chapter 5 Linked Lists

PES Institute of Technology-BSC QUESTION BANK

Analysis of a Search Algorithm

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Common Data Structures

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT. Course Curriculum. DATA STRUCTURES (Code: )

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2)

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push)

Unit Write iterative and recursive C functions to find the greatest common divisor of two integers. [6]

Data Structures and Data Manipulation

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

Data Structures and Algorithms Lists

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Introduction to Data Structures and Algorithms

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Atmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : ,

Chapter 13: Query Processing. Basic Steps in Query Processing

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

TREE BASIC TERMINOLOGIES

Data Structures. Level 6 C Module Descriptor

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

22c:31 Algorithms. Ch3: Data Structures. Hantao Zhang Computer Science Department

ADTs,, Arrays, Linked Lists

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING LESSON PLAN

Ordered Lists and Binary Trees

Fast Sequential Summation Algorithms Using Augmented Data Structures

Data Structures and Algorithms

Two Parts. Filesystem Interface. Filesystem design. Interface the user sees. Implementing the interface

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Algorithms and Data Structures

The Scenario_Builder Tool

Universidad Carlos III de Madrid

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Useful Java Collections

Sequences in the C++ STL

Sample Questions Csci 1112 A. Bellaachia

Matrix Multiplication

Linked Lists: Implementation Sequences in the C++ STL

Linked Lists Linked Lists, Queues, and Stacks

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

System Software Prof. Dr. H. Mössenböck

Stack & Queue. Darshan Institute of Engineering & Technology. Explain Array in detail. Row major matrix No of Columns = m = u2 b2 + 1

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Data Types. Abstract Data Types. ADTs as Design Tool. Abstract Data Types. Integer ADT. Principle of Abstraction

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

Data Structures and Algorithms

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Data Structures Using C++

Heaps & Priority Queues in the C++ STL 2-3 Trees

What Is Recursion? Recursion. Binary search example postponed to end of lecture

Record Storage and Primary File Organization

Lecture 10: Dynamic Memory Allocation 1: Into the jaws of malloc()

Bangalore University B.Sc Computer Science Syllabus ( Semester System)

BCS2B02: OOP Concepts and Data Structures Using C++

Linked List as an ADT (cont d.)

Data Structures and Algorithms(5)

Data Structures, Practice Homework 3, with Solutions (not to be handed in)

Introduction to data structures

Data Structures UNIT III. Model Question Answer

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION /5:15-6:45 REC-200, EVI-350, RCH-106, HH-139

Binary Search Trees CMPSC 122

STACKS,QUEUES, AND LINKED LISTS

Computer Programming using C

File System Management

DATABASE DESIGN - 1DL400

Module 2 Stacks and Queues: Abstract Data Types

Circular Linked List. Algorithms and Data Structures

Petrel TIPS&TRICKS from SCM

CIS 631 Database Management Systems Sample Final Exam

Physical Data Organization

Persistent Binary Search Trees

root node level: internal node edge leaf node Data Structures & Algorithms McQuain

INTRODUCTION The collection of data that makes up a computerized database must be stored physically on some computer storage medium.

CSE 211: Data Structures Lecture Notes VII

Chapter 13 File and Database Systems

Chapter 13 File and Database Systems

Sequential Data Structures

Stacks. Linear data structures

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

West Virginia University College of Engineering and Mineral Resources. Computer Engineering 313 Spring 2010

Lecture 11 Array of Linked Lists

Transcription:

Assist. Prof. Dr. Caner ÖZCAN

LINKED LISTS Linked lists are useful to study for some reasons. Most obviously, linked lists are a data structure for real programming. Knowing the strengths and weaknesses of linked lists will help you thinking about complexity of processing time and memory space of algorithms. Linked lists are a good way of understanding the pointers. Linked list problems are a nice combination of algorithms and pointer manipulation. 2

LINKED LISTS A linked list is a data structure that can be changed during execution. Consecutive elements are connected with the pointer. Last element points to NULL. Size can grow or shrink during the execution of the program (It can be made just as long as required) It doesn t made waste memory 3

ARRAYS vs. LINKED LISTS Arrays are suitable for: Inserting/deleting an element at the end. Randomly accessing any element. Searching the array for a particular value. Linked lists are suitable for: Inserting an element. Deleting an element. Applications where sequential access is required. In situations where the number of elements can not be predicted beforehand. 4

TYPES of LISTS Depending on the construction of connection style, several different types of linked lists are possible. 1. Linear singly linked list (Linear List) 5

Liste Tipleri 2. Circular linked list The pointer of the last element in the list points back to the first element. 6

Liste Tipleri 3. Doubly linked list The connection is established between adjacent nodes in both directions. The list can be traversed either forward or backward. 7

LINKED LISTS List is an abstract data type This data type is defined by the user. Typically more complex than simple data types like int, float, etc. Main aim is; 8

Basic Operations on a List Creating a list Traversing the list Inserting an item to the list Deleting an item from the list Concatenating two lists into one 9

Working with Linked Lists Consider the structure of a node in the list as follows: 10

Creating a Linear List First, a node must be created and the head must be provided to point that node. no name next age 11

Creating a Linear List If number of nodes is n in the initial linked list: Allocate n records, one by one. Read in the fields of the records. Modify the links of the records so that the chain is formed. 12

Creating a Linear List 13

Traversing the List Once the linked list has been constructed and head points to the first node of the list: Follow the pointers. Display the contents of the nodes as they are traversed. Stop when the next pointer points to NULL 14

Traversing the List 15

Inserting a Node in a List For insertion: A record is created holding the new item. The next pointer of the new record is set to link it to the item which is to follow it in the list. The next pointer of the item which is to precede it must be modified to point to the new item. The problem is to insert a node before a specified node. Specified means some value is given for the node (called key). In this example, we consider it to be number. 16

Inserting a Node in a List 17

Inserting a Node in a List When a node is added to the beginning, Only one «next» pointer needs to be modified. Head is made to point to the new node. New node points to the previously first element. When a node is added to the end, Two «next» pointers need to be modified. Last node now points to the new node. New node points to NULL When a node is added to the middle, Two «next» pointers need to be modified. Previous node now points to the new node. New node points to the next node. 18

Inserting a Node in a List 19

Inserting a Node in a List 20

Deleting a Node from the List For deletion: The next pointer of the item immediately preceding the one to be deleted is altered, and made to point to the item following the deleted item. 21

Deleting a Node from the List To delete a specified node (give the node whose number field is given) Three conditions arise: Deleting the first node. Deleting the last node. Deleting an intermediate node. 22

Deleting a Node from the List 23

Deleting a Node from the List 24

Main Function 25

26