473,378 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Delete a node in a single link list that takes O(1) time

How to write code to delete a specific node in a single link list that
takes O(1) time? £¨ link list uses pointers, not hash. £© That is, the
time deleting a node is the same (independent from the length of the
list. Show your c/c++ source code.

May 19 '07 #1
11 5604
hotice wrote:
How to write code to delete a specific node in a single link list that
takes O(1) time? £¨ link list uses pointers, not hash. £© That is, the
time deleting a node is the same (independent from the length of the
list. Show your c/c++ source code.
You first!

--
Ian Collins.
May 19 '07 #2
hotice <xu*******@gmail.comwrote:
How to write code to delete a specific node in a single link list that
takes O(1) time? £® link list uses pointers, not hash. £© That is, the
time deleting a node is the same (independent from the length of the
list. Show your c/c++ source code.
Think about how a single linked list works. What is a node in such a
list? What properties does it have? Now think of a couple ways to remove
a node from the list. What information do you need to do it? Do
different removal strategies require different information?

Do all the above without code first. Write a simple description of what
needs to happen in what ever language you feel most comfortable in.
May 19 '07 #3
On May 18, 8:48 pm, hotice <xuxin2...@gmail.comwrote:
How to write code to delete a specific node in a single link list that
takes O(1) time? £¨ link list uses pointers, not hash. £© That is, the
time deleting a node is the same (independent from the length of the
list. Show your c/c++ source code.
What you describe is not a linked list anymore.
Show your own code.

May 19 '07 #4
* Salt_Peter:
On May 18, 8:48 pm, hotice <xuxin2...@gmail.comwrote:
>How to write code to delete a specific node in a single link list that
takes O(1) time? ( link list uses pointers, not hash. ) That is, the
time deleting a node is the same (independent from the length of the
list. Show your c/c++ source code.

What you describe is not a linked list anymore.
Well, not that I like doing homework for anyone, but this problem goes
back to about 1967. It's well known with well known solution. Young
"hotice" is just too dishonest to think of any way of finding a solution
other than to cheat, not even doing his own googling.

Show your own code.
Second that.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 19 '07 #5
On 2007-05-18 18:51:47 -0700, Salt_Peter <pj*****@yahoo.comsaid:
On May 18, 8:48 pm, hotice <xuxin2...@gmail.comwrote:
>How to write code to delete a specific node in a single link list that
takes O(1) time? ( link list uses pointers, not hash. ) That
is, the
>time deleting a node is the same (independent from the length of the
list. Show your c/c++ source code.

What you describe is not a linked list anymore.
Of course it is. In fact, I'd say that the obvious way of removing an
element from a linked list is O(1) time. (think about it).
Show your own code.

--
Clark S. Cox III
cl*******@gmail.com

May 19 '07 #6
On May 19, 12:05 am, Clark Cox <clarkc...@gmail.comwrote:
On 2007-05-18 18:51:47 -0700, Salt_Peter <pj_h...@yahoo.comsaid:
On May 18, 8:48 pm, hotice <xuxin2...@gmail.comwrote:
How to write code to delete a specific node in a single link list that
takes O(1) time? £¨ link list uses pointers, not hash. £© That
is, the
time deleting a node is the same (independent from the length of the
list. Show your c/c++ source code.
What you describe is not a linked list anymore.

Of course it is. In fact, I'd say that the obvious way of removing an
element from a linked list is O(1) time. (think about it).
I agree with the O(1), but thats not was he's asking for.
>
Show your own code.

--
Clark S. Cox III
clarkc...@gmail.com

May 19 '07 #7
On May 19, 12:05 am, Clark Cox <clarkc...@gmail.comwrote:
On 2007-05-18 18:51:47 -0700, Salt_Peter <pj_h...@yahoo.comsaid:
On May 18, 8:48 pm, hotice <xuxin2...@gmail.comwrote:
How to write code to delete a specific node in a single link list that
takes O(1) time? £¨ link list uses pointers, not hash. £© That
is, the
time deleting a node is the same (independent from the length of the
list. Show your c/c++ source code.
What you describe is not a linked list anymore.

Of course it is. In fact, I'd say that the obvious way of removing an
element from a linked list is O(1) time. (think about it).
Its definitely O(1), he doesn't know it but thats not what he's asking
for.
May 19 '07 #8
hotice wrote:
How to write code to delete a specific node in a single link list that
takes O(1) time? £¨ link list uses pointers, not hash. £©
What info do you have to delete the node? If you have only a pointer
to the node to be deleted and nothing else, it's obviously impossible
to delete it in constant time. You need a pointer to the previous node.
May 19 '07 #9
* Juha Nieminen:
hotice wrote:
>How to write code to delete a specific node in a single link list that
takes O(1) time? ( link list uses pointers, not hash. )

What info do you have to delete the node? If you have only a pointer
to the node to be deleted and nothing else, it's obviously impossible
to delete it in constant time. You need a pointer to the previous node.
No.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 19 '07 #10
What info do you have to delete the node? If you have only a pointer
to the node to be deleted and nothing else, it's obviously impossible
to delete it in constant time. You need a pointer to the previous node.

No.
What info do you have to delete the node? If you have only a pointer
to the node to be deleted and nothing else, it's obviously impossible
to delete it in constant time. You need a pointer to the previous node.

No.
---------
list_t *tmp = this->next;
this->val = this->next->val;
this->next = this->next->next;
delete tmp;
---------

but your 'val' has to support '=' ;]

May 19 '07 #11

<an*******@ukr.netwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...
>
What info do you have to delete the node? If you have only a pointer
to the node to be deleted and nothing else, it's obviously impossible
to delete it in constant time. You need a pointer to the previous node.

No.

What info do you have to delete the node? If you have only a pointer
to the node to be deleted and nothing else, it's obviously impossible
to delete it in constant time. You need a pointer to the previous node.

No.

---------
list_t *tmp = this->next;
this->val = this->next->val;
this->next = this->next->next;
delete tmp;
---------

but your 'val' has to support '=' ;]
Consider: what if you're at the end of the list, and this->next is NULL?

-Howard

(P.S., please don't do other people's homework for them. How are they
supposed to learn anything if we help them cheat on their assignments?)

May 21 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Shwetabh | last post by:
Hi, can some one tell me: -> how to remove a loop from a singly linked list with a loop. -> how to count the number of nodes in a looped singly link list. Thanks
13
by: Raj | last post by:
Is there any way to delete a particular node from a singly linked list where the header of the list is unknown.Only pointer available is the one which points to the node to be deleted
4
by: plmanikandan | last post by:
Hi, I am new to link list programming.I need to traverse from the end of link list.Is there any way to find the end of link list without traversing from start(i.e traversing from first to find the...
3
by: azeem_a_k | last post by:
A linklist is a type of data structure which is built from structures and pointers. The linked list is a container class of all types of objects. There are mainly three types of linklist are given...
33
by: desktop | last post by:
In the C++ standard sec 23.1.2 table 69 it says that erase(q) where q is a pointer to an element can be done in amortized constant time. I guess that is not worst case since std::set is...
4
by: mendiratta | last post by:
Hello, I am Learning Link List. Today wrote a simple program, but not working. Program is like this #include<stdio.h> #include<stdlib.h> #include<alloca.h> struct node{ int...
4
by: ravi | last post by:
Can any body help in finding the middle element of a link list in an effective manner i know the simple solution of using two pointers and increment one pointer by one and second by two. but...
3
by: ravi | last post by:
Can any body tell me an effective algo to sort a doubly link list algo must be time as well as memory effective
20
by: sirsnorklingtayo | last post by:
hi guys please help about Linked List, I'm having trouble freeing the allocated memory of a single linked list node with a dynamic char* fields, it doesn't freed up if I use the FREE()...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.